You can use ActionScript to add animation to a document, either by referencing an existing motion tween or by copying the animation from a tween span to ActionScript 3 code. The following sections show you how easy it is to do this, and sample files show you how far you can take these techniques. You can use the Copy Motion as ActionScript 3 option to translate an animation to ActionScript 3 code, which you can then assign to an instance by modifying a single line of code.
Flash CS4 introduces a new feature, thanks to object-based animation, where you can give a tween span an instance name to which you can then attach other instances. These instances will all animate the same way as the tween with the instance name.
You can also use code to script all of your animation from scratch, completely avoiding motion tweens, but this goes beyond the scope of this learning guide. To learn more about scripted animation, read Creating animation in ActionScript 3.
To make this most of this learning guide, you need to install the following software and files:
A basic knowledge of the Flash workspace.
If you have a tween span, you can copy all of the animation from that tween span and convert it to ActionScript 3 button using a menu option. The information from that tween is copied to the clipboard as code, which you can then paste as ActionScript in an AS file, another FLA file, and so on. This can help designers and developers work together, in that developers can easily remove tween spans from a document and fill it with code instead. The developer doesn't need to worry about making the animation look exactly the same; the hard work is done for him or her by Flash.
The following example shows you how (this is slightly different from Flash CS3):
Select the frame that contains your code. Return to the Actions panel and uncomment the following line of code. This means you remove the two forward slashes at the beginning of the line so it looks like the following:
__animFactory_Symbol1_2.addTarget(<instance name goes here>, 0);
<instance name goes here> to myClip.Copying motion as ActionScript works almost the same was as in Flash CS3, but if you are familiar using the feature you might notice a couple differences:
As you saw in the previous exercise, you need to uncomment the final line of code that you paste and enter the instance name yourself.
You can use a tween instance to apply a motion tween to other instances in an FLA file. You give a tween an instance name, much like you can give movie clips instance names so you can refer to them in your code. Giving a tween an instance name means you can assign the tween to other movie clips, and they take all the properties of that tween and animate the same way. Using this technique means creating certain forms of animation is much more efficient—both for your workflow, and in the FLA file.
In the sample files you can find the file simple-tween-instance.fla. One of the instances in the FLA file is a motion tween, which you will give an instance name and apply to the static movie clip in the file:

Figure 61. Give a tween an instance name.
There is a second instance in this file, which is a static (non-tweened) movie clip that has the instance name staticMonkey. Let's apply the tween to this instance:
theTween.addTarget(staticMonkey);
This code applies the tween from the first monkey to the second one and both animate.
This is only the most basic example of what you can do with tween instances. For example, you might want to wrap some ActionScript around that line to apply it to numerous instances that you pull from the Library. An example of this can be found in the source files for this learning guide, called snow-tween-instance-3speeds.fla, and a description of how that file works can be found both in the FLA file's commented code and in Jen's blog.
Tween instances are useful when designers and developers need to work together on a project. Here's an example of how you can use a tween instance in this kind of workflow: A designer creates a transition for a menu item that triggers an event or animation when the menu is selected, and a developer needs to make this menu interactive. The developer would take the prototype the designer created, move the tween offstage (or hide the layer and make it not export), and give the tween an instance name. Then the developer adds the menu object and invokes the event when users click the menu item.
As always, be sure to read other sections of the Animation Learning Guide for Flash.
Jen deHaan was raised by wolves in the deep woods of the Canadian north. Later in life, Jen worked with Flash as a deseloper, then wrote about Flash for five versions, and then worked on stuff that didn't include much Flash. She came to her senses in 2007 by rejoining the fabled Flash team at Adobe as a QE, focusing on the good stuff—Motion (on timelines). Jen enjoys long walks in the rain pondering how many times she can use the word Flash in a bio, and admits that after numerous years in California she is no longer addicted to Tim Horton's coffee.
John Mayhew is a hopeless software developer, and has been for a very long time, but he still loves it. John likes being able to launch an app, demo a feature, and show people exactly what he creates for a living. Along the way he has worked for several small companies and consulted for many years. Among the more notable companies John worked for are Micrografx (ABC FlowCharter and their Graphics Suite offering) and Macromedia (mobile authoring tools), which eventually led him to the Flash authoring team. He has focused for the last few years on creating a simple, yet more powerful animation system in the Flash authoring tool. Achieving both of those goals has proven to be quite a challenge. You can see if John and his colleagues achieved those lofty ambitions in Flash CS4 Professional.