Sunday, November 7, 2010

Flash - ActionScript - Event Handling - Create a Listener - Create and Specify a Function

The first step in event handling is to create a listener that will detect the event.

A listener looks something like this:

wheretolisten.addEventListener(whatevent, responsetoevent);



The actual command is addEventListener().
wheretolisten is the object where the event occurs (usually a button). [e.g. "btn1" (a button that you named btn1)]
whatevent is the specific kind of event (such as a mouse click).  [e.g. "MouseEvent.CLICK" ]
respondtoevent is the name of a function that is triggered when the event happens. [e.g. "showimage1" (a function that you naemed showimage1)]




The next step is to create a function that will respond to the event.

A function is simple a group of actions that are bunched together. You can trigger a function be referencing its name.

A function looks something like this:

function showimage1 (myEvent: MouseEvent) {};

In the above example, the function receives one parameter (within the parentheses) called myEvent, which is an event that involes the mouse. The item following the colon indicates what type of object it is. If the function is triggered, all the actions between the curly brackets are executed.


**reference: "Adobe cs5 Flash Classroom in a Book"

No comments:

Post a Comment