MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual page 180

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

It's also possible for operators to have the same precedence. In this case, the associativity
determines the order in which the operators perform. You can either have left-to-right
associativity or right-to-left associativity.
Take a look at the multiplication operator again. It has left-to-right associativity, so the
following two statements are the same.
var mySum:Number;
var myOtherSum:Number;
mySum = 2 * 4 * 3;
myOtherSum = (2 * 4) * 3;
trace(mySum); // 24
trace(myOtherSum); // 24
You might encounter situations in which two or more operators of the same precedence
appear in the same expression. In these cases, the compiler uses the rules of associativity to
determine which operator to process first. All of the binary operators, except the assignment
operators, are left-associative, which means that operators on the left are processed before
operators on the right. The assignment operators and the conditional (
) operator are right-
?:
associative, which means that the operators on the right are processed before operators on the
left. For more information on assignment operators, see
"Using assignment operators"
on page
194. For more information on the conditional (?:) operator, see
"About the
conditional operator" on page
199.
For example, consider the less than (
) and greater than (
) operators, which have the same
<
>
precedence. If both operators are used in the same expression, the operator on the left is
processed first because both operators are left-associative. This means that the following two
statements produce the same output:
trace(3 > 2 < 1);
// false
trace((3 > 2) < 1); // false
The greater than (
) operator is processed first, which results in a value of
because the
>
true
operand
is greater than the operand
. The value
is then passed to the less than (
)
3
2
true
<
operator, along with the operand
. The less than (
) operator converts the value
to the
1
<
true
numeric value
and compares that numeric value to the second operand
to return the value
1
1
(the value
is not less than
).
false
1
1
Consider the order of operands in your ActionScript, particularly when you set up complex
conditions and you know how often one of those conditions is true. For example, if you know
that
will be greater than 50 in your condition, you need to write
first. Therefore, it's
i
i<50
checked first, and the second condition that you write doesn't need to be checked as often.
180
Syntax and Language Fundamentals

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

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?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flash 8

Table of Contents