Posted by sortofme on February 29th, 2008
In AS 3.0, if you do want to pass params in your Events you can create your own custom events:
Actionscript:
-
package{
-
-
import flash.events.Event;
-
-
class CustomEvent extends Event{
-
-
public static const MOUSE_DOWN:String = "onMouseDown";
-
-
public var myString:String;
-
-
public function CustomEvent( type:String, str:String ){
-
myString = str;
-
super( type );
-
}//...
-
-
/*_______you then dispatch this like this______*/
-
-
//in hboxvar
-
//you would have to import your custom event
-
dispatchEvent( new CustomEvent( CustomEvent.MOUSE_DOWN, "1,2,3") )
-
-
//again you would need to import your custom event
-
hboxvar.addEventListener( CustomEvent.MOUSE_DOWN, dosomething );
-
-
private function dosomething( event:CustomEvent ):Void{
-
trace( event.myString ) // output: 1,2,3
-
}
another interesting approach can be found here, where flep assigns multiple event types to one custom event, to have more variety in eventHandling.
But probably the most flexible of solutions is to add to the custom Event an Array, as Parameter, alllowing multiple parameters to be passed on when dispatched.
comment: display CustomEvent classÂ
Recent Comments