|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).
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).