Here is an easy and efficient tool i made for my last past projects that will help you to deals with events in flash 8.

I wasn't that much used to use the dispatch event technics, but sometimes they are very helpful. But the built in class from macromedia has a serious problem of preparation and scopes. For example listeners and event spreaders were directly linked, i couldn't link a listener after 2 or 3 levels of classes hierarchy...

So i wrote a global static class that is able to deals with arrays of events, add/remove listeners for each event.

With this system you can wait for an event from anywhere from your projects, and trigger that event from anywhere.

(I also made a little benchmark between my class and the original dispatchevent class, and performance is quite the same.)

Download :

You can download a simple fla example : here

Example :

Here is a simple example that explains how to deploy both listener and trigger calls :

Code for the listener

import net.lecrabe.core.EventManager;

// create the listener

function onMove(rot:Number){

trace("scene receives rotation : "+rot);

}

// tell the manager to add me as a listener of "onMove"

EventManager.addListener("onMove", this);

Code for the event trigger

import net.lecrabe.core.EventManager;

EventManager.sendEvent("onMove", 4);

Extra:

You can also speciefied to hear the event once, so that the listener would be removed when the event occured :

EventManager.addListener("onMove", this, true);

Another big plus of this class is that you can send and collect arguments through the functions.

(with the dispatchevent class, you had to deal with variables associations) :

function onMove(rot:Number, cw:Boolean, text:String){

trace("scene receives rotation : "+rot+" clockwise="+cw+" ok="+text);

}

EventManager.sendEvent("onMove", 4, true, "yes");