Peter Elst

Founding Partner – Project Cocoon

AS3 Signals – the best thing since sliced bread

with 8 comments

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

 

Creative Commons License
This work, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.0 Belgium License.

No related posts.

Written by Peter

January 22nd, 2010 at 12:25 pm

Posted in ActionScript

33 Tweets

8 Responses to 'AS3 Signals – the best thing since sliced bread'

Subscribe to comments with RSS or TrackBack to 'AS3 Signals – the best thing since sliced bread'.

  1. Hey Peter,

    I’ve seen the basic used in many AS3/Flex projects before where you have one custom event class with an Object property to avoid having to create a massive amount of custom event classes. However, that system doens’t have type checking, whereas this one (I suppose) does.

    Looks promising and I will give it a try when I find the time…

    Steven

    Steven Peeters

    22 Jan 10 at 12:51 pm

  2. I wonder whether this would play nice with frameworks that manage events. I find myself working with Parsley a lot lately and it would be nice if I could combine Parsley messaging and something like AS3 signals. That would remove even more of the event handling hassle.

    Max

    22 Jan 10 at 1:25 pm

  3. I have a massive project I’m about to start with. I think I’ll give this a try and see how it goes. Seems very cool.

    Eric Dolecki

    22 Jan 10 at 7:04 pm

  4. cool Eric, let us know how it goes — its always difficult to judge from example code if it scales well to larger real world apps.

    Peter

    22 Jan 10 at 7:48 pm

  5. Paul Robertson

    22 Jan 10 at 7:50 pm

  6. I always felt myself embarrassed working with the custom events in as3, every times looks like it’s a question of workarounds and tricky over the normal syntax.. resulting in bad code.

    I worked on a project with c++ and Qt, where slot and signal policy are the normal way to dispatch events, and this kind of “porting” (if we can call it in this way) is exactly what i’m looking for.

    Composition against Inheritance looks like an old fight, the point here is not which one is better in theory, but which is better in its implementation, and inheritance implementation of events in as3 wasn’t planned in a good way.

    Nicola Bortignon

    23 Jan 10 at 1:15 am

  7. I took a look at the code, and I like the idea but it’s probably than events since events are native in AS3.

    ariel sommeria

    25 Jan 10 at 1:13 pm

  8. I don’t see anything wrong with programming and having the idea of looking ahead of the application.

    The import concept for classes is enough and simple
    to diagram your application.

    I also hear a big buzz on “Flash” dying out cuz
    too many developers can’t write and get use to as3.

    Is simple, just practice

    Sharedtut

    1 Feb 10 at 5:41 am

Leave a Reply

« Back to text comment

Twitter Users
Enter your personal information in the form or sign in with your Twitter account by clicking the button below.

Additional comments powered by BackType