User Guide
46 Chapter 2: ActionScript Language Reference
, (comma)
Availability
Flash Player 4.
Usage
(expression1, expression2 [, expressionN...])
Parameters
None.
Returns
The value of expression1, expression2, and so on.
Description
Operator; evaluates expression1, then expression2, and so on. This operator is primarily used
with the
for loop statement and is often used with the parentheses () operator.
For more information, see “Operator precedence and associativity” in Using ActionScript in Flash.
Example
The following example uses the comma (,) operator in a for loop:
for (i = 0, j = 0; i < 3 && j < 3; i++, j+=2) {
trace("i = " + i + ", j = " + j);
}
// Output:
// i = 0, j = 0
// i = 1, j = 2
The following example uses the comma (,) operator without the parentheses () operator and
illustrates that the comma operator returns only the value of the first expression without the
parentheses () operator:
var v:Number = 0;
v = 4, 5, 6;
trace(v); // output: 4
The following example uses the comma (,) operator with the parentheses () operator and
illustrates that the comma operator returns the value of the last expression when used with the
parentheses () operator:
var v:Number = 0;
v = (4, 5, 6);
trace(v); // output: 6
The following example uses the comma (,) operator without the parentheses () operator and
illustrates that the comma operator sequentially evaluates all of the expressions but returns the
value of the first expression. The second expression,
z++, is evaluated and z is incremented by
one.
var v:Number = 0;
var z:Number = 0;