Many people ask what is event handling, the answer is that it is the technique in which we specify action that should performed on the occurrence of particular event. In Action Script 3 the event handling contains the following three elements:
Event Source: It is the element which actually receives the event. For example a button could be event source which may receive the event click. It is also called as event target as it is targeted by Flash Player and where the event actually occurs.
The Event: Event is the action, to which you want to respond to. It may be rollover, rollout etc...
Event response: Event response are the list of actions which are performed in response to the above mention event.
The Model could be like this:
function The_response( eventObject:EventType)
{
// list of actions
}
eventSource.addEventListener(EventType:EVENT_NAME, The_response);
The code has two sections: The first is the function which we have defined to contain series of actions that are to be performed in response to the event. Here The_response is the function name. This function has the parameter. Specifying the parameters is just like declaring variable. Here we have declared the parameter. There is always a class associated with the events. These classes work as a data type for the parameters of function. In between the opening and closing braces we write code which is the series of actions that are to be performed in response to the event.
After defining the function we can now evoke this function by using event source( may be a button) on the occurrence particular event. We accomplish this by defining addEventListener() method. We have to use events name as the first parameter and the method name without parenthesis as the second parameter.
Monday, May 5, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment