ActionScript 2.0 has the operators of ActionScript 1.0 in Flash MX, plus the colon of type annotations, and keeps the Flash 4 word operators as deprecated. How operators convert their operands is on Types and conversion.
Precedence and associativity
Operators higher in the table bind more tightly; operators on one row are grouped by
their associativity. This follows the table in Macromedia’s ActionScript reference for
Flash MX 2004, with === and !==, which it leaves out, placed
with == as in ECMA-262.
| Level | Operators | Kind | Associativity |
|---|---|---|---|
| 1 | x() x[] x.y x++ x-- | call, member, postfix | left to right |
| 2 | ++x --x +x -x ~ ! not new delete typeof void | unary | right to left |
| 3 | * / % | multiplicative | left to right |
| 4 | + - add | additive | left to right |
| 5 | << >> >>> | shift | left to right |
| 6 | < <= > >= instanceof lt le gt ge | relational | left to right |
| 7 | == != === !== eq ne <> | equality | left to right |
| 8 | & | bitwise and | left to right |
| 9 | ^ | bitwise exclusive or | left to right |
| 10 | | | bitwise or | left to right |
| 11 | && and | logical and | left to right |
| 12 | || or | logical or | left to right |
| 13 | ?: | conditional | right to left |
| 14 | = *= /= %= += -= <<= >>= >>>= &= ^= |= | assignment | right to left |
| 15 | , | comma | left to right |
A cast, Type(value), is parsed as a call and so binds at level 1.
Every operator
The player column is the first Flash Player that runs it, as Adobe’s ActionScript 2.0 reference gives it. ActionScript 2.0 itself needs Flash Player 6 or later.
| Operator | Name | Does | Player |
|---|---|---|---|
+ | addition | Adds numbers, or joins strings if either side is a string. | 4 |
- | subtraction, negation | Subtracts, or with one operand negates. | 4 |
* / % | multiplication, division, modulo | Arithmetic on numbers; % works on fractions too. | 4 |
++ -- | increment, decrement | Add or subtract 1, giving the new value before the operand and the old value after it. | 4 |
= | assignment | Sets a variable, property or element; checked against the target’s type. | 4 |
+= -= *= /= %= | compound assignment | a += b is a = a + b. | 4 |
& | ^ ~ | bitwise | Work on 32-bit integers. | 5 |
<< >> >>> | shifts | Left, signed right and unsigned right shift. | 5 |
&= |= ^= <<= >>= >>>= | bitwise assignment | As the compound assignments. | 5 |
== != | equality | Compare after converting to a common type. | 5 |
=== !== | strict equality | Compare without converting. | 6 |
< > <= >= | comparison | Compare numbers, or two strings by character code. | 4 |
&& || ! | logical | && and || evaluate the right side only if needed and give the deciding value. | 4 |
?: | conditional | a ? b : c. | 4 |
, | comma | Evaluates both, gives the right one. | 4 |
. [] | member access | A property by name or by computed name; [] also makes arrays. Dot access on a typed value is checked, bracket access is not. | 4 |
{} | object literal | A new Object. | 5 |
() | parentheses | Groups, calls a function, or casts when the callee is a type. | 4 |
new | new | Makes an object with a class’s constructor. | 5 |
delete | delete | Removes a property and gives true if it did. | 5 |
typeof | typeof | Gives a type name; see Types. | 5 |
void | void | Gives undefined. | 5 |
instanceof | instanceof | True if the object is an instance of the class, and from player 7 also of an interface it implements. | 6 |
: | type | Not an operator at run time: in a declaration, gives the type of a variable, parameter or return value. | compile time |
Deprecated operators
The Flash 4 string and logic words still compile but should not be used in new
code: add (use +), eq (==),
ne (!=), lt (<), gt
(>), le (<=), ge
(>=), and (&&), or
(||), not (!) and <>
(!=). The string forms convert both sides to strings.