Re: [Flashcoders] How to use DispatchEvent in AS2.0 class
Look at Grant Skinner article on using EventDispatcher: http://www.gskinner.com/blog/archives/23.html Basically you can use EventDispatcher in three ways. Here are a simple example: // create an Action instance var action:Action = new Action(); // create the listeners var listener1:Listener1 = new Listener1(); var listener2:Listener2 = new Listener2(); var listener3:Listener3 = new Listener3(); // add listeners to the action action.addEventListener("done", listener1); action.addEventListener("done", listener2); action.addEventListener("done", listener3.onDoneEvent); // trigger events by calling the perform() method action.perform(); The trace should look like: Action.perform() called Listener3.onDoneEvent() : event 'actionDone' received Listener2.handleEvent(): event 'actionDone' received Listener2.actionDone(): event 'actionDone' received Listener1.actionDone() : event 'actionDone' received - import mx.events.EventDispatcher; class Action { public var dispatchEvent:Function; public var addEventListener:Function; public var removeEventListener:Function; private var classname:String; public function Action(){ // enable class A to dispatch events // and handle listeners EventDispatcher.initialize(this); classname = "Action"; } public function get name():String { return this.classname; } public function perform():Void { // do some stuff trace("Action.perform() called"); // then dispatch the 'done' event to listeners dispatchEvent({target:this, type:"actionDone"}); } } - /* * Method 1: event is handle by a method whose name is * the same as the event name. */ class Listener1 { // Event handler for event of type 'done' public function actionDone(event:Object):Void { var type:String = String(.type); trace("Listener1.actionDone(): event '"+type+"' received"); } } - /* * Method 2: use of the generic method handleEvent(), which is called by * default by the EventDispatcher. This method can be useful to catch * any received events. * Note that the doneAction() method is also called. */ class Listener2 { public function handleEvent(event:Object):Void { var type:String = String(event.type); trace("Listener2.handleEvent(): event '"+type+"' received"); } public function actionDone(event:Object):Void { var type:String = String(event.type); trace("Listener2.actionDone(): event '"+type+"' received"); } } - /* * Method 3: The event is handle by a custom method. */ class Listener3 { public function onDoneEvent(event:Object):Void { var type:String = String(event.type); trace("Listener3.onDoneEvent(): event '"+type+"' received"); } } hidayath q a écrit : can anyone tell me.How to use DispatchEvent in AS2.0 class. Iike to to dispath an event from one class to another class which will have addEventListener to handle the event. Can anyone give a small example and explanation. Regards. S.Hidayath ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] How to use DispatchEvent in AS2.0 class
Hi, Your dispathing class may have those elements: // before your class declaration import mx.events.EventDispatcher // I your properties declaration public var dispatchEvent:Function; public var addEventListener:Function; public var removeEventListener:Function; // In your init method, or constructor EventDispatcher.initialize(this); // In your method where your want the event to be dispatched this.dispatchEvent({type:"PanelMove",direction:"open"}); // you can add all objetc properties you want... "type" is looked to identify wich event has been dispatched, all other props will be your parameters Then in your listening class, just add: // In your listening method (mcPanelClip is an occurence from the dispatching class, here a movieclip) this.fListeningFunc = Delegate.create(this,OnPanelMove); mcPanelClip.addEventListener("PanelMove",this.fListeningFunc); // The method wich receives the event pirvate funtion OnPanelMove(obj:Object):Void { trace (obj.direction) // all your params were transmitted through this "obj" object } ++ PR hidayath q a écrit : can anyone tell me.How to use DispatchEvent in AS2.0 class. Iike to to dispath an event from one class to another class which will have addEventListener to handle the event. Can anyone give a small example and explanation. Regards. S.Hidayath ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
[Flashcoders] How to use DispatchEvent in AS2.0 class
can anyone tell me.How to use DispatchEvent in AS2.0 class. Iike to to dispath an event from one class to another class which will have addEventListener to handle the event. Can anyone give a small example and explanation. Regards. S.Hidayath ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders