| Programming ActionScript 3.0 > Flash Player APIs > Event Handling > Introduction to ActionScript event handling | |||
You can think of events as occurrences of any kind in your SWF file that are of interest to you as a programmer. For example, most SWF files support user interaction of some sort--whether it's something as simple as responding to a mouse click or something more complex, such as accepting and processing data entered into a form. Any such user interaction with your SWF file is considered an event. Events can also occur without any direct user interaction, such as when data has finished loading from a server or when an attached camera has become active.
In ActionScript 3.0, each event is represented by an event object, which is an instance of the Event class or one of its subclasses. An event object not only stores information about a specific event, but also contains methods that facilitate manipulation of the event object. For example, when Flash Player detects a mouse click, it creates an event object to represent that particular mouse click event. In this case, the event object is an instance of the MouseEvent class.
After creating an event object, Flash Player dispatches it, which means that the event object is passed to the object that is the target of the event. An object that serves as the destination for a dispatched event object is called an event target. For example, when an attached camera becomes active, Flash Player dispatches an event object directly to the event target, which in this case is the object that represents the camera. If the event target is on the display list, however, the event object is passed down through the display list hierarchy until it reaches the event target. In some cases, the event object then "bubbles" back up the display list hierarchy along the same route. This traversal of the display list hierarchy is called the event flow.
You can "listen" for event objects in your code using event listeners. Event listeners are the functions or methods that you write to respond to specific events. To ensure that your program responds to events, you must add event listeners either to the event target or to any display list object that is part of an event object's event flow.
These three basic ideas form the structure of the new event model: the event flow, event objects, and event listeners. A solid understanding of each concept is important if you want to respond to events that occur in your SWF file. For advanced developers, the new event model allows you to create and dispatch custom events, but this chapter focuses primarily on the events that are defined by ActionScript 3.0 and dispatched directly by Flash Player.
Flex 2
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flex/2/docs/00001925.html