
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Event Handlers Applied
|
243
5. Finally, to engage the event handler, attach the process clip to the appropriate
timeline using attachMovie().
6. To disengage the handler, remove the
process clip using removeMovieClip().
To see this technique in action, download “Event Loop, Controllable” from the
online Code Depot.
Event Handlers Applied
We’ll conclude our exploration of ActionScript events and event handlers with a
couple of real-world examples. These are simple applications, but they give us a
sense of how flexible event-based programming can be. For more event code sam-
ples, see the Language Reference coverage of the events associated with the objects
listed at the beginning of this chapter.
Example 10-2 makes a clip named
box_mc shrink and grow. The box_mc clip must be
square, and must have an initial size between
box_mc.maxHeight and box_mc.minHeight.
Example 10-3 simulates a custom mouse pointer by hiding the normal system
pointer and making a clip follow the mouse location around the screen. In the exam-
ple, the onMouseDown( ) and onMouseUp( ) handlers resize the custom pointer
slightly to indicate mouseclicks. The code is placed inside the clip that acts as the
custom pointer.
Example 10-2. Oscillating the size of a movie clip
// Set oscillation parameters
box_mc.sizeIncrement = 10; ...