Creating movie clips with button states
When you attach an
mouse event handlers for a movie clip instance, the movie clip responds to mouse events in the
same way as a button does. You can also create automatic button states (Up, Over, and Down) in
a movie clip by adding the frame labels
When the user moves the mouse over the movie clip or clicks it, the playhead is sent to the frame
with the appropriate frame label. To designate the hit area used by a movie clip, you use the
property of the MovieClip class.
hitArea
To create button states in a movie clip:
Select a frame in a movie clip's Timeline to use as a button state (Up, Over, or Down).
1
Enter a frame label in the Property inspector (
2
To add additional button states, repeat steps 1–2.
3
To make the movie clip respond to mouse events, do one of the following:
4
Attach an
on()
movie clip event handlers" on page
Assign a function to one of the movie clip object's mouse event handlers (
onRelease
Event handler scope
The scope, or context, of variables and commands that you declare and execute within an event
handler depends on the type of event handler you're using: event handlers or event listeners, or
and
on()
onClipEvent()
Functions assigned to event handler methods and event listeners (like all ActionScript functions
that you write) define a local variable scope, but
For example, consider the following two event handlers. The first is an
associated with a movie clip named
movie clip instance.
// Attached to clip_mc's parent clip Timeline:
clip_mc.onPress = function () {
var color; // local function variable
color = "blue";
}
// on() handler attached to clip_mc:
on(press) {
var color; // no local variable scope
color = "blue";
}
Although both event handlers contain the same code, they have different results. In the first case,
the
variable is local to the function defined for
color
handler doesn't define a local variable scope, the variable scopes to the Timeline of the movie
on()
clip
.
clip_mc
For
event handlers attached to buttons, rather than to movie clips, variables (as well as
on()
function and method calls) are scoped to the Timeline that contains the button instance.
88
Chapter 4: Handling Events
handler to a movie clip, or assign a function to one of the MovieClip
on()
event handler to the movie clip instance, as discussed in
, and so forth), as discussed in
handlers.
clip_mc
,
, and
_up
_over
_down
,
, or
_up
_over
87.
"Using event handler methods" on page
and
on()
onClipEvent()
. The second is an
onPress
to the movie clip's Timeline.
).
_down
"Using button and
onPress
handlers do not.
event handler
onPress
handler attached to the same
on()
. In the second case, because the
,
83.
Need help?
Do you have a question about the FLASH MX 2004 - ACTIONSCRIPT and is the answer not in the manual?