Your First ActionScripts
In This Chapter
- Using the Actions Panels
- Moving from Scene to Scene
- Messing with Movie Clips
- Changing Movie Clip Properties
- Another Property-Changing Example
- Text Fields, Arrays, and Loops
- What You've Learned
In this chapter, we'll go all the way from your first look at
Using the Actions Panels
The Actions panels are one kind of panel, much like the other panels in Flash, such as Properties, Color Mixer, or Info. You open and close Actions panels like you open and close any other panel in Flash. Any code you place in an Actions panel becomes immediately activeyou don't have to save the file to test it. The Actions panel toggles between Frame Actions (Actions that only occur within the timeline), Movie Clip Actions (Actions attached to movie clips), and Button Actions (Actions buttons). Button and Movie Clip Actions are pretty much the same thing: actions attached to things on the stage, as opposed to a frame in the timeline.
The Panels
Let's open one of the Actions panels up.
Open a new Flash file with File New.
Window Actions.
Now click on Frame 1 on the timeline. The panel's title changes to "Actions - Frame," as shown in Figure 31.
Figure 31 The Frame Actions panel
Open the Common Libraries that came with Flash MX by choosing Window Common Libraries Button. Drag any of the buttons to the stage.
Now choose Window Common Libraries Learning Interactions, and drag one of the movie clips to the stage.
Click on the button on the Stage. The panel's title changes to "Actions - Button."
Click on the movie clip on the Stage. The panel's title changes to "Actions - Movie Clip."
As you can see, the same panel serves for frame actions, button actions and movie clip actions. It's easy to make a mistake and enter your actions in the wrong panel, so make sure you check every time before you start entering code.
NOTE
If some of your actions suddenly disappear, check your frame and movie clips and buttons. You may have entered your actions in the wrong panel. It happens to the best of us. Frequently.
Let's look at all of the parts of an Actions panel. To see everything, let's look at an Actions panel that has something interesting in it.
Open the file chapter3/drag_jake2.fla.
Click on the small fish (the one without all the teeth).
Open the Actions panel.
The panel should resemble Figure 32.
Figure 32 The parts of an Actions panel
Normal Mode Versus Expert Mode
Actions panels open up automatically in Normal Mode, unless you've changed your preferences. Normal Mode is Flash-assisted scriptingyou drag commands from the Toolbox list to the Action list, and Flash prompts you for what parameters you should fill in. You aren't allowed to type commands directly into the scripting window while in Normal Mode.
Normal Mode can be helpful, since your actions are likely to be free of syntax errors. However, Normal Mode can act as something of a crutch, because you don't have to remember all the parts of a commandFlash always tells youso I strongly recommend that while you're learning ActionScript, you always switch to Expert Mode. Expert Mode allows you to type in everything: commands, parameters, and so on. You'll make more mistakes at first, but you'll learn ActionScript better, and that's our goal. So let's change our panel to Expert Mode.
Open the View Options menu in the Actions panel, as in Figure 33.
Figure 33 Switching to Expert Mode
Choose "Expert Mode."
I also recommend choosing "View Line Numbers." It will help later when we're troubleshooting our code.