User Guide

63
4
CHAPTER 4
Handling Component Events
Every component has events that are broadcast when a user interacts with it (for example, the
click and change events) or when something significant happens to the component (for
example, the
load event). To handle an event, you write ActionScript code that executes when
the event occurs.
Each component broadcasts its own set of events. This set includes the events of any class
from which the component inherits. This means that all components, except the media
components, inherit events from the UIObject and UIComponent classes, because they are
the base classes of the version 2 architecture. To see the list of events a component broadcasts,
see the components entry and its ancestor classes’ entries in the Components Language
Reference.
This chapter uses several versions of a simple Macromedia Flash application, TipCalculator,
to teach you how to handle component events. The FLA and SWF files are installed with
Flash to:
In Windows: the C:\Program Files\Macromedia\Flash 8\Samples and
Tutorials\Samples\Components\TipCalculator folder.
On the Macintosh: HD/Applications/Macromedia Flash 8/Samples and Tutorials/
Samples/Components/TipCalculator folder.
This chapter contains the following sections:
Using listeners to handle events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Delegating events. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
About the event object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Using the on() event handler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78