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
.
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
wrap the expression
5+2
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 (
Boolean value based on the comparison. For example, if you have two operands that evaluate
to
, the logical AND (
true
evaluate to
, the logical OR (
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:
Operator
Operation performed
Logical AND
&&
Logical OR
||
For information on using logical operators, see
194
Syntax and Language Fundamentals
and
instead of adding them. To work around this, you can
5
2
in a pair of parentheses, as shown in the following code:
) operator returns
&&
) operator returns
||
numOne
and
true
false
. Or if one or both of the operands
true
.
true
"Using logical operators" on page
,
, and
numTwo
) and then return a
195.
Need help?
Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?