|In this tutorial, we will begin to explore the many ways to use ActionScript in your FlashR project. I'm not talking about the many things that you can make happen with ActionScript. I'm talking about how you can add ActionScript code to your Flash movie. |
In the beginning there was Flash. When you created a Flash project, you created an fla file. Then, when you were ready to publish your Flash to the web, you compiled your fla file into an swf file. However, after a few years people began to use ActionScript to enhance their Flash movies. At this point, the question was where to put the ActionScript. At first, programmers added their code inside the fla file. Now that Flash and ActionScript have grown up a little, most programmers find that it is more efficient to keep the ActionScript separate from, but part of, the Flash movie.
Add Code to the Timeline
The most basic method, and the method used most often in the past, was to combine ActionScript as an internal part of the Flash fla file. When writing ActionScript within the Flash movie, you can place the ActionScript on any frame of the timeline. Although there is no established rule about which frame to use, most programmers find it helpful to place their ActionScript code in the first frame on the timeline. To make things even easier, programmers usually create a special layer for their ActionScript, sometimes called the "Actions" layer.
This is the method that I use for most of my beginner's tutorials because it is less complicated than the other methods. For example, in a previous tutorial, we learned how to write ActionScript code that would draw a circle onto the stage.
Let's add this code to a new Flash movie. Start a new Flash project and name it RedCircle.fla.
Using an Include Statement
This second method of associating ActionScript with your Flash project is not much different from the method that we just discussed. Basically, we will move the ActionScript from the fla file to a separate file and add an include statement to our Flash movie which will tell Flash to read the ActionScript from that external file.