Using Properties

 < Day Day Up > 



Properties are attributes of objects. Each instance of an object can have different properties. Movie Clips, frames, and symbols have properties that you can control through ActionScript. You can control changes, such as position, color, transparency, and so on.

In Flash MX, Movie Clips are no longer the only objects to which you can assign instance names. You can give instance names to buttons, text, and video. When you select the object, you type the instance name in the Property inspector.

To set a property, follow these steps:

  1. Select a Movie Clip.

  2. Open the Actions panel.

  3. Select the Properties book and choose the property you want to control. Add it to the right pane by double-clicking your choice.

  4. In the Parameters area type an expression. You can choose from the following:

    • _visible — Visibility is either true or false.

    • _x or _y — The x, y coordinates of the object.

    • _droptarget — The target path of a dragable Movie Clip that must be dropped on a specific target.

An example of changing properties of a Movie Clip would be to move a clip by a specified number of pixels. Let's say you wanted to move the mymovie2 Movie Clip by 20 pixels. The first thing to do is locate the clip. Then you set the new value (more on setting values in the "Variables" section). The getProperty action does this. To move the mymovie2 Movie Clip (remember this is inside mymovie1) by 20 pixels, follow these steps:

  1. Select the frame or object you are attaching the action to. In Normal mode open the Movie Clip Control book in the Actions toolbox and double-click on getProperty.

  2. In the Parameters pane there is a drop-down list of properties to choose from; select the x.

  3. Click in the Target field, then click the Insert a Target Path icon and select the Movie Clip you want to target.

  4. For the value, check Expression, then type 20 into the Value field. So if you want to move mymovie2 over 20 pixels the code would be

    getProperty("mymovie2.mymovie2","_x") + 20

If you try to enter this code directly into the setProperty value box, it wouldn't work. If it's entered in the value box, Flash thinks it's a value and it isn't. Flash needs to perform a calculation to determine the value (expression), so check the Expression box by the value of the setProperty action. You can see how you can save a lot of time once you understand how to write ActionScript. It would be much easier to write this line of code rather than use the Normal mode.

Variables

Variables are the information containers of ActionScript. The container is the variable's name, which remains constant, but the content can change. Variables can record user input and evaluate whether a condition is true or false.

Flash remembers data and the label that identifies the data. The data and its label make up the variable. Every variable has a name, which is used to access the data it contains. To put information into the container (variable) the formula is as follows:

variable Name = Value variable Name is the name of the variable and value is the data, for  example: message="Hi";

Message is the variable name, the text (Hi) is the value, and the equal sign (=) is the assignment operator. It assigns the right side to the variable on the left side. In this example, the value is text. The value can also be mathematical. Your code can be attached to a frame, keyframe, button, or Movie Clip.

To set or declare a value, you can type the variable's name or use an action. The set variable action is in the Variables book. Double-click set variable to see a message telling you that the variable has to be named. In the value box, I typed Joyce. The syntax reads as follows:

MyName = "Joyce";
Note 

Declaring or setting the variable is a good habit to get into, but if you don't, Flash does it automatically. If you come from a programming background you can name your variables with var prefix. Setting the variable yourself lets you make your own naming conventions.

Variables are stored in the target where they are declared. So if you have TitleName="Macromedia Studio MX Bible" in a Movie Clip named mymovie1 and in the Movie Clip named mymovie2, there won't be a problem.

Movie Clips can share variables by using target paths that describe where they are. If you recall in the ActionScript overview, you used mymovie1 and mymovie2 Movie Clips with mymovie2 inside of title. If you want to change the value of TitleName in the Movie Clip mymovie2 from the main Timeline (root or level0) the code would look as follows:

_level2.mymovie1.mymovie2.TitleName="New Value"
Tip 

When first learning how to write your own code, you can set an option to check the syntax for you by choosing Check Syntax from the Actions panel Options pop-up menu. If an error is found, an Output dialog box opens and any errors are described. When you are first beginning to write code, you should check it often by pressing Control+Enter (Command+Return). If you are still having problems with your code, you can use the Debug option by choosing Control ® Debug Movie.

Data types

Data type is the kind of information that a variable element can hold. There are prime data types (string, number, and Boolean) which have a constant value. Then there are reference data types (Movie Clip and objects) which have values that can change. This list describes the different data types.

  • Strings — A string consists of text or numbers or both enclosed in quotes (""). When using numerical calculations, the quotes are not present in the code. The quote marks indicate a string. If you were to use numbers such as "6" + "2" it would be interpreted at 62.

  • Boolean — Variable values that are either true or false. Boolean values are used in either/or situations such as a toggle switch.

  • Number — Number data types are any values (or expression values) that refer to numeric values in Flash. Number data does not contain quotes around it in the syntax.

  • Movie Clip — Movie Clips are symbols, and they are the only data type that refers to a graphic element.

  • Object — Objects have properties and each property has a name and value. The value can be any data type including the object data type.



 < Day Day Up > 



Macromedia Studio MX Bible
Macromedia Studio MX Bible
ISBN: 0764525239
EAN: 2147483647
Year: 2003
Pages: 491

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