国产探花免费观看_亚洲丰满少妇自慰呻吟_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>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 张掖市| 石城县| 武功县| 奇台县| 石门县| 马关县| 子长县| 两当县| 泰州市| 富川| 睢宁县| 保亭| 汨罗市| 木里| 中牟县| 滨海县| 长岭县| 衡山县| 贵阳市| 雅江县| 庆云县| 军事| 婺源县| 望谟县| 拉孜县| 保定市| 曲沃县| 华安县| 德令哈市| 北安市| 长治县| 开原市| 濮阳市| 石楼县| 长垣县| 凤翔县| 梁平县| 永城市| 南京市| 理塘县| 漳浦县|