Using Operators To Manipulate Values In Expressions - MACROMEDIA FLASH MX 2004 - ACTIONSCRIPT Reference Manual

Actionscript reference guide
Hide thumbs Also See for FLASH MX 2004 - ACTIONSCRIPT:
Table of Contents

Advertisement

Using operators to manipulate values in expressions

An expression is any statement that Flash can evaluate and that returns a value. You can create an
expression by combining operators and values or by calling a function.
Operators are characters that specify how to combine, compare, or modify the values of an
expression. The elements that the operator performs on are called operands. For example, in the
following statement, the
;
and
are the operands:
foo
foo
3
foo + 3
This section describes general rules about common types of operators, operator precedence, and
operator associativity. For detailed information on each operator mentioned here, as well as
special operators that don't fall into these categories, see the entries in
Dictionary," on page
Operator precedence and associativity
When two or more operators are used in the same statement, some operators take precedence over
others. ActionScript follows a precise hierarchy to determine which operators to execute first. For
example, multiplication is always performed before addition; however, items in parentheses take
precedence over multiplication. So, without parentheses, ActionScript performs the
multiplication in the following example first:
total = 2 + 4 * 3;
The result is 14.
But when parentheses surround the addition operation, ActionScript performs the addition first:
total = (2 + 4) * 3;
The result is 18.
When two or more operators share the same precedence, their associativity determines the order
in which they are performed. Associativity can be either left-to-right or right-to-left. For example,
the multiplication operator has an associativity of left-to-right; therefore, the following two
statements are equivalent:
total = 2 * 3 * 4;
total = (2 * 3) * 4;
For a table of all operators and their precedence and associativity, see
Precedence and Associativity," on page
Numeric operators
Numeric operators add, subtract, multiply, divide, and perform other arithmetic operations.
The most common usage of the increment operator is
You can use the increment operator before or after an operand. In the following example,
incremented first and then tested against the number 30:
if (++age >= 30)
In the following example,
if (age++ >= 30)
operator adds the value of a numeric literal to the value of the variable
+
205.
787.
is incremented after the test is performed:
age
instead of the more verbose
i++
Using operators to manipulate values in expressions
Chapter 12, "ActionScript
Appendix B, "Operator
i = i+1
age
.
is
45

Advertisement

Table of Contents
loading
Need help?

Need help?

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

Questions and answers

Table of Contents