Flex 事件分發(fā)(FlexViewer事件機制)剝離過程
將FlexViewer里面的事件分發(fā)及監(jiān)聽事件機制剝離出來在其他項目中使用
AppEvent.as
package com { import flash.events.Event; /** * @author SamSung * 創(chuàng)建時間:2014-7-24 下午1:21:05 * */ public class AppEvent extends Event { //-------------------------------------------------------------------------- // // Properties // //-------------------------------------------------------------------------- private var _data:Object; private var _callback:Function; public function AppEvent(type:String, data:Object = null, callback:Function = null) { super(type); _data = data; _callback = callback; } /** * The data will be passed via the event. It allows the event dispatcher to publish * data to event listener(s). */ public function get data():Object { return _data; } /** * @private */ public function set data(value:Object):void { _data = value; } /** * The callback function associated with this event. */ public function get callback():Function { return _callback; } /** * @private */ public function set callback(value:Function):void { _callback = value; } /** * Override clone */ public override function clone():Event { return new AppEvent(this.type, this.data, this.callback); } /** * Dispatch this event. */ public function dispatch():Boolean { return EventBus.instance.dispatchEvent(this); } /** * Dispatch an AppEvent for specified type and with optional data and callback reference. */ public static function dispatch(type:String, data:Object = null, callback:Function = null):Boolean { return EventBus.instance.dispatchEvent(new AppEvent(type, data, callback)); } public static function addListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void { EventBus.instance.addEventListener(type, listener, useCapture, priority, useWeakReference); } public static function removeListener(type:String, listener:Function, useCapture:Boolean = false):void { EventBus.instance.removeEventListener(type, listener, useCapture); } } }
EventBus.as
package com { import flash.events.Event; import flash.events.EventDispatcher; /** * The EventBus allows centrallized communication among modules without * point-to-point messaging. It uses the singleton design pattern * to make sure one event bus is available globally. The bus itself * is only available to the container. Modules use the container's * static method to communicate with the event bus. */ public class EventBus extends EventDispatcher { /** Application event bus instance */ public static const instance:EventBus = new EventBus(); /** * Normally the EventBus is not instantiated via the new method directly. * The constructor helps enforce only one EvenBus availiable for the application * (singeton) so that it asures the communication only via a sigle event bus. */ public function EventBus() { } /** * The factory method is used to create a instance of the EventBus. It returns * the only instanace of EventBus and makes sure no another instance is created. */ [Deprecated(replacement="instance")] public static function getInstance():EventBus { return instance; } /** * Basic dispatch function, dispatches simple named events. In the case * that the event is only significant by the event token (type string), * this new dispatch method simplify the code. */ [Deprecated(replacement="AppEvent.dispatch")] public function dispatch(type:String):Boolean { return dispatchEvent(new Event(type)); } } }
上一篇:Flex中Array的IndexOf 的作用示例介紹
欄 目:Flex
下一篇:flex4獲取當(dāng)前窗口的長度與寬度的方法
本文標(biāo)題:Flex 事件分發(fā)(FlexViewer事件機制)剝離過程
本文地址:http://mengdiqiu.com.cn/a1/Flex/11566.html
您可能感興趣的文章
- 01-11flex調(diào)用webservice中的自定義類的方法
- 01-11Flex實現(xiàn)的上傳攝像頭拍照并將UI保存為圖片
- 01-11Flex字體加粗問題只能對英文的字體加粗
- 01-11flex利用webservice上傳照片實現(xiàn)代碼
- 01-11Flex控制彈出窗口拖動范圍示例代碼
- 01-11flex內(nèi)嵌html網(wǎng)頁示例代碼
- 01-11Flex中在Tree綁定數(shù)據(jù)后自動展開樹節(jié)點的方法
- 01-11Flex彈出窗口請求Action函數(shù)示例
- 01-11Flex中通過RadioButton進行切換示例代碼
- 01-11Flex中TabNavigator設(shè)置Tabs樣式思路及源碼


閱讀排行
本欄相關(guān)
- 01-11flex調(diào)用webservice中的自定義類的方法
- 01-11Flex實現(xiàn)的上傳攝像頭拍照并將UI保存
- 01-11datagrid不可編輯行有關(guān)問題的控制方法
- 01-11Flex控制彈出窗口拖動范圍示例代碼
- 01-11flex利用webservice上傳照片實現(xiàn)代碼
- 01-11Flex字體加粗問題只能對英文的字體加
- 01-11Flex中在Tree綁定數(shù)據(jù)后自動展開樹節(jié)點
- 01-11flex內(nèi)嵌html網(wǎng)頁示例代碼
- 01-11Flex中通過RadioButton進行切換示例代碼
- 01-11Flex彈出窗口請求Action函數(shù)示例
隨機閱讀
- 01-10使用C語言求解撲克牌的順子及n個骰子
- 01-10delphi制作wav文件的方法
- 04-02jquery與jsp,用jquery
- 08-05dedecms(織夢)副欄目數(shù)量限制代碼修改
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 01-11ajax實現(xiàn)頁面的局部加載
- 08-05織夢dedecms什么時候用欄目交叉功能?
- 08-05DEDE織夢data目錄下的sessions文件夾有什
- 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
- 01-10C#中split用法實例總結(jié)