News - Happenings at iGeeks

January 28th, 2004

EventDispatcher for Actionscript 2.0

I had heard a lot of this being mentioned by many prominent Flash Developers, the other day I was talking to Peter Hall about the same, also heard of Peldi liking the same over AsBroadcaster (yes, the case have changed in AS 2.0), he even did a Server Side equivalent of the same, “Ported EventDispatcher to SSAS” and Jesse Warden have an entry on the same, “Two Reasons EventDispatcher is neato-cheato

For the Archive sake, here is something on EventDispatcher (thanks for Peter Hall for helping me);

/*
There are two ways to do the initialisation.
In the prototype (Example1) is more efficient more clumsy.
*/

class Example1 {
// these will be filled in with EventDispatcher.initialize
public function addEventListener (event:String, o:Object):Void{}
public function removeEventListener (event:String, o:Object):Void{}
private function dispatchEvent (o:Object):Void{}

function aMethod(){
//send the event:
dispatchEvent({type:”eventName”});
}

private static var dispatcherInited =
EventDispatcher.initialize(Example1.prototype);
}

class Example2 {
// these will be filled in with EventDispatcher.initialize
public function addEventListener (event:String, o:Object):Void{}
public function removeEventListener (event:String, o:Object):Void{}
private function dispatchEvent (o:Object):Void{}

function Example2{
EventDispatcher.initialize(this);
}

function aMethod(){
//send the event:
dispatchEvent({type:”eventName”});
}
}

Brajeshwar

Comments

Hey Brajeshwar,

If guess function decleration can also be like

public function addEventListener:Function;
public function removeEventListener:Function; private function dispatchEvent:Function;

Which one is better?

//Abdul