Previous Page
Next Page

The Basic Context for Programming in Flash

With the enhanced Actions panel (also known as the ActionScript editor) in Flash 8, you can program interactivity by writing interactive commands directly into the Script pane of the Actions panel.

New Feature 

Flash 8's Actions panel can now show you hidden characters, such as character spaces and line breaks, in your code. Choose Hidden Characters from the options menu of the Actions panel to see these characters. Due to the reactions of many Flash designers and beginner developers, the Actions panel also has a new Script Assist feature, which replaces the sorely missed "Normal mode" of Flash MX. For more information on Script Assist, see Chapter 18.

In the Actions panel, you can type your code from scratch, as well as insert your code with the help of Action booklets or the new Script Assist feature. Syntactically, ActionScript looks and feels very much like JavaScript. Macromedia has gone to great lengths to make ActionScript compatible with ECMAScript 4 (the standard programming guidelines derived from JavaScript). And like other object-oriented languages, ActionScript is composed of many familiar building blocks: variables, operators, conditionals, loops, expressions, built-in properties, subroutines, and native functions.

Accessing ActionScript Commands

All of the ActionScript commands are found in the Flash interface in the Action booklets or plus (+) button menu of the Actions panel. However, assembling actions with one another is not something Flash 8 automatically performs unless you use the Behaviors panel to add interactive functionality to your movie elements. Although it is beyond the scope of this chapter to fully explain fundamental programming principles, we can give you a sense of the whole of ActionScript by providing an organized reference to each of its parts.

Actions List Organization in the Actions Panel

In the Actions panel, you can cut, copy, and paste code within the Script pane from one area of your movie to another using Ctrl+X (z+X), Ctrl+C (z+C), and Ctrl+V (z+V), respectively. You are free to select partial or entire lines of code, and modify the code in any way you want. With Flash 8, you can even edit your code in your preferred text editor! If you want to create your own programming macros in other programming applications, you can write your scripts outside of the Flash authoring environment and copy the final code into the Actions panel when you're done.

Tip 

To make sure that you don't have any syntax errors after reorganizing code, click the Check Syntax button in the Actions panel toolbar. Flash alerts you if there are scripting errors by placing messages in the Output panel.

Also, use the new Script Navigator in the lower-left corner of the Actions panel to quickly switch back and forth between keyframe or object code. For example, you can choose one frame in the Script Navigator, copy its code, and then switch to another frame to paste the code.

If you decide to write ActionScript with another editor, you can use the #include directive to load the contents of the external code file (.as) into the Flash movie at publish or export time. For more information on the #include directive, read Chapter 32, "Managing and Troubleshooting Flash Movies".

The Help Panel

Don't know what the methods of the Sound object are? Need to see if the getVersion() function will work in a Flash Player 4-compatible movie? Flash 8 has conveniently nested everything related to help documentation in the Help panel. Among other items, the new Help panel contains all the syntax of the ActionScript language. You can access the Help panel in a few ways:

  • Choose Help ð Flash Help, or press F1.

  • Click the Reference icon in the Actions panel.

  • Right-click (or Control+click on Mac) an action in the left-hand Script pane of the Actions panel and choose View Help in the contextual menu.

We'll quickly show you how to use the new Help panel in an actual Flash document:

  1. Open a new document (File ð New).

  2. Select frame 1 of Layer 1, and open the Actions panel by pressing F9.

  3. Open the Global Functions booklet and click the Browser/Network booklet. Double-click the loadMovie action. The action will appear in the Script pane, as shown in Figure 24-1.

  4. Select the text loadMovie in the Script pane, making sure not to select the (); portion of the action. Click the Help icon (that is, the circle with the question mark) at the top right of the Actions panel. The Help panel will open, displaying the definition for the loadMovie() action, as shown in Figure 24-2.

Image from book
Figure 24-1: The Actions panel with a loadMovie() action in the Script pane
Image from book
Figure 24-2: The Help panel with the definition for loadMovie

You can select other actions from the left pane of the Help panel and view their descriptions.

Tip 

You can also print descriptions from the Help panel by choosing Print from the options menu at the top-right corner of the panel, or clicking the Printer icon in the Help panel toolbar.

ActionScript 1.0 and 2.0

So why all the fuss about ActionScript now? Let's make one thing clear right away: For most Flash designers and developers, or rather for most of the work that's done in Flash, the graduation of ActionScript 1.0 to 2.0 may mean next to nothing at all. This isn't to say that ActionScript 2.0 should be ignored or is not a monumental leap forward for Flash programming — we simply want to calm or allay any fears you might have after reading about ActionScript 2.0 from other sources. If you've used ActionScript in Flash versions prior to MX 2004, then ActionScript 1.0 refers to the coding styles that those versions of the application used.

ActionScript 2.0 introduces a couple of major structural changes to the way in which you can code Flash ActionScript. To begin with, it uses strong data typing. You'll learn more about data typing in Chapter 26, "Using Functions and Arrays," but for now, know that ActionScript 2.0 imposes some rules on how you can assign values to variables, functions, and other objects in your code. Unless you're creating code that uses custom classes and object-oriented programming concepts such as inheritance and prototypes, you won't really need to worry about whether your code will work as ActionScript 2.0 code. Another big change with ActionScript 2.0 is case-sensitivity. Prior to Flash Player 7, most ActionScript terms were case-insensitive, meaning you could refer to object references or variables with varying cases, such as:

var firstName = "Robert";
var lastName = "Reinhardt";
var fullName = firstName + " "+ lastName;

In ActionScript 1.0, you could have used the following code as the last line, without receiving an error:

var fullName = firstname + " "+ lastname;

However, in ActionScript 2.0, that same line of code would be incorrect because firstname and lastname are not using the same case as the original variables.

Why should the distinction between ActionScript 1.0 and 2.0 even be an issue? For starters, when you publish a Flash movie for Flash Player 6, 7, or 8, you need to decide how Flash 8 will compile the ActionScript code in your document. In the Publish Settings dialog box, you can choose which ActionScript version to publish in the Flash tab. Unless directed otherwise, you'll publish most of the Flash movies for Part VII of this book as ActionScript 2.0, even though it pretty much looks and feels like ActionScript 1.0.


Previous Page
Next Page