(Increment) - MACROMEDIA FLASH MX 2004-ACTIONSCRIPT LANGUAGE Reference

Actionscript language reference
Table of Contents

Advertisement

++ (increment)

Availability
Flash Player 4.
Usage
++expression
expression++
Parameters
A number or a variable that evaluates to a number.
expression
Returns
A number.
Description
Operator (arithmetic); a pre-increment and post-increment unary operator that adds 1 to
. The
expression
The pre-increment form of the operator (
result. The post-increment form of the operator (
returns the initial value of
The pre-increment form of the operator increments
as
:
y
var x:Number = 1;
var y:Number = ++x;
trace("x:"+x);//traces x:2
trace("y:"+y);//traces y:2
The post-increment form of the operator increments
value of
as the result
x
var x:Number = 1;
var y:Number = x++;
trace("x:"+x);//traces x:2
trace("y:"+y);//traces y:1
For more information, see "Operator precedence and associativity" in Using ActionScript in Flash.
Example
The following example uses ++ as a post-increment operator to make a
var i:Number = 0;
while (i++<5) {
trace("this is execution "+i);
}
/* output:
this is execution 1
this is execution 2
this is execution 3
this is execution 4
can be a variable, element in an array, or property of an object.
expression
(the value prior to the addition).
expression
:
y
) adds 1 to
++expression
expression++
to 2 (
x
x + 1 = 2
to 2 (
x
x + 1 = 2
and returns the
expression
) adds 1 to
expression
) and returns the result
) and returns the original
loop run five times:
while
++ (increment)
and
27

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH MX 2004-ACTIONSCRIPT LANGUAGE and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flash mx

Table of Contents