
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Flash 5’s on( ) and onClipEvent( ) Handlers
|
229
When exporting to Flash 5 format, you must use the Flash 5–style event syntax. A
single button handler can respond to multiple events, separated by commas. For
example:
on (rollOver, rollOut) {
// Invoke a custom function in response to both the rollOver and rollOut events
playRandomSound( );
}
To upgrade such code to Flash MX’s preferred syntax, using the same callback han-
dler to respond to both events, you’d use:
theButton.onRollOver = playRandomSound;
theButton.onRollOut = playRandomSound;
or, even more tersely:
theButton.onRollOver = theButton.onRollOut = playRandomSound;
Flash 5–style movie clip onClipEvent( ) handlers take the form:
onClipEvent (eventName) {
statements
}
Again, the eventName is the name of the corresponding Flash MX event handler prop-
erty, with the word “on” removed. For example, the Flash MX MovieClip.
onEnterFrame( ) event handler was implemented as follows in Flash 5:
onClipEvent (enterFrame) {
statements
}
Unlike button handlers, clip handlers can respond to a single event only.
Events introduced after Flash 5 are not available in on( ) or
onClipEvent( ) form. For example, there is no such thing as
onClipEvent(setFocus), because the onSetFocus( ) event was intro-
duced in Flash MX and first supported by Flash Player ...