国产探花免费观看_亚洲丰满少妇自慰呻吟_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. 當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ā)表
主站蜘蛛池模板: 鄂伦春自治旗| 津南区| 西乌| 西贡区| 保德县| 威信县| 若尔盖县| 郁南县| 克山县| 房产| 江北区| 疏附县| 江山市| 桃园县| 灌云县| 合川市| 大新县| 师宗县| 铜鼓县| 鹤壁市| 鹰潭市| 武清区| 林州市| 罗田县| 南皮县| 麻栗坡县| 乐平市| 元谋县| 广宗县| 聊城市| 双柏县| 梧州市| 麻江县| 永寿县| 白玉县| 海阳市| 开封市| 长武县| 日土县| 永善县| 隆昌县|