Flex 事件分发(FlexViewer事件机制)剥离过程
来源:本站原创|时间:2020-01-11|栏目:Flex|点击: 次
将FlexViewer里面的事件分发及监听事件机制剥离出来在其他项目中使用
AppEvent.as
package com { import flash.events.Event; /** * @author SamSung * 创建时间: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
本文标题:Flex 事件分发(FlexViewer事件机制)剥离过程
本文地址:https://www.xiuzhanwang.com/a1/Flex/11566.html
您可能感兴趣的文章
- 01-11flex调用webservice中的自定义类的方法
- 01-11Flex实现的上传摄像头拍照并将UI保存为图片
- 01-11Flex字体加粗问题只能对英文的字体加粗
- 01-11flex利用webservice上传照片实现代码
- 01-11Flex控制弹出窗口拖动范围示例代码
- 01-11flex内嵌html网页示例代码
- 01-11Flex中在Tree绑定数据后自动展开树节点的方法
- 01-11Flex弹出窗口请求Action函数示例
- 01-11Flex中通过RadioButton进行切换示例代码
- 01-11Flex中TabNavigator设置Tabs样式思路及源码
阅读排行
本栏相关
- 01-11flex调用webservice中的自定义类的方法
- 01-11Flex实现的上传摄像头拍照并将UI保存
- 01-11datagrid不可编辑行有关问题的控制方法
- 01-11Flex控制弹出窗口拖动范围示例代码
- 01-11flex利用webservice上传照片实现代码
- 01-11Flex字体加粗问题只能对英文的字体加
- 01-11Flex中在Tree绑定数据后自动展开树节点
- 01-11flex内嵌html网页示例代码
- 01-11Flex中通过RadioButton进行切换示例代码
- 01-11Flex弹出窗口请求Action函数示例
随机阅读
- 01-10使用C语言求解扑克牌的顺子及n个骰子
- 01-10delphi制作wav文件的方法
- 04-02jquery与jsp,用jquery
- 08-05dedecms(织梦)副栏目数量限制代码修改
- 01-11Mac OSX 打开原生自带读写NTFS功能(图文
- 01-11ajax实现页面的局部加载
- 08-05织梦dedecms什么时候用栏目交叉功能?
- 08-05DEDE织梦data目录下的sessions文件夹有什
- 01-10SublimeText编译C开发环境设置
- 01-10C#中split用法实例总结