| package { import flash.display.Sprite; public class DispatchEventDemo extends Sprite { public function DispatchEventDemo() { new A new B } } } |
| package { import flash.events.EventDispatcher; public class DT { private static var _dispatcher:EventDispatcher; public static function get dispatcher():EventDispatcher{ _dispatcher=_dispatcher==null?new EventDispatcher:_dispatcher return _dispatcher } } } |
|
package {
import flash.events.Event public class EventX extends Event { public static const RECEIVE_ARG:String="receive_arg"; private var _arg:Object public function EventX(type:String,arg:Object,bubbles:Boolean=false,cancelable:Boolean=false) { super(type,bubbles,cancelable); _arg=arg; } public function get arg():Object { return _arg;//返回参数对象 } } } |
|
package {
import flash.events.* public class A { public function A() { var dispatcher:EventDispatcher=DT.dispatcher; dispatcher.addEventListener(EventX.RECEIVE_ARG,onTrace); } private function onTrace(evt:EventX):void{ trace(evt); trace(evt.arg.a) trace(evt.arg.b) } } } |
| package { public class B { import flash.events.* public function B() { var dispatcher:EventDispatcher=DT.dispatcher; dispatcher.dispatchEvent(new EventX(EventX.RECEIVE_ARG,{a:"arg:a",b:"arg:b"})); } } } |
admin#flashas.net (#为@) 联系QQ:
:40777822
浙ICP备06033001号