Event Listeners

Event listeners are an important part of Flash. What they allow you to do is to “listen” for an event that occurs on a specific object. For example, one event that often occurs in Flash is a button getting clicked. When a button is clicked the button object dispatches an event telling flash that is was clicked. Often times we want to respond to a click and function. Say we have a window that pops up and on the window there is a cancel button. We want the window to close when the cancel button is clicked. Here is the code:

cancelButton.addEventListener(MouseEvent.CLICK, handleClick);
function handleClick(event:MouseEvent):void
{
//Write the code here that closes the window
}

In this example I have added a button to the window and given it the instance name cancelButton. This allows me to listen to that button and respond to the events.

  1. Anonymous
    July 7, 2008 at 11:38 pm | #1

    so what do I enter into the “//Write the code here that closes the window”???

  2. October 16, 2008 at 7:20 pm | #2

    how could i define an object data type event listener? for example i want my eventlistener to return a value(object may be)…

    is there any way to do it? thanx so on.

  1. No trackbacks yet.