Do I need unique event type identifiers in as3?

Let's say I have two classes that 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 good that both declare an event type using the same string "click"?

Or should event type identifiers be unique throughout the application?

+3
source share
2 answers

You may run into conflicts. This will be very obvious if you use bubbles or listen to both events on the same object. Essentially, event listeners listen on a string. There is no strong typing, just checking if (string == type) (this is simpler, but essentially what happens).

:

public static const EVENT_TYPE_ONE:String = "eventTypeOne";

[Event(name="eventTypeOne", type="com.me.events.CustomEvent")], .

+5

CustomEventOne , addEventListener CustomEventOne.EVENT_TYPE_ONE, , CustomEventOne.EVENT_TYPE_ONE, CustomEventTwo.EVENT_TYPE_TWO, "click". , , .

0

Source: https://habr.com/ru/post/1720027/


All Articles