Several ActionScript classes have something called events. An event is raised by an object when a specific event occurs. For example, when someone hovers over a button symbol in SWF, the Button.onRollOver event is raised for this particular Button instance. When the mouse moves to another location, the Button.onRollOut event is raised for the same instance. These events occur regardless of whether anyone notices or not. If you want to do something in response to an event, you must control it using an event handler or event listener. The choice between the two is determined by the object - some objects are expected by handlers, some by listeners - so get into the ActionScript language reference when in doubt. Handlers are relatively lightweight, but for some reason, listeners seem to be perplexed at first.
Event handlers
The most popular events probably belong to the Button and MovieClip classes, which, as a rule, have much in common (a clip can be a button, but not vice versa). To handle the Button.onRelease event, all you have to do is drag the button symbol to the Stage and assign it an instance name using the Property inspector. Use this name in a script frame to assign a function to an event.
myButton.onRelease = function() {
Other Button events work the same way as MovieClip events, and all events that require event handlers.
You can handle any number of events. Assign a function to each event, if necessary. For example, a button that responds to rollover, release, and deployment might look like this:
myButton.onRollOver = function() { // do something } myButton.onRelease = function() { // do something } myButton.onRollOut = function() { // do something }
Event listeners
Managing event listeners requires a few more steps. The listener is executed using a shared instance of the object. This object acts as a connection between at least two others: the object that triggers the event, and any objects that listen to the event. Let's take a look at the MovieClipLoader example.
var mcl:MovieClipLoader = new MovieClipLoader();
At this point, weve declared a variable mcl, which points to an instance of MovieClipLoader. Now, well declare another mclListener variable that points to an instance of the object. (Sounds funny, I know, but created an Object.)
var mclListener:Object = new Object();
This shared object will now become our connection. At this point, the code is very similar to the event handler approach.
mclListener.onLoadInit = function() {
I could select any event from the MovieClipLoader class, it really doesn't matter. It should be noted here that the shared object processes the event on behalf of the instance of the operational class. With event handlers, an instance of the operational class processes its own events.
Now that we have our listener, and now that the function has been assigned to one of its events on behalf of our MovieClipLoader instance, we just need to subscribe to the listener on mcl.
mcl.addListener(mclListener);
Done. Let's see that all in one case:
var mcl:MovieClipLoader = new MovieClipLoader(); var mclListener:Object = new Object(); mclListener.onLoadInit = function() {
To listen to more than one event, simply follow its example with an event handler.
var mcl:MovieClipLoader = new MovieClipLoader(); var mclListener:Object = new Object(); mclListener.onLoadStart = function() {
Link: http://www.quip.net/blog/2006/flash/event-handlers-listeners
You can also check this Yahoo answer