Event Handler Syntax
The
names
of events (and their corresponding
event handlers) are predetermined by ActionScript. Button event
handlers are defined using on
(eventName
), and movie clip
event handlers are defined using onClipEvent
(eventName
), where
eventName
is the name of the event to be
handled.
Hence, all button event handlers (except
keyPres
s, which also
requires a key
parameter) take the form:
on (eventName
) {statements
}
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 therollOver
androllOut
events playRandomSound( ); }
All movie clip event handlers take the form:
onClipEvent (eventName
) {statements
}
Unlike button handlers, clip handlers can respond only to a single event.
Get ActionScript: The Definitive Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.