Hands-On: Flash MX 2004 ActionScripting
Exercise 34: Place Actions on a Movie Clip Instance
You've just placed Actions in key frames; now let's see how they work with Movie
Clips.
Actions on Movie Clips are powerful, you'll have to fully study this feature
to really learn it, but you can get a taste of it in a practice session on this
page.
There are books written only for ActionScripts, so you can expect
to spend some time learning how to use them in the future.
- Use the file: MX2004_ActionScripting-Loops.fla to put ActionScripts on
a Movie Clip.
- Choose Window > Scene or [Shift] + [F2], and then
click the Plus Mark + to add a new scene.
- Create a Movie Clip inside the Scene 2 that contains several
frames with some kind of animation inside the clip (so we can see whether
it's playing or not). The simple animation could be a filled circle that
you animate as a bouncing ball. To make this Movie Clip begin by choosing Insert > New
Symbol or pressing [Control] + [F8]. Name the symbol myAnimation.
- Don’t forget, when you build your animation, select the circle, press
[F8] and turn it into a graphic, I called mine ball. You won’t
be able to animate your ball without doing this.
- Click on Scene 2, there should only be one keyframe in this
scene. Open the Library to find the myAnimation Movie Clip.
- Drag this Movie Clip onstage and test the scene, not the movie (to
verify it is animating). Remember your main timeline should have only one frame.
- Back on the Flash MX 2004 main stage, select the instance of the
Movie Clip myAnimation onstage and open the Actions panel [F9].
Notice that all the Global Functions from Timeline Control and Movie Clip Control
are available (that is, they're not grayed out).
- From the plus button select Actions > Global Functions > Movie
Clip Control > onClipEvent. Type load inside of the parentheses(load).
- This time select Actions > Global Functions > Timeline Control > Stop
So at this time your code looks like this:
onClipEvent (load) {
stop ();
}
- Repeat step 8 and type mouseUp inside of the parentheses (mouseUp) and
then repeat step9 again. So at this time your code now looks like
this:
onClipEvent (load) {
stop ();
}
onClipEvent
(mouseUp) {
stop
();
}
- Repeat step 8 and type mouseUp inside of the parentheses (mouseUp) and
then repeat step9 again but choose Play instead of Stop.
So at this time your code now looks like this:
onClipEvent (load) {
stop ();
}
onClipEvent
(mouseUp) {
stop
();
}
onClipEvent
(mouseDown) {
play
();
}

- Test Scene 2 now and, when the Movie Clip loads, it stops.
Click the mouse anywhere and it starts playing let go of the mouse and it stops
again.
Another way to create the same effect is to put a stop Action on
the first keyframe inside the master Movie Clip.
There is nothing really wrong with the above technique, but a stop
inside the master Movie Clip means every instance will exhibit this behavior.
Placing the Action on one instance affects just that one instance.
TIP : If the line currently selected in your script is within
the curly braces, you won't be adding another clip event, because you can't put
an event inside an event. Remember: Every time you add an Action, Flash will
try to put the Action right below the line currently selected in your script.
- Save your file for additional exercises.
There are a few important things to note about this session.
- First, the clip events mouse down and mouse uprespond toany
mouse click—not just clicks on the clip itself. If you want something
that responds to clicks right on a graphic, using a regular button is easiest.
- The basic things to remember are that just like buttons, Actions on clip
instances are wrapped inside events.
- Buttons respond to the on event while Movie Clips respond
to the onClipEvent.
- Finally, Actions attached to clip instances affect only the
particular instance to which they're attached.
|