EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 92

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
92 Data and Data Types
The ActionScript editor supports code hints for built-in classes and for variables that are based
on these classes. If you want Flash to provide code hints for a particular object type that you
assign to a variable, you can strictly type the variable. Code hints provide tooltip-style syntax
hints and a pop-up menu that helps you write your code quickly.
For example, type the following code:
var members:Array = new Array();
members.
As soon as you type the period (.) in the Actions panel, Flash displays a list of methods and
properties available for Array objects.
For recommended coding conventions for naming variables, see “Naming variables
on page 736.
Using variables in an application
In this section, you use variables in short code snippets of ActionScript. You need to declare
and initialize a variable in a script before you can use it in an expression. Expressions are
combinations of operands and operators that represent a value. For example, in the expression
i+2, i and 2 are operands, and + is an operator.
If you do not initialize a variable before you use it in an expression, the variable is undefined
and may cause unexpected results. For more information on writing expressions, see Chapter
5, “Syntax and Language Fundamentals,” on page 113.
If you use an undefined variable, as shown in the following example, the variables value in
Flash Player 7 and later will be
NaN, and your script might produce unintended results:
var squared:Number = myNum * myNum;
trace(squared); // NaN
var myNum:Number = 6;
In the following example, the statement that declares and initializes the variable myNum comes
first, so
squared can be replaced with a value:
var myNum:Number = 6;
var squared:Number = myNum * myNum;
trace(squared); // 36
Similar behavior occurs when you pass an undefined variable to a method or function, as
shown next.
To compare undefined and defined variables being passed to a function:
1. Drag a Button component to the Stage from the Components panel.
2. Open the Property inspector and type bad_button into the Instance Name text box.

Table of Contents

Related product manuals