Every now and then, ActionScript 3.0 bums me out. Sometimes, when you want to do a thing seemingly straightforward, AS3 makes you drudge through a lot of monotonous boilerplate coding. For me, this is most true when creating custom events. That’s why I was so relieved to come across Robert Penner’s AS3 Signals. AS3 Signals is a faster and easier way to deal with events—particularly custom events—in AS3. I haven’t delved too deep into its capabilities but what I have experienced so far has been fantastic. 

The first time I tried to create a custom event in AS3, it was pretty intimidating, especially if I wanted that event to carry a custom property with it. After I got used to the process, it quickly turned from intimidating to just plain annoying: make a new class extending Event, create a string constant for your event type, override clone(), override toString()…Seriously? I just wanted my shopping cart to know when a product was added and what that product was.

With AS3 Signals, signals (you can think of them as events) are properties of the objects that dispatch them, not classes unto themselves. This system leads to two huge time-saving benefits: 1. you don’t need to worry about your object extending eventDispatcher, and 2. you don’t have to create a bunch of custom event classes. On top of that, AS3 Signals offers some great features you wish were part of the native AS3 Event architecture, like addOnce (makes sure your listener is only triggered the first time the signal fires), and removeAll (removes all listeners of a signal).

The features go even deeper with DeluxeSignal which gives you access to familiar event properties like target, and NativeSignal which translates the native AS3 events you use all the time to a signal.

I can see this new framework completely replacing my custom event needs in AS3. And at that point, why not use NativeSignal for your non-custom events to keep things consistent?

Once I get a few more projects under my belt using AS3 Signals I plan to put up a short tutorial. Until then, you can get acquainted using the links below.

Resources

- AS3 Signals download, info, and morehttps://github.com/robertpenner/as3-signals/wiki

- A great intro tutorial by Aiden Tailorhttp://insideria.com/2010/10/an-introduction-to-as3-signals.html

- Video intro tutorial by John Linquist (I much prefer video tutorials): http://johnlindquist.com/2010/01/21/as3-signals-tutorial/

- AS3 Signals creator Roboert Penner’s blog: http://robertpenner.com/flashblog/

Blog comments powered by Disqus