Alright so I have been doing a lot of research on frameworks and structures for building out some classes of my own at work. We have a lot of code we share between developers and its finally time to move things into a bit more of a structured framework and leverage some of our reusable code. The first hill I had to climb was events. In AS3 events are really our communication pipeline. We use events to talk between objects while still keeping a nice Object Oriented independent structure. Events have there flaws though. The biggest of which, for me, is the lack of a real world usable way to outline for other developers when to use events in an interface. It is currently not possible in AS3 for an interface to dictate what events should be dispatched. Yes I have seen workarounds and even though they do fix the problem they also create more work then needed. This is where Signals comes into play.
As3 Signals is a library for dispatching events through composition instead of inheritance. A class does not need to extend EventDispatcher to use a signal and with that comes the ability to control the listeners to your signal. You can clear out everyone listening, add a listener only one time, and a lot of other neat features. The big deal though is performance. Is it faster? Well I threw together a little experiment using gSkinners Performance Harness to test dispatching 100000 events using a Event Dispatcher and then again using a Signal. The Tests start with 0 listeners to the signal and the event dispatcher and move up to 5. You can see the Performance Tests Here and if your interested in running this yourself feel free to download the code.
If your not interested in looking at all, let me just tell you signals is faster, though oddly enough when there are 0 listeners event dispatching is faster. Honestly I can’t imagine this happens very often though! Hope this helps some people out. Maybe in the near future I will pump out a small signals tutorial for those interested, doubtful though as I don’t think I could any better then this John Lindquist Signals Tutorial. Check it out!