194
Syntax and Language Fundamentals
Using assignment operators
You can use the assignment operator (=) to assign a given value to a variable. You might assign
a string to a variable, as follows:
var myText:String = "ScratchyCat";
You can also use the assignment operator to assign several variables in the same expression. In
the following statement, the value of 10 is assigned the variables
numOne
,
numTwo
, and
numThree
.
var numOne:Number;
var numTwo:Number;
var numThree:Number;
numOne = numTwo = numThree = 10;
You can also use compound assignment operators to combine operations. These operators
perform the operation on both operands, and then they assign the new value to the first
operand. For example, both of these statements do the same thing:
var myNum:Number = 0;
myNum += 15;
myNum = myNum + 15;
When you work with the assignment operator, you can have problems if you try to add values
in an expression, as you can see in the following example:
trace("the sum of 5 + 2 is: " + 5 + 2); // the sum of 5 + 2 is: 52
Flash concatenates the values
5
and
2
instead of adding them. To work around this, you can
wrap the expression
5+2
in a pair of parentheses, as shown in the following code:
trace("the sum of 5 + 2 is: " + (5 + 2)); // the sum of 5 + 2 is: 7
About logical operators
You use logical operators to compare Boolean values (
true
and
false
) and then return a
Boolean value based on the comparison. For example, if you have two operands that evaluate
to
true
, the logical AND (
&&
) operator returns
true
. Or if one or both of the operands
evaluate to
true
, the logical OR (
||
) operator returns
true
.
The logical operators take two operands and return a Boolean result. The logical operators
differ in precedence and are listed in the table in order of decreasing precedence:
For information on using logical operators, see
“Using logical operators” on page 195
.
Operator
Operation performed
&&
Logical AND
||
Logical OR
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...