Henrik Andersson wrote:

> Custom events are usually overkill.

If I understand you correctly, Henrik, I disagree. Custom events are
incredibly useful.

AS3 is event-driven, and I routinely have all sorts of custom events.
In a recent game, I added event listeners to 7 different custom events
in the main class's constructor. When an animation in a MC finishes,
the MC sends the ANIMATION_FINISHED message. When the timer fires, it
sends another message. When the student answers a question, I send
another message.

I have a class that extends Event, and custom events are defined in
this class. So, when you send a custom event, you get an event object
just as you would with a system event.

To me, this is a lot cleaner and easier to follow than callbacks or
calls to other methods. It's also less prone to mysterious bugs--when
you call a method, it always returns to the caller. If that caller no
longer exists, you get a crash that can be very hard to diagnose. When
you send a custom message, the code doesn't automatically return to
the sender.

Or, perhaps I misunderstood your meaning.

Cordially,

Kerry Thompson
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to