Adding Interactivity with ActionScript

     

ActionScript is a programming language, a way of sending both commands and questions to the Flash Player about timelines , movie clips, and objects such as buttons .

graphics/new_icon.jpg

Flash MX 2004 introduces a new version of ActionScript, ActionScript 2 (AS2), which enhances productivity and supports better coding practices. To take advantage of AS2 features, you must publish for Flash Player 7 (FP7).


For a summary of key new features in AS2, see "A New Version of ActionScript," page 330 , in Chapter 14, " What's New in Flash MX 2004?"


Existing AS1 scripts may have problems when published for FP7. It should be safe, however, to publish existing scripts for Flash Player version 6 (FP6) and play them in FP7.

What kinds of problems? For instance, there are some new objects and procedures whose names are now "reserved" by the ActionScript compiler: In movies published for FP6, they cause no problems. In movies published for FP7, you use them at your peril. Examples include ContextMenu , Error , and PrintJob .

In addition, AS1 seldom cared about capitalization. AS2, in contrast, is case sensitive. So, for instance, myTxt and MyTxt were considered the same variable in AS1, but not in AS2.

There are several other ways in which FP7 is stricter or more "correct" than FP6. ActionScript that depended on FP6's laxness may "break" in FP7.

The CD accompanying this book has a table of some key new ActionScript requirements for FP7: ASPlayerDifferences.htm .


graphics/troubleshooting_icon.jpg

Having problems converting an old Flash file to use AS2? See the "Troubleshooting" section later in this chapter, page 458 .


Often, you can accomplish tasks easily with ActionScript that would be difficult or impossible without it. Without ActionScript, you can access only a small portion of Flash's capabilities. For example, you need some ActionScript to get any kind of interactivity, such as responding when the user clicks on a button or presses a key on the keyboard. ActionScript is also the only way to get Flash to go to a particular frame of a timeline and either start or stop playing.

Flash's visual (non-scripting) tools enable you to create animations. ActionScript adds interactivity and enables you to animate with more control, often while consuming fewer processor cycles. With ActionScript, you can create navigation systems, listen for and gather user input, collect data, make calculations, examine the computer environment, and transform graphics, sound, and video.

graphics/new_icon.jpg

Behaviors, new in Flash MX 2004, make it easy to put simple interactivity in your movie without actually having to type one line of ActionScript code. But all behaviors do is automatically apply ActionScript.


NOTE

Do not confuse behaviors with components. A component is a ready-made object such as a button, check box or drop-down menu (combo box). Components can (and usually do) have both ways of behaving (implemented in ActionScript) and a visual appearance (implemented in movieclips). A behavior is basically just a snippet of ActionScript that you can apply to appropriate objects with a couple of mouse clicks. A behavior in itself doesn't have any visual appearance.


Useful as they are, behaviors don't begin to illustrate the richness, flexibility, and endless possibilities that ActionScript opens up to the Flash developer. ActionScript is Flash's native language; behaviors are like a phrase book ”extremely useful, but still limited. The phrase book may not have exactly what you want to say, and it limits itself to quite simple "ideas."

There are other advantages to ActionScript. For instance, when used for animation, ActionScript usually gives you smaller SWF files and better performance than tweening. Another advantage is that you can perform tasks with more precision, such as moving a movie clip to a precise position on the Stage.

NOTE

ActionScript is based on the ECMA-262 standard, which JavaScript also implements. ActionScript and JavaScript are siblings, one of which chose a life in Flash, the other in the browser. Naturally, each is optimized for its environment, but they still bear a close family resemblance. AS2 is based on ECMA-262 version 4.


ActionScript offers endless possibilities, and you can easily get started using it. The place to start is the Actions panel.

Accessing the Actions Panel

To display or maximize the Actions panel, do one of the following:

  • From the Window menu, choose Actions.

  • Press F9.

The Actions panel maximizes or becomes visible. Or, if it was behind another window, it comes to the front. In the default layout, the Actions panel is docked with the Property inspector, as shown in Figure 19.1. (If you want to restore the default layout, choose Window, Panel Sets, Default Layout.)

Figure 19.1. The Actions panel is Flash's built-in ActionScript editor.
graphics/19fig01.jpg

The Actions panel is Flash's built-in ActionScript editor. It displays menu-style code hints if you use appropriate suffixes for object instances, such as _mc for movie clips. You can "pin" the current script (keep it in the Actions panel) by using the Pin Active Script button.



Using Macromedia Studio MX 2004
Special Edition Using Macromedia Studio MX 2004
ISBN: 0789730421
EAN: 2147483647
Year: N/A
Pages: 339

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