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

首頁 > 網(wǎng)站 > WEB開發(fā) > 正文

11.8.使用States的延時實例工廠

2024-04-27 13:52:11
字體:
供稿:網(wǎng)友
11.8.1. 問題
我需要一個對象,它能為AddChild 對象實例化不同類型的對象。
11.8.2. 解決辦法
創(chuàng)建工廠類,并賦值給AddChild 對象的targetFactory 屬性。
11.8.3. 討論
AddChild 對象的targetFactory 屬性需要一個實現(xiàn)IDeferredInstance 接口的對象。

IDeferredInstance 接口只需要一個方法:getInstance():Object. 當(dāng)AddChild 對象需要一個新的可視化對象被添加到組件時該方法返回所需的實例對象。

這里提供的類很簡單,但它可根據(jù)type 屬性值返回不同類型的UIComponent:
+展開
-ActionScript
package oreilly.cookbook
{
import mx.containers.HBox;
import mx.containers.VBox;
import mx.controls.Button;
import mx.controls.Text;
import mx.controls.TextInput;
import mx.core.IDeferredInstance;
import mx.core.UIComponent;
public class SpecialDeferredInstance implements
IDeferredInstance
{
private var comp:UIComponent;
private var _type:String;
public function set type(str:String):void {
_type = str;
}
public function get type():String{
return _type;
}
public function getInstance():Object
{
var text:Object;
if(_type == "TextVBox"){
comp = new VBox();
text = new Text();
text.text = "TEXT";
comp.addChild(text as Text);
var btn:Button = new Button();
btn.label = "LABEL";
comp.addChild(btn);
comp.height = 160;
comp.width = 320;
}
else
{
comp = new HBox();
text = new TextInput();
text.text = "TEXT";
comp.addChild(text as TextInput);
var btn:Button = new Button();
btn.label = "LABEL";
comp.addChild(btn);
comp.height = 160;
comp.width = 320;
}
return comp;
}
}
}

設(shè)置好targetFactory 后,AddChild 方法根據(jù)SpecialDeferredInstance 實例的type 參數(shù)可有不同類型的對象,例如:
+展開
-XML
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxmlwidth="400"
height="300currentState="empty">

<mx:Script>
<![CDATA[
import oreilly.cookbook.SpecialDeferredInstance;
[Bindable]
private var defInst:SpecialDeferredInstance =
new SpecialDeferredInstance();

]]>
</mx:Script>
<mx:states>
<mx:State name="defInst">
<mx:AddChild relativeTo="{mainHolder}"
targetFactory="{defInst}"/>

</mx:State>
<mx:State name="empty"/>
</mx:states>
<mx:Button click="currentState == 'defInst' ? currentState='empty' : currentState='defInst'label="change"/>
<mx:HBox id="mainHolder"/>
</mx:VBox>
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 磐安县| 静安区| 赣榆县| 罗平县| 同仁县| 岳阳市| 和平县| 台中县| 陈巴尔虎旗| 湾仔区| 静海县| 凤山市| 清镇市| 崇文区| 垦利县| 商都县| 区。| 长汀县| 玛纳斯县| 韶关市| 湟源县| 北票市| 卫辉市| 抚顺县| 张家口市| 西宁市| 五家渠市| 云梦县| 墨江| 班玛县| 德兴市| 嵊州市| 丰原市| 顺昌县| 宜川县| 龙江县| 岳阳市| 莱芜市| 会同县| 兴业县| 扶风县|