9.1. How ActionScript WorksActionScript is Flash's own scripting language, similar (but not identical) to JavaScript, the scripting language that's supported in Internet Explorer, Netscape Navigator, and most other Web browsers. Where JavaScript lets you script (act on) all the different parts of a Web page, ActionScript lets you script (act on) all the different parts of your Flash animation. Flash calls individual snippets of ActionScript code actions . Here's an example of an action: on (press) { startDrag(this); } As you can see, an action is composed of English words (well, pidgin English, perhaps). Attaching this chunk of code to an object in your animationa button, saytells Flash:
You create and edit scripts in the Actions panel. Figure 9-1 shows what the complete script might look like. Figure 9-1. Flash attaches a script to an object you select on the Stage just before you display the Actions panel. Here, Flash is attaching this script to a button named rightEyeInstance. Buttons, in fact, are one of the most popular ways to bring interactivity into Flash animations, and you can see how to empower them with actions in Chapter 11.The above action is simple and straightforward, but you can create custom actions that do pretty much anything you likewithin the constraints of the ActionScript language, the Flash scripting and security models, and your own programming expertise, that is. (See the box on Section 9.2.) Flash gives you the following two ways to create actions:
The following sections show you how to create actions using the Actions panel and behaviors, respectively. Tip: Whenever you're considering adding an action to your animation, always check the Behaviors panel first to see whether there's a behavior that fits your bill. If there is, you've just saved yourself time. If not no harm done. Figure 9-3. Top: Flash attaches the behaviors listed in the Behaviors panel to the object shown at the top of the panel. Here, Flash is attaching a single behavior (a scrap of ActionScript code that loads a movie clip symbol when someone presses and then releases a button) to an instance of the oval blue button symbol called myButtonInstance. |