Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 06-09-2010, 05:18 PM   #1
scorpion9
Senior Member
 
Join Date: Feb 2008
Location: Estonia
Posts: 453
Default custom event with multiple types

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
scorpion9 is offline   Reply With Quote
Old 06-09-2010, 05:52 PM   #2
jooniya
Interactive Des/Dev
 
Join Date: Jan 2010
Location: Philadelphia, PA
Posts: 232
Default

You just have to make 'public static const'.

Example:

ActionScript Code:
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);         }     } }
jooniya is offline   Reply With Quote
Old 06-09-2010, 06:53 PM   #3
scorpion9
Senior Member
 
Join Date: Feb 2008
Location: Estonia
Posts: 453
Default

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.
scorpion9 is offline   Reply With Quote
Old 06-10-2010, 01:09 PM   #4
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,833
Send a message via Skype™ to henke37
Default

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.
__________________
Signature: I wrote a pair of articles about the timeline.
henke37 is offline   Reply With Quote
Old 06-10-2010, 05:38 PM   #5
scorpion9
Senior Member
 
Join Date: Feb 2008
Location: Estonia
Posts: 453
Default

thanks for the reply.

i got it working. i had a little mistake in event dispatcher as well
scorpion9 is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:37 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.