[AS3]sendMediaEvent事件发送(自定义事件发送)(3)
第三种方法,实现IEventDispatcher接口。 package { importflash.display.Sprite; importflash.events.Event; importflash.events.EventDispatcher; /** *... *@authoraisajiajiao *使用IEventDispatcher接口 */ pu
第三种方法,实现IEventDispatcher接口。
- package
- {
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.events.EventDispatcher;
- /**
- * ...
- * @author aisajiajiao
- * 使用IEventDispatcher接口
- */
- public class CustomEventDispatcherDemo3 extends Sprite
- {
- public function CustomEventDispatcherDemo3()
- {
- var dispatcher:SampleEventDispatcher = new SampleEventDispatcher();
- //不推荐直接使用字符串表示事件类型,这里只是作为演示
- dispatcher.addEventListener("Custom",actionListener);
- dispatcher.dispatchEvent(new Event("Custom"));
- }
- private function actionListener(e:Event):void
- {
- trace("自定义事件发送类" + e);
- }
- }
- }
- import flash.events.Event;
- import flash.events.EventDispatcher;
- import flash.events.IEventDispatcher;
- //这样灵活性非常大,可以在这里实现你想要的各种功能
- class SampleEventDispatcher implements IEventDispatcher
- {
- public var _dispatcher:EventDispatcher;
- public function SampleEventDispatcher()
- {
- _dispatcher = new EventDispatcher();
- }
- public function addEventListener(type:String,listener:Function,
- useCapture:Boolean = false,priority:int = 0,useWeakReference:Boolean = false):void
- {
- _dispatcher.addEventListener(type,listener,useCapture,priority,useWeakReference);
- }
- public function dispatchEvent(event:Event):Boolean
- {
- return _dispatcher.dispatchEvent(event);
- }
- public function hasEventListener(type:String):Boolean
- {
- return _dispatcher.hasEventListener(type);
- }
- //注意这里的参数个数是与addEventListener数目不同的,仅有3个
- public function removeEventListener(type:String,listener:Function,useCapture:Boolean = false):void
- {
- _dispatcher.removeEventListener(type,listener,useCapture);
- }
- public function willTrigger(type:String):Boolean
- {
- return _dispatcher.willTrigger(type);
- }
- }
所有自定义事件最终的输出结果如下图:
http://blog.csdn.net/aisajiajiao/article/details/6960475
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...