Friday, March 25, 2011

Passing parameters to event handlers in AS3

After along research I found a simple way where you can simply passing parameters to event hanlder.

in order to do this you need to extend the event class and create new custom class that will handle the parameters arguments as below :


  • create new class and name it EventType.as 
package {
// Import class
import flash.events.Event;
// EventType
public class EventType extends Event {
// Properties
   public var arg:*;
   // Constructor
   public function EventType(type:String, bubbles:Boolean = false, cancelable:Boolean = false, ... a:*) {
   super(type, bubbles, cancelable);
   arg = a;
   }
// Override clone
override public function clone():Event{
return new EventType(type, bubbles, cancelable, arg);
};
}
}

now all you need is to dispatch new event using EventType instead of event as below :

dispatchEvent(new EventType("TestHandler",false,false,"Test :)"))

private function TestHandler(e:EventType):void
{
trace( e.arg[0]);
}

hope it save your time :)

Create facebook Iframe Application Using flash AS3 API ( Updated Version ).

please like and post your questions :  http://www.facebook.com/pages/FlashCS5-Tutorials/176320862386436 After I have received a lot of requ...