Get Control of Your AS3 Event Flow With Signals
Karl Macklin
•
27 min read
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
Please
accept marketing cookies
to load this content.
Links
- Signals on github: https://github.com/robertpenner/as3-signals
- Robert Penner on Twitter: http://twitter.com/robpenner
- Guide to FlashDevelop: https://code.tutsplus.com/anfangerleitfaden-fur-flashdevelop-basix--active-7168t
Signals Cheat Sheet
1 |
|
2 |
// Create a Signal without specific Value Classes
|
3 |
var signal:Signal = new Signal(); |
4 |
|
5 |
// Add listeners
|
6 |
signal.add(myListener); |
7 |
signal.add(myOtherListener); |
8 |
|
9 |
// Dispatch signal
|
10 |
signal.dispatch(); |
11 |
|
12 |
// Add one-time listeners that gets removed after first call
|
13 |
signal.addOnce(willOnlyBeCalledOnceListener); |
14 |
|
15 |
// Remove listener
|
16 |
signal.remove(myListener); |
17 |
|
18 |
// Dispatch signal with values
|
19 |
signal.dispatch("my string", "my other string", instanceOfObject); |
20 |
|
21 |
// Create a Signal WITH specific Value Classes
|
22 |
var signalWithValueClasses:Signal = new Signal(String, int); |
23 |
// Any dispatch on this Signal requires at least a String and an int but can accept more than that, like so:
|
24 |
signalWithValueClasses.dispatch("hello", 25, "I'm optional, but allowed!"); |



