The event model is just a bunch of callbacks associated with event types (strings). The EventDispatcher
maintains this association and iterates over the callbacks when a specific event is triggered by it.
This is pretty trivial to recreate yourself, and in you case you can simplify it greatly.
Here's an example of what could be a simple EventDispatcher
in AS2:
function EventDispatcher():Object
{
var listeners:Object = { };
return {
addEventListener: function(type:String, callback:Function)
{
listeners[type] = callback;
},
dispatchEvent: function(type:String)
{
for(var i:String in listeners)
{
if(i === type) listeners[i]();
}
}
};
}
And its implementation:
// Create the event dispatcher.
var eventDispatcher:Object = EventDispatcher();
// Add an event listener as with AS3.
eventDispatcher.addEventListener("ending", endGame);
// Define the handler function.
function endGame():Void
{
trace("Game has ended.");
}
// Dispatch an event.
eventDispatcher.dispatchEvent("ending");
If you want to bring it closer to the AS3 Event model, you need to create an 'Event' object within the dispatchEvent
loop and pass that to the handler, something like this:
dispatchEvent: function(type)
{
for(var i:String in listeners)
{
var event:Object = { type: i, target: this };
if(i === type) listeners[i](event);
}
}