This tutorial shows you how to capture the animation properties of an object as ActionScript code, and then apply the ActionScript to another object on the Stage.

Requirements

To follow along with this article, you will need the following software and files:

Copying and pasting ActionScript from an animation

1.In Flash, choose File > Open and open the copy_actionscript.fla file. The timeline includes a layer named Ball, which has been animated to bounce up and down (see Figure 1).

2.Move the playhead back and forth to preview the animation.


Figure 1: Move the playhead in the timeline to watch the ball in the Ball layer bounce up and down.

You'll copy and paste this animation to apply it to a completely different object.

3.Click the Insert Layer button below the Timeline to insert a new layer.

4.Double-click the layer name and type Dog.

5.Select the first frame of the Dog layer. Choose the Library panel. Drag the prepared movie clip, mudbubble_dog, to the Stage.

Now you need to give the movie clip an instance name. Instance names are required for applying ActionScript animations.

6.Make sure the Property Inspector is open. If not, choose Window > Properties > Properties. Then choose the Property inspector and type Dog for the Instance Name.

7.Move the playhead to the beginning of the timeline. Select the first frame of the Ball layer, hold down the Shift key, and select the last frame to select all the frames in between.

8.Choose Edit > Timeline > Copy Motion As ActionScript 3.0. This copies the animation to the clipboard, and displays a dialog box prompting you to enter an instance name for the object you will apply this animation to.

9.Type Dog and click OK.

You won't copy the animation directly to the Dog layer. Because the ActionScript refers to the Dog instance name, you can paste the animation into a separate layer, and the animation will still work.

10.Click the Insert Layer Layer button below the Timeline.

11.Select the new layer, and choose Window > Actions to open the Actions panel. You'll paste the ActionScript on the clipboard right into this window.

12.Insert your pointer in the first line, right-click (Windows) or Control-click (Mac OS) to display the context menu, and choose Paste (see Figure 2).

Figure 2: Paste the ActionScript into the Actions panel.

13.Once the code is pasted, close the Actions panel. Now it's time to test your movie.

14.Choose Control > Test Movie to export the test SWF file. The ball and the dog should bounce together (see Figure 3).

Figure 3: The completed movie shows the dog and ball bouncing together.