You can use button events with button instances, but you can also use them with movie clip instances to create button movie clips. Button movie clips combine the power of movie clips with the control of button events. You can turn a movie clip into a button movie clip by assigning an on
handler to the movie clip instance, or by defining button event handler methods for an instance. You can also create a new class and define event handler methods in the prototype object of that class. (For information about defining methods in the prototype object, see Defining event handler methods in a class definition.)
All button events are triggered by user interaction: press
, release
, releaseOutside
, rollOver
, rollOut
, dragOver
, dragOut
, and keyPress
. In the Actions toolbox, the MovieClip object has an Events category containing methods that correspond to each button event, such as onPress
, onRelease
, onReleaseOutside
, onRollOver
, onRollOut
, onDragOver
, onDragOut
, and onKeyPress
.
A button movie clip has a full movie clip Timeline, not the four-frame Timeline of a button. You can use the frame labels _up
, _over
, and _down
to create the Up, Over, and Down states of a button movie clip. When the user moves the mouse over a button movie clip or clicks it, the gotoAndStop
action causes the playhead to go to the appropriate frame label and display the appropriate image on the Stage. If you want the playhead to start playing at the frame label, you can put a play
action on the frame.
To designate a movie clip to use as the hit area of a button movie clip, you use the hitArea
property of the MovieClip object.
For information about using button events with buttons, see Using button event handler methods to trigger scripts.
To use the on action to create a button movie clip:
on
action.on
action, add actions to run when the selected events occur. To define a movie clip event handler method to create a button movie clip:
object
parameter, enter the target path for the movie clip whose event you want to handle.The following code defines a function for the onPress
method of the instance mc
that moves the playhead of mc
:
mc.onPress = function() { play(); };
To create states for the button movie clip:
_up
, _over
, or _down
).