View Full Version : custom event with multiple types

06-09-2010, 05: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.

any ideas

06-09-2010, 05:52 PM
You just have to make 'public static const'.


package classes
import flash.events.Event;

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, 06: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, 01: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, 05:38 PM
thanks for the reply.

i got it working. i had a little mistake in event dispatcher as well