Section 9.1. How ActionScript Works


9.1. How ActionScript Works

ActionScript 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:

When someone presses (that is, clicks) this button, let him drag the contents of the frame around in Flash Player .

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:

  • By typing (or pointing and clicking) ActionScript code directly into the Actions panel (Window Actions) . You can type ActionScript code from scratch right in the Actions panel. Or, if youre familiar with ActionScript but want to avoid typing, you can build your actions by choosing functions, statements, properties, and so on from the Action panel's drop-down menu (Figure 9-2).

    Figure 9-2. Clicking the Add button (the + sign) lets you choose from a list of functions, statements, operators, events, and more. When you choose an item from the list, Flash types it into the script pane for you. If you know ActionScript, using this list saves you typing time and searching time. But if you don't know ActionScript, this list isn't much help.
  • By using behavior wizards . The Flash design team came up with a brilliant idea: Build wizards to make it easy for folks to create common actionsfor example, ActionScript that makes a movie clip start playing when you click a button. Flash calls these common actions behaviors , and you can see them (and access the wizards that help you create them) by displaying the Behaviors panel (Window Behaviors), as shown in Figure 9-3.

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.
Bottom: Clicking the Add Behavior icon displays all the different behaviors you can add. The behaviors you see here depend on which object you selected on the Stage just before you displayed the Behaviors panel.




Flash 8
Flash Fox and Bono Bear (Chimps) (Chimps Series)
ISBN: 1901737438
EAN: 2147483647
Year: 2006
Pages: 126
Authors: Tessa Moore

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net