You can manipulate the value of a variable using operators while a condition is
example, you can use the increment operator (
condition is true. In the following code, the condition is
10. While that is true, you increment
var i:Number;
for (i = 1; i < 10; i++) {
trace(i);
}
The Output panel displays the numbers 1 through 9, which is
reaches the end condition (
Therefore, the value of
For more information on conditions and loops, see
About operator precedence and associativity
When you use two or more operators in a statement, some operators take precedence over
other operators. Operator precedence and associativity determine the order in which
operators are processed. ActionScript has a hierarchy that determines which operators execute
before others. There is a table that outlines this hierarchy at the end of this section.
Although it may seem natural to those familiar with arithmetic or basic programming that the
compiler processes the multiplication (
compiler needs explicit instructions about which operators to process first. Such instructions
are collectively referred to as operator precedence.
You can see an example of operator precedence when you work with the multiplication and
addition operators:
var mySum:Number;
mySum = 2 + 4 * 3;
trace(mySum); // 14
You see the output of this statement is 14, because multiplication has a higher operator
precedence. Therefore, 4 * 3 is evaluated first and the result is added to 2.
You can control what happens by enclosing expressions in parentheses. ActionScript defines a
default operator precedence that you can alter using the parentheses (
put parentheses around the addition expression, ActionScript performs the addition first:
var mySum:Number;
mySum = (2 + 4) * 3;
trace(mySum); // 18
Now the output of this statement is
one number higher using
i
is equal to 10), when it stops. The last value displayed is 9.
i
is 1 when the SWF file starts playing, and 9 after the trace completes.
i
) operator before the addition (
*
.
18
) to increment the variable
++
while
true
i++
incrementing in value until it
i
"About statements" on page
. For
true
while the
i
is less than the value of
i
.
141.
) operator, the
+
) operator. When you
()
About operators
179
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?