Sunday, July 31, 2011

Basic Event Listeners and Hadlers Actionscript 3.0

When you run a flash movie every time the mouse is clicked, it dispatches or broadcasts an event.

For example the below image shows an instance of simple button.This button has also been given the instance name of button1 in the Property inspector.


If you select frame 1 of the Actions layer and open the Actions panel, you will notice the following code, which will be responsible for detecting and responding to the CLICK event:
//Event Listerner
button1.addEventListener(MouseEvent.CLICK,Clicked)
//Event Handler
function Clicked(Evt:MouseEvent)
{
trace("Button1 Clicked");
}

The first two lines of code demonstrate what is needed for the invocation of the event listener.The second parameter in the addEventListener() method is the name of a function that
will execute when the event is detected, in this case Clicked().

0 comments: