AS3 Event handling- Part 2

In the previous post we checked out some issues with AS2 event handling mechanism. In this post we will look at some well known words used  in AS3 event handling. AS3 has radical changes compared to AS2 version of action script. In terms of event handling, it provides you more control over event propagation( hey, I will tell you about this term latter, wait for this) . Here are the list of some keyword that are used in the event handling codes.

EventDispatcher: It’s the object of a class that is able to dispatch some event. Internally this class has a base class EventDispatcher  which enables the class object dispatch event and keep the track of it’s listeners by a method called addEventListener. It dispatches any event by dispatchEvent method. An example is given below.

  1. dispatchEvent(new Event(Event.CLOSE));

EventObject: Event object is an instance of the event class or or it’s subclass which holds information about the event (occurrence, source of the event, event flow and other details). For example when we click by the help of the mouse on an sprite instance, it dispatches an mouse click event. This mouse click event object is an instance of the MouseEvent and provides details of the event.
Event Target: Target of an event is usually the object that is responsible for the event dispatch. In the above example the class containing the code is the default target. But not necessarily it’s always. If the object has some inner child objects then the event target changes to the innermost child( We will discuss about this complex thing latter in details).

Event Listeners: These are the methods we write how to handle the event when it occurred. An example might clarify this. So look below.

  1. private function eventHandler(eventObject:EventType):void
  2. {
  3.     trace(eventObject.target);// this would give you name of the class that dispatches the event.(e ventTarget name).
  4. }
  5.  
  6. eventTarget.addEventListener(EventType.EVENT_NAME, eventHandler);

In the next post we will create an example and study it to explore more about the AS3 events.

This entry was posted in Flash. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>