07 May

AS3 events

While working with Bloom Lite framework, I have discovered Native Signals – “a new approach for AS3 events, inspired by C# events and signals/slots in Qt.” I have read before, that Events in Flash was slow, but I have also read, that the fastest way to do events is just call required listener (function) directly.
And I’ve decided to make my own fast and ugly approach for AS3 events.
It has only one class and, I believe, works super fast.
It is available for download from GitHub: https://github.com/pozirk/misc, and it’s very easy to use, here is an example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
public class MyClass extends Eventer
{
  public static const MYEVENT:uint = 1;
  ...
  public function myFunc():void
  {
    if(...) //something happened
      fireEvent(MYEVENT, anyObjectHere);
  }
}
 
...
 
var my:MyClass = new MyClass();
my.addEvent(MyClass.MYEVENT, funcToCall);
 
...
 
public function funcToCall(obj:Object):void
{
  ...
}

So, any class can extends Eventer class, or just has it as a variable, and each class defines its own events (static IDs), which can be fired.

My approach doesn’t have anything like bubbling or capture phases, also there is only one listener possible for every event, but I was aiming for speed and I have thrown away everything and made it as fast as possible.
Hope, it will be useful for someone else, although there is nothing special here.

Leave a Reply

Your email address will not be published. Required fields are marked *