Choosing Actions

I l @ ve RuBoard

In Normal mode, the Actions panel provides several ways for you to select action statements to include in an ActionScript: You can choose items from the Add pop-up menu; you can choose items from a scrolling list in the Actions Toolbox; and you can copy and paste items from a separate panel, the Reference panel (you'll learn more about using it later in this chapter). In both the menu and list form, Flash organizes statements hierarchically in categories and subcategories . In the Actions Toolbox, the categories can be collapsed and expanded just like nested folders.

graphics/01icon02.gif Tips

  • The Add menu is always available. Use it to create ActionScripts when you've configured the Actions panel to hide the Actions Toolbox.

  • With so many categories and subcategories, it can be hard to remember exactly which category holds a particular action. The Index category shows all the actions from the other categories in a single alphabetical list.


To use the Add menu:

  1. Open a Flash document, and make sure that the Actions panel is open .

  2. In the Timeline, select the frame to which you want to add actions.

    The name Actions-Frame appears in the title bar of the Actions panel.

  3. In the Actions-Frame panel, click the Add button (the one with a plus sign).

    A menu of action-statement categories appears.

  4. Choose a category.

    Some categories break down further into subcategories. In that case, a submenu of action-statement subcategories appears, and you must choose a subcategory as well.

  5. Choose a subcategory, if appropriate.

    A submenu of actions appears (Figure 12.8).

    Figure 12.8. The hierarchical Add pop-up menu lists actions to choose among.

    graphics/12fig08.gif

  6. Choose an action.

    Flash adds the chosen action to the Script pane.

The Mystery of Action Categories

In early versions of Flash, you put together scripts by choosing English-like statements from a single menu. As the ActionScript language has evolved, however, the statements have become less like English, and their numbers have increased. Scrolling through one long list of actions has become les practical. In an at empt to make the list more manageable, the Actions Toolbox organizes actions in eight main categories, each with its own subcategories. Until you become familiar with ActionScripting, however, trying to remember which category contains the action you are looking for can be difficult. You may find it easier to look for action statements directly by name. A ninth category, Index, lists all ActionScript items in one huge alphabetical list.

Here's a brief overview of the Actions Toolbox categories.

  • Actions. This category includes actions for controlling movie playback; controlling Web browsers and networks; manipulating movie clips, working with variables ; creating more sophisticated, subtle controls (such as testing whether certain conditions are true and creating logical loops ); printing from within Flash Player; setting up actions; and miscellaneous actions.

  • Operators. This category includes actions for calculating values from variables and expressions. One subcategory, Arithmetic Operators, is fairly easy to grasp. Arithmetic Operators basically are familiar mathematical symbols, such as the plus sign (+). You can use the + operator to add a series of numbers, for example.

    Operators can do more than math, however. You might have operators perform a "math operation" on text elements "adding" a series of words to form a message, for example. Or you might use operators to as ign values to variables. The equal sign in the expression p = w , for example, puts the value of the variable on the right side of the equal sign (in this case, w ) into the variable on the left side ( p ). Again, that value might be numbers, or it might be letters and words.

    You can also use operators to compare itemsto see whether the variables on either side of the operator have the same value, for example.

  • Functions. Functions are predefined chunks of ActionScript. Just as macros in a word processor encapsulate the necessary code for repetitive typing, formatting, and so on, functions in ActionScripts encapsulate bits of ActionScript that perform frequently used operations.

  • Constants. Constants are reserved words whose value is always the same, such as the Boolean expressions true and false .

  • Properties. Properties define the characteristics of objects. You often include properties actions in scripts that control objectsto set the transparency ( _alpha ) or screen position ( _x and _y ) of a movie-clip instance, for example.

  • Objects. Objects are collections of predefined properties (characteristics of an object), methods (sets of instructions for carrying out operations involving the object), and events. The Movie Clip object, for example, includes predefined properties such as useHandCursor and hitArea; methods such as prevFrame , nextFrame , play , and stop ; and events such as onLoad and onMouseDown .

  • Deprecated. Deprecated actions are actions that were available in earlier versions of Flash but that are being phased out (see the sidebar "More about Deprecated Actions," later in this chapter).

  • Flash UI Components . This category contains actions for creating your own reusable elements. Flash comes with several prefabricated components, such as scroll boxes and radio buttons . You can access these items from the Components panel.

  • Index. This category contains an alphabetical listing of all the items located in the other category folders.

    graphics/01icon02.gif Tip

    • Can't recall what category holds the action you want? Select the action in the alphabetized list in the Index category of the Actions Toolbox. Control-click (Mac) or right-click (Windows); then, from the contextual menu, choose Show Original. Flash pops open the right category and subcategory folders and selects the action in the Actions Toolbox.


To use the Actions Toolbox:

  1. In the Actions Toolbox, on the left side of the Actions panel, click a category icon.

    The icon expands, and a list of subcategories and/or actions appears.

  2. If appropriate, click a subcategory icon to access the action you need.

  3. To add an action to the Script pane, do one of the following:

    • Double-click the action.

    • Drag the action from the Actions Toolbox to the Script pane (Figure 12.9).

      Figure 12.9. When you drag a statement from the Actions Toolbox to the Script pane, the dog-eared pointer helps you position the action (top). Release the mouse button to place the action in your ActionScript (bottom).

      graphics/12fig09.gif

    • Control-click (Mac) or right-click (Windows) the action to access the contextual menu; then choose Add to Script.

      Flash places the appropriate text in the Script pane and displays any parameters associated with the statement in the Parameters area, located just above the Script pane (Figure 12.10).

      Figure 12.10. When you add an action to the Script pane, any parameters or properties that further define the action appear in the parameters area.

      graphics/12fig10.gif

graphics/01icon02.gif Tip

  • If you prefer, you can enter actions with keyboard shortcuts. All shortcuts for adding actions to scripts begin with the Esc key. To view these shortcuts in the Actions Toolbox, from the Options menu in the top-right corner of the Actions panel, choose View Esc Shortcut Keys. Flash displays the shortcut within square brackets immediately following the action to which it's assigned.


More about Deprecated Actions

As any language evolves, new words and expressions become standard and old terms fall out of everyday use. You can continue to speak and write with the older words, but as time passes those antiquated words become unintelligible to modern speakers . The same is true for scripting languages, where the term deprecated is used to designate "words," pieces of code, that still work but are superceded by more recent code. In the Actions Toolbox, the deprecated actions are gathered together in the Deprecated category.

In the development of Flash's scripting capabilities, major changes occurred between Flash versions 4 and 5. Version 5 introduced the full-fledged scripting language ActionScript. Many deprecated actions (such as the ones found in the Deprecated > Actions category of the Actions Toolbox) are left over from a time when Flash attempted to use easy-to-understand, English-like action statements to make scripting as easy as possible for novices.

Here's an example of a situation where you might have used a deprecated action: controlling playback of a movie clip with a button. Imagine you have an instance of a movie clip of a kitten playing (the name of the movie clip instance is cat ). In English, you might think, "At this point in my Flash movie, I want people to be able to make the cat be still. I must create a button that tells the cat to stop playing." In Flash 4, you might have created a script for the button like this

 on (release){    tellTarget ("cat"){         stop();     }  } 

In Flash MX you can accomplish the same thing with dot syntax using a much more compact statement (you'll learn more about dot syntax in Chapter 15).

 on (release){    cat.stop();  } 

The difference is subtle. The deprecated action is a bit longer and more English-like. Telling a target item (the thing in parentheses) to do the action that follows is a fairly easy concept for scripting novices. Simply using a period to connect an object to the action you want to perform on that object is more abstract. It may take a bit of practice to feel comfortable with the new syntax if you are making the transition from earlier versions of Flash.

Ultimately, relying on deprecated actions will stand in the way of your learning scripting. You'll soon reach the place where you want to try more adventuresome scripts, and you'll have to switch the way you think about putting those scripts together. So it makes sense to learn to use the new ActionScript right now.

In order to allow Flash MX designers to create documents that are compatible with earlier versions of Flash Player, Flash MX continues to support the deprecated actions, and they are compliant with ECMA-262a set of specifications for the JavaScript language developed by the European Computers Manufacturers Association (ECMA). A day may come, however, when that's no longer true.

I l @ ve RuBoard


Macromedia Flash MX for Windows and Macintosh. Visual QuickStart Guide
Macromedia Flash MX 2004 for Windows and Macintosh (Visual QuickStart Guides)
ISBN: 0582851165
EAN: 2147483647
Year: 2002
Pages: 243

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