Using button and movie clip event handlers
You can attach event handlers directly to a button or movie clip instance by using the
onClipEvent()
the
handler handles button events. You can also use
on()
clips that receive button events. For more information, see
states" on page
88.
To use an
or
on()
clip on the Stage and specify the event you want to handle for that instance. For example, the
following
event handler executes whenever the user clicks the button that the handler is
on()
attached to.
on(press) {
trace("Thanks for pressing me.");
}
You can specify two or more events for each
ActionScript in a handler executes when either of the events specified by the handler occurs. For
example, the following
out of the button.
on(rollOver, rollOut) {
trace("You rolled over, or rolled out");
}
You can also attach more than one handler to an object if you want different scripts to run when
different events occur. For example, you could attach the following
the same movie clip instance. The first executes when the movie clip first loads (or appears on the
Stage); the second executes when the movie clip is unloaded from the Stage.
onClipEvent(load) {
trace("I've loaded");
}
onClipEvent (unload) {
trace("I've unloaded");
}
For a complete list of events supported by the
on page 583
and
Event handling through
event handler methods that you define. For example, suppose you have a button in a SWF file;
the button can have an
can have an
onPress
rotate. When the button is clicked, the SWF file plays and the object rotates. Depending on your
preference, you can use
handling. However, the scope of variables and objects in
different than in event handler and event listeners. (See
You can attach
onClipEvent()
the Stage during authoring. You cannot attach
that are created at runtime (using the
handlers to objects created at runtime, use event handler methods or event listeners. (See
event handler methods" on page 83
and
handlers. The
on()
handler, attach it directly to an instance of a button or movie
onClipEvent()
handler attached to a button executes whenever the mouse rolls over
on()
on page
onClipEvent()
and
on()
onClipEvent()
handler that tells the SWF file to play, and the same button
on(press)
method, for which you define a function that tells an object on the Stage to
and
on()
onClipEvent()
and
on()
attachMovie()
and
handler handles movie clip events, and
onClipEvent()
on()
"Creating movie clips with button
handler, separated by commas. The
on()
and
on()
onClipEvent()
584.
doesn't conflict with event handling through
, event handler methods, or both types of event
on()
"Event handler scope" on page
only to movie clip instances that have been placed on
onClipEvent()
method, for example). To attach event
"Using event listeners" on page
Using button and movie clip event handlers
with movie clips to create movie
onClipEvent()
event handlers, see
and
handlers is
onClipEvent()
or
to movie clip instances
on()
85.)
handlers to
on()
88.)
"Using
87
Need help?
Do you have a question about the FLASH MX 2004 - ACTIONSCRIPT and is the answer not in the manual?