Hands-On: Flash MX 2004 ActionScripting
Exercise 32.1: Actions That Loop Parts Of Your Movie Clip
- In a new file, use the Text tool to create a text block at 28pts
tall containing the words SomaliaExtraordinaire. Save this
file as: MX2004_ActionScripting-Loops.fla
- Select the Text block and convert to a Movie Clipsymbol [Ctrl]
+ [F8]. Name it "wine_expert".
Position
the clip instance in the center of the screen, select Windows > Design
Panels > Align, (or [Control] + [K]) and then click
the To stage: icon. Then Click both of the middle icons in the Distribute: row.
- Insert keyframes [F6] at frame20 and frame 30.
- Move the red current frame marker to frame 1 and move SomaliaExtraordinaire text
all the way off the stage to the left. Try holding the [Shift] key down
while pressing the Left Arrow key, it will move quite quickly.
- In the Properties Inspector panel set Motion Tweening for both frame
1 and frame 20.
- Place the red current frame marker in frame 20, and then use the
Properties panel to make the tween rotate one time clockwise (CW)
on it way from frame 20 to frame 30.
- Test the movie. Notice that the whole movie loops over and over. Instead
we're going to make the rotation part (from frame 20 to frame 30) loop forever.
In
the Timeline rename the first layer "animation" and then choose Insert > Layer and
name the new one "actions."
- Make sure the current layer is actions (you'll see a pencil in the
layer).
- Select frame 30 in your Actions layer, insert a keyframe [F6],
and then access the Actions panel (either by selecting Window >Development
Panels >Actions or press [F9].
- Make sure frame 30 remains selected when you edit the Actions panel.
We're going to set an Action to execute when the playback head reaches frame
30.
- Click the plus button and then Global Functions > Timeline Control > gotoAndPlay and
then type 20 in between the parentheses (20).
- Notice that in the Timeline, a small “a” appears in the
keyframe where you added the Action.

- Test the movie (don't just play in the authoring environment). It
plays once, and then every time it gets to frame 30 it goes back to frame 20
and plays again.
There is a better way to accomplish the above so that if you change the
frames for better timing, you don't mess up your animation.
Instead of making the destination of your gotoAndPlay an explicit
frame number, you can change the parameters to make the destination a named frame
label, which will be the same for the frame no matter where it is located
in the Timeline.
|