The Actions Panel
The Actions panel is the Flash dialog box that lets you access all the actions that will control your Flash movie. Depending on your level of expertise, you can create, delete, and edit actions in two modes: Normal and Expert. If you're uncomfortable with the ActionScript rules of grammar, the Actions panel can automate some of the scripting process, such as punctuation, generating semicolons and curly braces automatically. The ActionScript panel can also give you real-time code hints as you script and anytime access to the ActionScript reference.
In Flash, the name of the Actions panel appears as either Actions-Frame, Actions-Button, or Actions-Movie Clip, depending on which element you have selected. In any case, the contents of the panel remain the same, so this book always refers to it as the Actions panel.
To open the Actions panel:
From the Windows menu, choose Actions (F9).
or
Click the right-facing triangle in the Actions bar.
The Actions panel expands, and the triangle points downward (Figure 3.6).
Figure 3.6 Click the arrow in the Actions bar to expand or collapse the Actions panel.
or
Alt-double-click (Win) or Option-double-click (Mac) an instance on the Stage or a keyframe in the Timeline.
The Actions panel appears so that you can attach actions to either the keyframe or the instance.
or
Right-click (Win) or Ctrl-Click (Mac) on a keyframe or an instance, and choose Actions in the context menu that appears.
The Actions panel appears so that you can attach actions to either the keyframe or the instance.
To undock the Actions panel:
Drag the Actions panel by the top-left corner marked by the bumpy area.
Your pointer will change (hand for Mac, arrows for Windows), indicating that you can undock the Actions panel (Figure 3.7).
Figure 3.7 The Actions panel can be undocked from the Property inspector (Windows only).
To redock the Actions panel:
Grab the Actions panel by the bumpy area in the left corner, and drag it over the different panels on your desktop.
Those areas highlight with a bold outline.
Drop the Actions panel.
The Actions panel docks with the highlighted panels (Figure 3.8). In Mac OS X, the Actions panel cannot dock with the Property Inspector or the Timeline
Figure 3.8 You can dock the Actions panel in many places; choose one that suits your own work environment. The Actions panel can be above the Property inspector (top left; the default), above the Timeline (bottom left), to the left or right of the Timeline (right), or among the other panels (bottom).
TIP
You can disable docking of all your panels by choosing Edit > Preferences and choosing Disable Panel Docking in the General tab of the Preferences dialog box. (This option is available only on Windows.)
Normal mode
The Normal mode of the Actions panel features several sections and multiple ways to enter ActionScript statements (Figure 3.9). The Actions toolbox on the left side displays all the available commands, organized in logical categories. At the bottom, an index lists all the ActionScript commands in alphabetical order. You choose actions from this categorized list. A brief description of the selected action appears in the top-right section of the Actions panel, and below it, the Parameters pane lets you enter different parameters for that selected action. In the bottom-right section, your completed script appears in the Script pane. At the top of the Actions panel, you can use the pull-down menu to navigate to different scripts within your Flash movie.
Figure 3.9 The Actions panel in Normal mode.
Expert mode
The Expert mode of the Actions panel is for experienced ActionScript developers who don't need the structured scripting help provided in Normal mode. Expert mode allows you to enter scripts in the Script pane freely, as though you were typing in a text-editing application (Figure 3.10).
Table 3.1
Figure 3.10 The Actions panel in Expert mode.
Tips
Feel free to switch between Expert and Normal mode. Flash maintains any special formatting you may have used in Expert mode unless you change your script in Normal mode. Then Flash uses its Normal-mode formatting on your script.
Switching from Expert to Normal can be an easy way to check for errors. Flash won't allow you to switch from Expert to Normal unless your script is free of errors.
To choose Normal or Expert mode:
With the Actions panel open, click the Options button in the top-right corner.
The Options pop-up menu appears (Figure 3.11).
Figure 3.11 The Options menu in the Actions panel gives you the choice of Normal or Expert mode.
Choose Normal Mode (Cmd-Shift-N for Mac, Ctrl-Shift-N for Windows) or Expert Mode (Cmd-Shift-E for Mac, Ctrl-Shift-E for Windows).
or
Click the View Options button (above and to the right of the Script pane), and choose Normal Mode or Expert Mode from the menu (Figure 3.12).
Figure 3.12 Choose Normal Mode or Expert Mode from the View Options menu.
To add an action in Normal mode:
Select the instance or frame where you want to assign an action.
In the Actions toolbox, expand an action category by clicking it.
Double-click the desired action.
The action appears in the Script pane (Figure 3.13).
Figure 3.13 Add an action by choosing a statement from the Actions toolbox. Here, the action stop() has been added to the Script pane.
or
Select the instance or frame where you want to assign an action.
In the Actions toolbox, expand an action category by clicking it.
Select the action, and drag it into the Script pane (Figure 3.14).
Figure 3.14 Add an action by dragging the statement to the Script pane. The pointer changes temporarily to show you where you can drop the action.
The action appears in the Script pane.
or
Select the instance or frame where you want to assign an action.
Click the plus button above the Script pane, and choose the action from the pull-down menus (Figure 3.15).
Figure 3.15 Add an action by choosing it from the plus button's pull-down menus.
The action appears in the Script pane.
or
Select the instance or frame where you want to assign an action, put your pointer in the Script pane of the Actions panel, and press the Esc key.
Type the two-letter code corresponding to the action you want.
The action appears in the Script pane.
For a full list of shortcut-key commands for actions, see Appendix C, or choose View Esc Shortcut Keys from the Actions panel's Options menu (Figure 3.16) to display them in the Actions toolbox.
Figure 3.16 Choosing View Esc Shortcut Keys from the Options pull-down menu displays the shortcut keys for every action in the Actions toolbox.
TIP
While making your selection in the Actions toolbox, you can use the arrow keys, the Page Up and Page Down keys, or the Home and End keys to navigate through the list. Press Enter or the spacebar to open or close categories or to choose an action to put in the Script pane.
To edit actions in Normal mode:
Select the action, and use the up- and down-arrow buttons to rearrange it in the Script pane.
or
Select the action, and drag it to its new location (Figure 3.17).
Figure 3.17 Move the stopAllSounds () statement by using the arrow buttons (top) or by dragging it to a new location (bottom). A bold horizontal line shows you where the statement will be when you release the mouse button.
Select the action, and use the minus button to delete it from the Script pane.
or
Select the action, and press the Delete key.
Select an action in the Script pane, and use the empty text boxes, check-boxes, and pull-down menus of the Parameters pane to change the parameters for the selected action.
The Script pane shows the action with the parameters in place (Figure 3.18).
Figure 3.18 The Parameters pane lets you change the parameters of a selected action. The Go To action has two parameter text boxes, a pull-down menu, and radio buttons that affect the way it will work. Entering 10 in the Frame text box and selecting the Go to and Play button change the statement in the Script pane, making the playhead go to Frame 10 and begin playing.
Tips
You can still use familiar editing commands such as Copy, Cut, and Paste to create and rearrange ActionScripts. When you paste a copied script, however, the new script appears after the selection rather than replacing it, as a text-editing application would.
Use the Shift key to select multiple actions to copy or cut.
If you copy or delete one line of a larger code block, the entire code block will be copied or deleted.
on (release) { play(); }
If you select just the first line of this code block and press the Delete key, all three lines will be deleted, because the on (release) statement includes the curly braces that span all three lines.
To modify the Actions panel display:
Drag or double-click the vertical splitter bar, or click the arrow button that divides the Actions toolbox and Script pane, to collapse or expand an area (Figure 3.19).
Figure 3.19 Resizing the Actions panel by dragging (top) or clicking the vertical splitter bar. The Actions toolbox can be resized (middle) or completely collapsed (bottom).
In Normal mode, click the triangle in the top-right corner of the Actions panel to collapse or expand the action description (Figure 3.20).
Figure 3.20 The black triangle collapses or expands the description of the action.
Actions-panel options
The Actions panel provides many features that can help you write reliable code quickly and easily. Chapter 12 explains many of the debugging tools in detail.
If you're writing ActionScript in Expert mode or entering an expression in a parameters text box in Normal mode, you'll be able to use code hints, which appear as you type. Code hints recognize what kind of action you are typing and offer choices and prompts on how to complete it. Flash makes it easy to be an expert! In Expert mode, you can also customize the format options so that your code looks just the way you want it for ease of reading and understanding.
Regardless of which mode you work in, additional coding help is available in the Actions panel. The Reference button, for example, calls up the Reference panel and sends you directly to the description and usage of any selected action in case you have trouble remembering what a particular action does or how it is used. If you want to keep an ActionScript visible as you select other elements in your Flash movie, you can do so by pinning your script. Pinning makes your script "stick" in the Script pane until you unpin it. This technique is very useful if you've forgotten the name of a text box or a movie clip and need to reference it in an ActionScript statement. You can pin your current script and then go look for your text box or movie clip. Your script remains in place, so that you can make the necessary edits.
To use code hints in Expert mode:
Enter an action in the Script pane by typing the opening parentheses of the action.
Flash detects the action and anticipates that you will enter its parameters. A code hint appears to guide you (Figure 3.21). If an action has different ways of handling parameters, the tool tip shows those options (Figure 3.22).
Figure 3.21 A code hint guides you as you enter ActionScript. The first required parameter for this action is the URL.
Figure 3.22 The action gotoAndPlay can be used with one or two parameters. The code hint shows you both ways.
Enter the first parameter and then a comma.
The bold parameter in the code hint advances to highlight the next required parameter (Figure 3.23).
Figure 3.23 After you enter the first parameter, the code hint directs you to the next parameter. The next parameter for this action is the window.
Continue entering the required parameters, and type a closing parenthesis to finish the action.
The code hint disappears (Figure 3.24).
Figure 3.24 When you enter the closing parenthesis, the code hint disappears. The getURL action shown here doesn't require the last parameter (the method).
or
Enter an object target path and then a period.
Flash anticipates that you will enter a method or property of the particular object that appears before the period. A menu-style code hint appears to guide you (Figure 3.25).
Figure 3.25 The code hint provides a scrolling list of methods and properties for each object. This list contains the methods and properties of the Math object.
Choose the appropriate method or property from the menu.
The method or property appears in the Script pane after your dot. Another code hint appears to guide you, providing the parameters of the method (Figure 3.26).
Figure 3.26 The sqrt() method of the Math object requires a number for its parameter.
Enter the parameters of the method, and type a closing parenthesis to finish.
The code hint disappears (Figure 3.27).
Figure 3.27 When you complete the method, the code hint disappears.
Tips
Dismiss a code hint by pressing the Escape key or clicking a different place in your script.
Navigate the menu-style code hints by using the arrow keys, the Page Up and Page Down keys, or the Home and End keys. You can also start typing, and the entry that begins with the letter you type will appear in the code hint. Press Enter to choose the selection.
You can call up code hints manually by pressing Ctrl-spacebar or by clicking the Show Code Hint button above the Script pane when your pointer is in a spot where code hints are appropriate (Figure 3.28).
Figure 3.28 The Show Code Hint button is above the Script pane in Expert mode.
Change the delay time for code hints to appear or turn off code hints by choosing Preferences from the Actions panel's Options menu. When the Preferences dialog box appears, change your preferences in the ActionScript Editor tab (Figure 3.29).
Figure 3.29 In the Preferences dialog box, you can change the time that it takes for code hints to appear.
To set formatting options in Expert mode:
From the Actions panel's Options menu, choose Auto Format Options.
The Auto Format Options dialog box appears.
Set the different formatting options and specify the way a typical block of code should appear (Figure 3.30); then click OK
Figure 3.30 The AutoFormat options dialog box gives you a preview of how a typical block of code would look with the selections you made..
Choose Auto Format from the Actions panel's Options menu (Ctrl-Shift-F for Windows, Cmd-Shift-F for Mac), or click the Auto Format button above the Script pane.
Flash formats your script in the Script pane according to the preferences you set in the Auto Format Options dialog box.
To look up actions in the Reference panel:
Select an ActionScript term in the Script pane or the Actions toolbox, and click the Reference button above and to the right of the Script pane.
or
Right-click (Win) or Ctrl-Click (Mac) an action in the Actions toolbox, and select View Reference from the context menu that appears.
The Reference panel opens to the selected ActionScript term. The typical entry in the Reference panel contains information about usage and syntax, lists parameters and their availability in various Flash versions, and sample code (Figure 3.31).
Figure 3.31 The entry for the gotoAndPlay action in the Reference panel.
To pin or unpin a script in the Script panel:
With ActionScript visible in the Script pane, click the Pin Current Script button to the right of the Script pull-down menu (Figure 3.32).
Figure 3.32 The Pin Current Script button (top) toggles to Unpin Current Script (bottom).
To unpin the script, click the button again.
ActionScript Categories
You've learned that objects, methods, and properties are essential components of ActionScript. But how do they relate to the categories of actions in the Actions toolbox in the Actions panel, and what are the other categories of actions? Flash organizes actions hierarchically in eight categories, plus an index. These categories are Actions, Operators, Functions, Constants, Properties, Objects, Deprecated, and Flash UI Components. Many contain subcategories of actions. Following is a brief description of the categories.
Actions contains the generic commands that control the movie. This category includes actions that manipulate variables (placeholders), expressions (formulas that combine variables), and conditional statements. This category also includes actions that work with movie clips, such as startDrag(mySpaceship). In general, you will be accessing many of the actions in this category to create the interactions between your objects.
Operators contains the symbols that transform variables and expressions or compare one value with another. They include the common mathematical symbols, such as the plus and minus sign, and symbols that modify text elements.
Functions contains actions, such as getVersion(), that retrieve specific pieces of information. You can think of functions as being input-output machines that return useful information.
Constants contains keywords that always signify a certain value. You can use constants, such as true and false, in your expressions.
Properties contains the keywords that refer to descriptions of movie clips that you can modify or evaluate. The property _rotation controls the angle of a movie clip, for example.
Objects contains all the objects and their unique methods and properties. An example is Selection.getFocus().
Deprecated contains the actions that are no longer recommended for use because newer actions have replaced them. These actions are collected in this category if you need to create older Flash content.
Flash UI Components contains all the premade interface components provided by Macromedia. Components are specialized movie clips whose contents you can customize. A Component pull-down menu, for example, lets you set the menu's options and its appearance without having to worry about coding its functionality.
Index contains all the ActionScript terms in alphabetical order. If you don't know where to find a term, select it in the Index category and right-click (Windows) or Ctrl-click (Mac). In the context menu that appears, choose View Original, and the correct category opens to show the term.