View Full Version : custom event with multiple types
06-09-2010, 06:18 PM
i recently made a custom event and its easy.
what i didnt find though was a way to add different types of events under the same category e.g
i know how to make CustomEvent.Type1 but i have no idea how to add other types.
06-09-2010, 06:52 PM
You just have to make 'public static const'.
public class ZoomEvent extends Event
public static const START:String = 'zoom start';
public static const COMPLETE:String = 'zoom complete';
public static const ENABLE:String = 'zoom enabled';
public static const DISABLE:String = 'zoom disabled';
public var percent:Number;
public function ZoomEvent(type:String, percent:Number, bubbles:Boolean = false, cancelable:Boolean = false):void
super(type, bubbles, cancelable);
this.percent = percent;
override public function clone():Event
return new ZoomEvent(this.type, percent, this.bubbles, this.cancelable);
06-09-2010, 07:53 PM
ive tried this already.
it doesnt work with multiple constants.
super(type, bubbles, cancelable);//Doesnt work
super(COMPLETE, bubbles, cancelable);//works but doesnt enable to use different types
so basically if i give constants directly to the super () parameter, it works, but if i try to pass constructor parameter "type" it wont work.
06-10-2010, 02:09 PM
You have to let the constructor take the type as an argument. The posted exampel does exactly that. It also properly defines the clone method, be sure to not forget that method.
06-10-2010, 06:38 PM
thanks for the reply.
i got it working. i had a little mistake in event dispatcher as well
vBulletin® v3.8.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.