Event handler scope
343
9.
Rename the new layer
actions
and add the following ActionScript to Frame 1 of the movie
clip’s timeline:
stop();
10.
Select Frame 10, all three layers, and select Insert > Timeline > Keyframe.
11.
Add a
stop()
action on Frame 10 of the actions layer, and add a frame label of
_over
in
frame 10 of the labels layer.
12.
Select the rectangle on Frame 10 and use the Property inspector to select a different
fill color.
13.
Create new keyframes on frame 20 of each of the three layers, and add a frame label of
_down
in the Property inspector.
14.
Modify the color of the rectangle in Frame 20 so each of the three button states have a
different color.
15.
Return to the main timeline.
16.
To make the movie clip respond to mouse events, do one of the following:
■
Attach an
on()
event handler to the movie clip instance, as discussed in
“Using button
and movie clip event handlers” on page 337
).
■
Assign a function to one of the movie clip object’s mouse event handlers (
onPress
,
onRelease
, and so forth), as discussed in
“Using event handler methods”
on page 330
.
17.
Select Control > Test Movie to test the Flash document.
Move your mouse pointer over the movie clip instance on the Stage and the movie clip
automatically goes to the movie clip’s _over state. Click the movie clip instance and the
playhead automatically goes to the movie clip’s _down state.
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 use: event handlers or event listeners,
or
on()
and
onClipEvent()
handlers. If you’re defining an event handler in a new
ActionScript class, the scope also depends on how you define the event handler. This section
contains both ActionScript 1.0 and ActionScript 2.0 examples.
ActionScript 1.0 examples
Functions assigned to event handler methods and event
listeners (as with all ActionScript functions that you write) define a local variable scope, but
on()
and
onClipEvent()
handlers do not.
Summary of Contents for FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Page 1: ...Learning ActionScript 2 0 in Flash...
Page 8: ...8 Contents...
Page 18: ...18 Introduction...
Page 30: ...30 What s New in Flash 8 ActionScript...
Page 66: ...66 Writing and Editing ActionScript 2 0...
Page 328: ...328 Interfaces...
Page 350: ...350 Handling Events...
Page 590: ...590 Creating Interaction with ActionScript...
Page 710: ...710 Understanding Security...
Page 730: ...730 Debugging Applications...
Page 780: ...780 Deprecated Flash 4 operators...
Page 830: ...830 Index...