PDA

View Full Version : Declaring event types


rawmantick
09-29-2009, 06:22 AM
Hi guys.

Say I'm making some pure AS3 component. It dispatches some custom events with different types and those events bring some extra data along with them.

I'd love to hear pros&contras, opinions, thoughts and anything about a better place of declaring event types. Is it better to declare constants in a custom event class, or is it better to have all those types declared in an event source (the component)?

Maybe the conversation will turn to an absolutely different direction, which is also desired actually.

Any general thoughts about event flow organizing are all good too.

wvxvw
09-29-2009, 06:30 AM
Constants - in the event class. Meta - in the component... Event's meta is recognized by Flash compiler too, so, you should be fine with it whichever compiler you're using (although, not sure about HaXe).

rawmantick
09-29-2009, 06:36 AM
Thanks wvxvw. So far I stay for declaring constants in an event class.

newblack
09-29-2009, 12:52 PM
the type attribute in the event metadata indicates the class that defines the constant, so it is fine to define those constants in your component, though i agree it's less clean.

ASWC
09-29-2009, 02:53 PM
Put constants in an Event class. If you were to create ASDocs that would make it simpler and well organized too.

-Ev-
10-01-2009, 02:22 PM
Definitely in the event class. All of Adobe's event types are declared in the event class they belong to. If nothing else, it's good to follow the standard that you're using for the built in event classes.

senocular
10-01-2009, 02:37 PM
I do both. I tend to use native event classes where possible, so rather than creating entirely new (and often rendundant) classes for new events, I'll create constants for event types in the classes that dispatch those events.

maskedMan
10-02-2009, 03:11 AM
It depends on how close to deadline the project is and whether the event needs to carry any extra data beyond the .target. My preference is to always keep the constant in the custom event declaration, as that is the convention Adobe has set forth.

If a quick fix has to go in immediately though, it can be easier to just declare the constant somewhere in the class itself... or (horror of horrors) just use a string literal. Not my proudest moments, but when you're under the gun and every second counts, creating a new event is out of the question