Kerry Thompson wrote:
Henrik Andersson wrote:
Custom events are usually overkill.
If I understand you correctly, Henrik, I disagree. Custom events are
incredibly useful.
That they are. But they are not miracle tool. You should use them wisely
and only when it makes sense.
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.
Sounds like you missed Event.COMPLETE, it is just as good to signal when
a task is done.
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.
Did you bother adding any properties in your custom class? If not, you
could just have used the Event class instead.
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.
Actionscript is a garbage collected language, objects can not vanish
while they are used as the value of this for a method. And if you manage
to pull a stunt like that in something like c++, bad you.
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders