
Page 1 of 3 Beginners to Flash programming often find themselves asking a fundamental question: "Dude, where do I put my code?" A quick sweep of the 100s of Community MX Flash tutorials, as well as other code repositories on the Web, reveals quite a few choices. You can put ActionScript into keyframes; attach it directly to objects, such as buttons; put it into external text files; and even write a special kind of external file called a class. So, which approach is best? Are some better than others?
To arrive at an answer, let's take a stroll among the various techniques mentioned. This is not an article on ActionScript syntax or how to program. If you were an aspiring chef, this might be a tour of various kitchen facilities, to give you a feel for what's available at each venue. After a brief look at the options, you may just find that the best approach is simply the one that makes you the most comfortable, even on a project-by-project basis. We'll start with timeline code, here in Part 1, then address the other procedures in subsequent articles.
Why start with the timeline? Well, when you fire up Flash and create a new document, the timeline is among the first things you see. Right off the bat, you get a neat, seemingly endless "Layer 1," quietly awaiting your creativity.

Figure 1 The main timeline of a new Flash document
The timeline is more than just a widget in the Flash interface; it's a metaphor that defines the arrangement of all the audio/visual equipment you bring to it. In much the same way symbols, graphics, and text can be manipulated in keyframes, ActionScript can be attached to any frame of any timeline, including the nested timelines of movie clip symbols. Just insert a keyframe where you see fit (Insert > Timeline > Keyframe), and that keyframe becomes available for ActionScript code.
How do you supply that code? Open the Actions panel (Window > Actions) and use the mouse to select a keyframe. Whatever you type into the script pane (the right side of the Actions panel) ends up attached to, or "in" the selected frame.

Figure 2 The Actions panel is your " portal"
to the selected keyframe's code
Keyframes that have ActionScript in them are indicated by a lowercase "a," visible from the timeline. This makes it easy to spot scripted versus non-scripted frames.

Figure 3 A small "a" indicates that a frame contains ActionScript
To edit existing code, either select the applicable keyframe, which updates the Actions panel to show what's inside, or use the lower left corner of the Actions panel to find frames that have code attached.

Figure 4 The Actions panel helps you locate code
Keywords
ActionScript, code, timeline, keyframe, event handling