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

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

11.14.創(chuàng)建State的自定義動(dòng)作(action)

2024-04-27 13:52:12
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
11.14.1. 問(wèn)題
我想在進(jìn)入state 時(shí)創(chuàng)建State 對(duì)象的自定義動(dòng)作。
11.14.2. 解決辦法
創(chuàng)建一個(gè)IOverride 接口的實(shí)現(xiàn)類(lèi),重寫(xiě)所有需要傳遞自定義行為的所有方法。
11.14.3. 討論
要實(shí)現(xiàn)額外的state 動(dòng)作,你需要?jiǎng)?chuàng)建自定義IOverride 對(duì)象,當(dāng)進(jìn)入state 時(shí)去執(zhí)行你自己的條件邏輯。任何實(shí)現(xiàn)此接口的對(duì)象都能被添加到state 的重寫(xiě)數(shù)組中--任何組件都有下列方法:
apply(parent:UIComponent):void
該方法應(yīng)用重寫(xiě),執(zhí)行重寫(xiě)(override)的自定義行為。將被改變的Parent 參數(shù)值會(huì)被存儲(chǔ)在此方法中以便當(dāng)離開(kāi)state 執(zhí)行撤銷(xiāo)操作。

initialize():void
初始化重寫(xiě)

remove(parent:UIComponent):void
刪除重寫(xiě)。在apply() 方法中記住的值將被恢復(fù)。當(dāng)進(jìn)入狀態(tài)時(shí)自動(dòng)調(diào)用此方法。不應(yīng)直接對(duì)其進(jìn)行調(diào)用

下面的例子中,實(shí)現(xiàn)IOverride 接口的類(lèi)叫CustomOverride ,通過(guò)apply 語(yǔ)句應(yīng)用自定義條件邏輯:
+展開(kāi)
-ActionScript
package oreilly.cookbook{
import flash.display.DisplayObject;
import mx.core.UIComponent;
import mx.states.IOverride;
public class CustomOverride implements IOverride {
private var widthValue:Number;
private var _target:DisplayObject;
public function CustomOverride(target:DisplayObject = null)
{
_target = target;
}
public function get target():DisplayObject {
return _target;
}
public function set target(value:DisplayObject):void {
_target = value;
//empty
public function initialize():void {}
//here we make sure to store the value of the parent before
we change it
//so that we can use this value in the remove method
public function apply(parent:UIComponent):void {
widthValue = _target.width;
if(_target.width > 500) {
_target.width = 500;
}
}
//here we use the stored value
public function remove(parent:UIComponent):void {
_target.width = widthValue;
}
}
}

這里新的CustomOverride 類(lèi)被用來(lái)改變vbox 的大小,這個(gè)類(lèi)可以被擴(kuò)展去使用多個(gè)目標(biāo)和做更可能多的事情而不僅僅局限于改變目標(biāo)寬度,這里只是為了做個(gè)簡(jiǎn)單的演示:
+展開(kāi)
-XML
<mx:states>
<mx:State name="openState">
<cookbook:CustomOverride target="{box1}"/>
</mx:State>
</mx:states>
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 余干县| 积石山| 瓮安县| 平昌县| 三都| 隆德县| 昌乐县| 富平县| 舟山市| 台山市| 宁波市| 青冈县| 大理市| 江山市| 盘锦市| 肃北| 平江县| 库伦旗| 广东省| 外汇| 安吉县| 噶尔县| 常德市| 临颍县| 巴楚县| 杂多县| 湘阴县| 新邵县| 临武县| 靖远县| 芮城县| 临夏市| 麻栗坡县| 新河县| 屏山县| 亳州市| 古田县| 平江县| 上犹县| 花莲县| 香港 |