自定义事件类

//Main文档类 package { import flash.display.Sprite; public class Main extends Sprite { public function Main():void { var tt:SetEventObject=new SetEventObject(); tt.addEventListener(MyEvent.FA_SHENG,an); tt.chufa(); } private function an(_event:MyEvent):void { trace(_event); } } } //MyEvent自定义事件类 package { import flash.events.Event; public class MyEvent extends Event { public static const FA_SHENG:String="发送了一个事件"; private var a:int; public function MyEvent():void { super(FA_SHENG); } public function get abc():int { return a; } public function set abc(n:int):void { a=n; } override public function toString():String { return formatToString("MyEvent","type","bubbles","cancelable","eventPhase","abc"); } override public function clone():Event { var evt:MyEvent=new MyEvent(); evt.a=a; return evt; } } } //SetEventObject发送事件类 package { import flash.events.EventDispatcher; public class SetEventObject extends EventDispatcher { public function chufa():void { var myevent:MyEvent=new MyEvent(); myevent.abc=45; dispatchEvent(myevent); } } }

你可能感兴趣的:(AS3/Flex)