国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > WEB開發 > 正文

4.6.創建一個自定義的TextInput

2024-04-27 13:51:53
字體:
來源:轉載
供稿:網友
4.6.1. 問題
我需要創建一個自定義的TextInput 組件,包括可以輸入文本的多行區域和綁定該組件的輸出到一個Text 顯示。
4.6.2. 解決
使用UIComponent 同時添加一個flash.text.TextField 到這個組件中。然后設置一個可綁定的文本屬性,將Text 組件的htmlText 屬性綁定到新組件的文本。
4.6.3. 討論
mx.controls.TextInput 組件限制訪問到flash.text.TextField 組件內部。如果需要對TextField 進行更完全的訪問和控制,簡單的把一個TextField 添加到UIComponent 中。

提供用來訪問TextField 的任何方法都應該被定義在這個組件中。如果需要對TextField 進行完全訪問,把TextField 當作一個公共屬性定義可能更容易。然而,無論何時,當TextField的屬性被訪問或者被改變,采用第一種方法通知組件會比較方便。看一下例子:
+展開
-ActionScript
package oreilly.cookbook
{
import flash.events.Event;
import flash.events.TextEvent;
import flash.text.TextField;
import flash.text.TextFieldType;
import mx.core.UIComponent;
public class SpecialTextInput extends UIComponent
{
private var textInput:TextField;
public static var TEXT_CHANGED:String = "textChanged";
public function SpecialTextInput()
{
textInput = new TextField();
textInput.multiline = true;
textInput.wordWrap = true;
textInput.type = flash.text.TextFieldType.INPUT;
textInput.addEventListener(TextEvent.TEXT_INPUT,
checkInput);
addChild(textInput);
super();
}
private function checkInput(textEvent:TextEvent):void
{
text = textInput.text;
}
override public function set height(value:Number):void
{
textInput.height = this.height;
super.height = value;
}
override public function set width(value:Number):void
{
textInput.width = this.width;
super.width = value;
}
[Bindable(event="textChanged")]
public function get text():String
{
return textInput.text;
}
public function set text(value:String):void
{
dispatchEvent(new Event("textChanged"));
}
}
}

要使用這個新組件,把Text 的htmlText 屬性綁定到新組件的text 屬性上去:
+展開
-XML
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxmlwidth="400"
height="300xmlns:cookbook="oreilly.cookbook.*">

<cookbook:SpecialTextInput id="htmlInputheight="200"
width="300"/>

<mx:TextArea htmlText="{htmlInput.text}"/>
</mx:VBox>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 江阴市| 论坛| 合作市| 翁牛特旗| 阿拉善盟| 林甸县| 乌兰浩特市| 磴口县| 朔州市| 德格县| 安康市| 黄浦区| 绵阳市| 昌黎县| 涡阳县| 玛曲县| 彝良县| 博乐市| 衡山县| 五指山市| 青神县| 安陆市| 修武县| 河间市| 桃园市| 昭通市| 余姚市| 礼泉县| 舞钢市| 凤山市| 泰来县| 甘孜县| 柏乡县| 胶州市| 伊春市| 邮箱| 毕节市| 海南省| 射阳县| 阿拉善盟| 格尔木市|