Printer Friendly Version

BellaOnline's Flash and Animation Editor

Mapping ActionScript to Flash Movie with Linkage

For the last few tutorials, we have discussed ways to add ActionScript to a Flash project. Our goal is to keep the ActionScript as modular as possible and run the code from an external file. So far, we have discussed three ways to associate ActionScript with our Flash movie. Each method has it pros and cons.

In the first method, we added the ActionScript code directly to the Timeline. With the second method, we moved the ActionScript code to an external file but still needed to place code on the Timeline that would use an include statement to tell Flash to get the external code. In the third method, we managed to keep our ActionScript in the external file and did not need to put any code on the Timeline. Instead, we used the Document Class to run the external code. However, with this method, we are forced to run the code when the Flash movie starts.

This fourth method is much like the Document Class method but gives us the freedom to run the code at any time throughout the movie. We will be using the Linkage Export for ActionScript feature to associate our external code with a symbol stored in the Library. Because the symbol is stored in the Library, the code in the external file does not run when the Flash movie starts. In order to run the external code, you need to place an instance of the symbol on the stage. You may do this from within the Flash workspace by dragging an instance from the Library or you may add an instance via ActionScript.

For our example, we can use the same external ActionScript file that we used for the Document Class method (named DrawCircle.as).

  1. Start a new Flash project. Name it RedCircle2.fla.

  2. To create a new symbol, click Insert New Symbol. In the Create New Symbol dialog box, name our new symbol "DrawCircle" which is the same name that we have given to our external ActionScript file. Set the Type to Movie Clip.

  3. Click on the Advanced button to extend the dialog box. In the Linkage section, place a checkmark in the box next to Export for ActionScript. Notice that Flash automatically names our new class "DrawCircle". Click on the OK button to close the dialog box.

    You will automatically be place in edit mode for the new symbol. But, we want to keep the symbol in the Library for now.

  4. Click on Scene 1 to go back to the main Timeline.

At this point, we do not have an instance of our DrawCircle movie clip on the stage. So, if we test our movie, we should not get a red circle. Let's give it a try. Click Control Text Movie. You should see a blank screen. Close the window and go back to the Flash workspace.

Now, let's drag an instance of our DrawCircle movie clip from the Library onto the stage. Click Control Text Movie again and you will see our red circle drawn on the stage. The beauty of this method is that we can add the symbol to the stage on any frame of the Timeline and as many times as needed. Also, did you notice that we used the same external ActionScript file (named DrawCircle.as) for two movies (RedCircle.fla and RedCircle2.fla).

Flash and Animation Site @ BellaOnline
View This Article in Regular Layout

Content copyright © 2013 by Diane Cipollo. All rights reserved.
This content was written by Diane Cipollo. If you wish to use this content in any manner, you need written permission. Contact Diane Cipollo for details.

| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2016 Minerva WebWorks LLC. All rights reserved.

BellaOnline Editor