If you haven’t heard about Robert Penner’s AS3 Signals yet, you’re missing out. Until yesterday I had only briefly looked at the project but after John Lindquist’s video tutorial I’m completely sold on the idea and look forward to using it in my projects.
So what is AS3 Signals suppose to do for you?
Well for one it uses composition rather than inheritance so you don’t need to have your class extend flash.events.EventDispatcher. You can dispatch a “signal” and pass any number of arguments with it, no more endless subclassing of flash.events.Event for creating your custom events.
There’s also some nice features that you don’t get with the traditional event handling in ActionScript 3.0, things like addOnce which makes sure a listener only gets triggered the first time, removeAll which removes all listeners on a Signal and numListeners that returns the number of listeners on a Signal instance.
Apart from the generic Signal class, you also have DeluxeSignal which allows you to define the target (it also has some experimental bubbling support using .parent) and the NativeSignal which lets you map native events like MouseEvent.CLICK to a Signal.
This AS3 Signals project makes for an incredibly easy way of working with events inside of ActionScript. Give it a try and let me know what you think!
Watch the video tutorial