
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
228
|
Chapter 10: Events and Event Handling
Flash 5’s on( ) and onClipEvent( ) Handlers
Earlier in this chapter, we discussed how to assign callback functions to the event
handler properties MovieClip.onEnterFrame( ) and TextField.onSetFocus( ). In Flash
5, these kinds of event handler properties were available on XML and XMLSocket
only. Movie clips and buttons used idiosyncratic event handler syntax attached
directly to physical clips or buttons in the Flash authoring tool. Button event han-
dlers were defined using on(
eventName), and movie clip event handlers were defined
using onClipEvent(
eventName), where eventName specified the event to be handled. As
of Flash MX, use of these older forms is generally discouraged. Event handler proper-
ties and event listeners are preferred because they promote the separation of code
from the visual elements of a movie. However, the older syntax is still supported, and
there are a few special cases where it is actually required (for examples, see Mov-
ieClip.onLoad( ) and Button keyPress in the Language Reference).
Flash 5–style button on( ) event handlers take the form:
on (eventName) {
statements
}
The eventName is the name of the corresponding Flash MX event handler property,
without the word “on” and with the first letter lowercase. For example, ...