Get Control of Your AS3 Event Flow With Signals

Get Control of Your AS3 Event Flow With Signals

Tutorial Details
  • Difficulty: Intermediate
  • Platform: Flash (Flash Player 9+)
  • Language: AS3
  • Software Used: FlashDevelop (optional)
  • Estimated Completion Time: 30 minutes

In this screencast we’ll go over all you need to know about AS3 Signals — a light-weight strongly-typed alternative to the native Flash event system. Prepare to see events in a whole new way!

Signals is a library by Robert Penner that allows for easy AS3 messaging between objects and classes. It lets you wire your applications with better APIs and less boilerplate code than regular AS3 Events.

In this video, I’ll introduce Signals, with a simple demo application that shows how it can be used.


Watch the Screencast

Don’t like ads? Download the screencast, or subscribe to Activetuts+ screencasts via iTunes!


Links


Signals Cheat Sheet

// Create a Signal without specific Value Classes
var signal:Signal = new Signal();

// Add listeners
signal.add(myListener);
signal.add(myOtherListener);

// Dispatch signal
signal.dispatch();

// Add one-time listeners that gets removed after first call
signal.addOnce(willOnlyBeCalledOnceListener);

// Remove listener
signal.remove(myListener);

// Dispatch signal with values
signal.dispatch("my string", "my other string", instanceOfObject);

// Create a Signal WITH specific Value Classes
var signalWithValueClasses:Signal = new Signal(String, int);
// Any dispatch on this Signal requires at least a String and an int but can accept more than that, like so:
signalWithValueClasses.dispatch("hello", 25, "I'm optional, but allowed!");

Add Comment

Discussion 4 Comments

  1. Karl Macklin says:
    Author

    Hey everyone!

    I’ll be watching the comments here closely for at least a few days (and now and then from that point on) in case anyone has any questions/suggestions regarding this.

  2. Brennan says:

    I am not sure I understand why I would use this over regular flash events. Would you be able to explain how you would you this in a real life example? It seems like a great tool but feels redundant.

  3. Daniel Vergara says:

    Thks for the tutorial, I recently had a problem passing params to the callback function of a listener, but this is a great solution to that.
    I think that maybe is redundant too but it feel like a little more freedom because you write your own callback function as well.

    Thanks again!!

    PD: Somebody knows where I can find good resources about designing an object oriented software, I mean I need to understand how I get started making a good object-oriented software with AS3.

  4. AS3-Signals is great.

    Here is a slideshow, GIT Code Sample, and screencast video about the fantastic AS3-Signals.

    http://www.rivellomultimediaconsulting.com/as3-signals-introduction/

Add a Comment

To add a code snippet to your comment, please wrap your code like so: <pre name="code" class="html">YOUR CODE</pre>. You can replace the class name with "js," "css," "sql," or "php." If there are any "<" or ">" within your code, please search and replace them with: &lt; and &gt; respectively.