Here are the first 9 paragraphs of Chapter 22 of Essential ActionScript 3.0.
22. Interactivity
In this chapter we’ll see how to add interactivity to an application by responding to Flash Player’s input events. Specifically, we’ll explore five different categories of input events:
* Mouse events
* Focus events
* Keyboard events
* Text events
* Flash Player-level events
For each of the preceding event categories, we’ll consider the specific events offered by Flash Player’s API and the code required to handle those events.
The descriptions of the events covered in this chapter apply specifically to Flash Player (both the browser add-on and standalone versions), but are also generally applicable to any Flash runtime that supports mouse and keyboard input (such as Apollo). When working with other Flash runtimes, be sure to consult the appropriate documentation for information on input events. For official reference material covering Flash Player’s input events, see Adobe’s ActionScript Language Reference under the “Constants” heading of the Event class and its subclasses. See also the “Events” heading under the TextField, DisplayObject, InteractiveObject, and Stage classes.
Before we start our examination of specific input events, let’s take a quick look at some general rules that govern all input events.
InteractiveObject Instances Only
Input-event notifications are sent to instances of classes that inherit from InteractiveObject only (i.e., Sprite, TextField, Stage, Loader, MovieClip, SimpleButton and subclasses of those classes.) Other types of objects are not notified of input events, even if those objects are on the display list. For example, instances of the Shape class can be placed on the display list, but the Shape class does not inherit from InteractiveObject, so Shape instances do not receive input-event notifications. If a Shape object visually overlaps a TextField object and the user clicks the Shape object, then the TextField object—not the Shape object—will be the target of the resulting mouse-click event. To handle interaction with a Shape or Bitmap object, place that object in a container (Sprite or MovieClip) and register with that container for input events.
Display List Objects Only
Objects that are not on the display list when Flash Player dispatches a given input event cannot receive notification of that event.
Default Behavior
Some input events trigger a native response by Flash Player, known as a default behavior. For example, moving the mouse pointer over a SimpleButton instance causes that instance to display its “over”-state graphic. In some cases, Flash Player’s default behavior can be prevented using the Event class’s instance method preventDefault(). For details see “Preventing Default Event Behavior” in Chapter 12.
Now on to the events!