views:

70

answers:

3

Say I have two classes which extend Event:

public class CustomEventOne extends Event
{
    public static const EVENT_TYPE_ONE:String = "click";

     //... rest of custom event

and

public class CustomEventTwo extends Event
{
    public static const EVENT_TYPE_TWO:String = "click";

     //... rest of custom event

Is it ok that they both declare an event type using the same string "click"?

Or do event type identifiers need to be unique throughout the application?

A: 

I was wrong. ^ see correct answer

Allan
+3  A: 

You can definitely run into collisions with this. This will be very evident if you use bubbling, or listen for both events on the same object. At the core, the event listeners are listening for a string. There is no strong typing, just a if(string==type) check (this is over simple, but essentially what is happening).

it would be proper to name these event types:

public static const EVENT_TYPE_ONE:String = "eventTypeOne";

If you make use of any [Event(name="eventTypeOne", type="com.me.events.CustomEvent")] this syntax is essential.

Joel Hooks
Thanks for the clarification - I have always made events unique, I asking out of curiosity more than anything else...
Reuben
A: 

If your code listens for a CustomEventOne event on an object by calling addEventListener with CustomEventOne.EVENT_TYPE_ONE, that event handler will get called when the object dispatches either CustomEventOne.EVENT_TYPE_ONE or CustomEventTwo.EVENT_TYPE_TWO as both are essentially "click". As Joel stated, objects listen for event types which are plain strings.

Amarghosh