Changing the Properties of Objects

I l @ ve RuBoard

An object that you are already familiar with is the movie clip. All its defining characteristicsheight, width, transparency, and so onare called its properties . When you are authoring a movie, you can change these characteristics with Flash's drawing tools, but ActionScripts let you modify an object's properties during playback.

To script a button that makes a movie clip invisible:

  1. Create a new Flash document, and place an instance of a movie clip and a button on the Stage in Keyframe 1.

  2. On the Stage, select the movie clip instance.

  3. In the Property Inspector's Instance Name field, enter a name for the instance, such as starMC1 (Figure 15.1).

    Figure 15.1. To make a movie clip the target of ActionScript, you must give the clip an instance name in the Property Inspector.

    graphics/15fig01.gif

  4. On the Stage, select the button instance.

  5. In the Property Inspector's Instance Name field, enter hideBTN .

  6. In the Actions-Button panel, from the Add menu, choose Actions > Movie Control > on .

    Flash adds the button handler to the Script pane.

  7. With the handler (Line 1 of the script) selected, in the Actions Toolbox, double-click Actions > Movie Clip Control > setProperty (Figure 15.2).

    Figure 15.2. You can create a button script that will control your movie clip by choosing actions from the Actions> Movie Clip Control category in the Actions Toolbox (shown) or from the Add menu.

    graphics/15fig02.gif

    Flash adds the setProperty action to Line 2 in the Script pane and displays fields for entering the appropriate parameters.

  8. From the Property pop-up menu, choose _visible (Visibility) (Figure 15.3).

    Figure 15.3. In Normal mode, the parameters area of the Actions panel offers a pop-up menu of properties that you can set for movie-clip objects when you add setProperty to a script. Visibility controls whether viewers can see the movie clip.

    graphics/15fig03.gif

    The _visible property has two possible states (or values): true (the object is visible) or false (the object is disabled and hidden).

    Terminology: Expressions and Variables

    Expressions and variables go hand in hand. If creating ActionScripts were like cooking, expressions would be the recipes, and variables would be the bowls, cups, pans, and other containers. The values would be the ingredients that you place in the containers.

    The recipe/expression might say, "Combine the contents of the red bowl and the green bowl, and put it in the blue pan." If you put eggs in the red bowl and milk in the green bowl, you'l get one dish. If you put tomatoes in the red bowl and pasta in the green bowl, you'l get quite another. Although the containers are the same, and although the instructions for combining their contents are the same, the variety of the contents makes for different results.

    When you create a movie clip and place it on the Stage, its default visibility is true. To script a button that hides the clip, you must set the clip's visibility to false.

  9. In the Target field, enter the instance name of the movie clip, starMC1 .

    This parameter tells Flash which object you want to perform the action on.

  10. In the Value field, enter false , and check the Expression checkbox.

    Checking the Expression checkbox tells Flash to interpret what you enter in the Value field as a description of the value, not as a set of the particular letters f, al, l, s, and e (Figure 15.4).

    Figure 15.4. By setting the parameters of the setProperty action, you tell Flash which object to manipulate and what to do with it. Here, setting the visibility property of the starMC1 movie clip to false will hide the movie clip.

    graphics/15fig04.gif

  11. Choose Control > Test Movie to try out your button.

    When you click the button, the movie clip disappears.

graphics/01icon02.gif Tips

  • Try duplicating the button, naming it showBTN . The duplicate has the same ActionScript attached. In the Script pane, double-click Line 2 to display the parameters of the _visible property. In the Value field, enter true . Now you have one button that makes the clip disappear and another that brings it back.

  • Play around with the various properties in the pop-up Property menu. Try changing the movie clip's width, height, or alpha setting, for example. If you're not sure what type of value to enter for a given property, look at the property in the Reference panel (choose Window > Reference) to see a description and examples.

  • The letters MC in the instance name are not required; they are just a mnemonic device to help you determine what you are dealing with when you see it in the somewhat cryptic context of a script.


Terminology: Syntax

ActionScript has its own rules, which are analogous to the rules of grammar and spelling in English. These rules, called syntax , govern such things as word order, capitalization, and punctuation of action statements. When you set the Actions panel to operate in Normal mode, Flash enters the statements you choose and handles most of the details of syntax for you. The following list briefly describes common ActionScript punctuation marks.

Dot (.). ActionScript uses dot syntax , meaning that periods act as links between objects and the properties (characteristics) and methods (behaviors) applied to them. In the statement

 cloneMC._duplicateMovieClip 

the dot (the period) links the movie clip named cloneMC with the method that creates a copy of the movie clip.

The dot also indicates the hierarchy of files and folders in path names, similar to the way that a slash does in HTML syntax. (Note that Flash 4 used slashes to indicate path names . Flash MX still recognizes this slash syntax , but Macromedia recommends using dot syntax, and that's what you'll find in this book.)

Semicolon (;). A semicolon indicates the end of a statement. The semicolon is not required Flash interprets the end of the line of statements correctly without itbut including it is good scripting practice. The semicolon also acts as a separator in some action statements.

Braces ({}). Braces set off ActionScript statements that belong together. A set of actions that take place after on (release) , for example, must be set off by braces.

Note that the action statements within braces can require their own beginning and ending braces. The opening and closing braces must pair up evenly. When you use Normal mode and Basic Actions, Flash enters the pairs of braces for you. You still need to pay at ention to where you are adding scripts within the Script pane, however, to ensure that you group the actions as you intend.

Parentheses (). Parentheses group the arguments that apply to a particular statement defining the scene and frame in a goto action, for example. Parentheses also allow you to group operations, such as mathematical calculations, so that they take place in the right order.

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