国产探花免费观看_亚洲丰满少妇自慰呻吟_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>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 化州市| 建始县| 沂水县| 池州市| 团风县| 鲁甸县| 祁阳县| 彭泽县| 卓尼县| 江阴市| 宜春市| 西昌市| 巴楚县| 碌曲县| 拉萨市| 红河县| 兴业县| 永平县| 大埔县| 桐庐县| 灵宝市| 库尔勒市| 永城市| 信宜市| 扶风县| 屏东市| 抚州市| 青田县| 冷水江市| 隆昌县| 城口县| 绍兴县| 平泉县| 安宁市| 蓝山县| 渭源县| 普陀区| 中方县| 团风县| 万安县| 秦皇岛市|