PDA

View Full Version : custom event with multiple types


scorpion9
06-09-2010, 05:18 PM
hi

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
MouseEvent.CLICK
MouseEvent.MOUSE_DOWN
...

i know how to make CustomEvent.Type1 but i have no idea how to add other types.

any ideas

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

Example:


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);
}
}
}

scorpion9
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.

henke37
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.

scorpion9
06-10-2010, 05:38 PM
thanks for the reply.

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