Operator | Syntax and Description | Examples |
---|---|---|
. (dot operator) |
object.property object.method instancename.variable instancename.child.variable Used to navigate movie-clip hierarchies to access nested movie clips, variables, or properties. The dot operator is also used to test or set the properties of an object, execute a method of an object, or create a data structure. | The following identifies the pattern property of the seashell object: seaShell.pattern |
++ (increment) |
++expression; expression++; Adds 1 to the expression. The preincrement form (++expression) adds 1 to the expression and returns the result. The postincrement form adds 1 to the expression and returns the initial value of the expression. | +myVar; |
-- (decrement) |
--expression; expression--; Subtracts 1 from the expression. The predecrement form (--expression) subtracts 1 from expression and returns the result. The postdecrement form subtracts 1 from the expression and returns the initial value of the expression. | --myVar; |
+ (addition) | expression1 + expression2 Adds numeric expressions and concatenates strings. If one expression is a string, all other expressions are converted to strings and concatenated. If both expressions are integers, the sum is an integer; if either or both expressions are floating-point numbers, the sum is a floating-point number. | Example 1:
trace(1+2); The output window would display 3. Example 2: When myVar = "shark", the following expression returns “Oh no! It's a shark!”: trace("Oh no! It's a " +myVar+ "!"); |
– (subtraction and negation) |
-expression1; expression1-expression2 Used for subtraction and negation. If used for negation, it reverses the sign of the expression. If used for subtraction, it finds the difference between the two numbers. |
x=5; y=4; trace(-x); trace(x-y); The output window would display –5, then 1. |
* (multiplication) | expression1*expression2 Multiplies two numbers. | trace (2*4); The output window would display 8. |
/ (division) | expression1/expression2 Divides expression1 by expression2. | trace (21/3); The output window would display 7. |
+= (addition and assignment) | expression1 += expression2
Assigns expression1 the value of expression1 + expression2. x += y is equivalent to x = x+y. | Example 1:
x = 5; x += 10; trace (x); The output window would display 15. Example 2: x = "I am afraid of"; x += "sharks!"; trace(x); The output window would display: I am afraid of sharks! |
= (assignment) | expression1 = expression2 Assigns the type expression2 to the variable, array element, or property in expression1. | tackID = 0; |
== (equality) | expression1 == expression2 Tests two expressions for equality. If expression1 is equal to expression2, the result is true. | When myVar = "shark", the following expression returns true: myVar == "shark" |
!= (inequality) | expression1 != expression2 Tests for inequality. If expression1 is not equal to expression2, the result is true. | 1 != 2 returns true |
< (less than) | expression1 < expression2 Compares two expressions and determines whether expression1 is less than expression2. | 1 < 2 returns true |
> (greater than) | expression1 > expression2 Compares two expressions to determine whether expression1 is greater in value than expression2. | 300 > 900 returns false |
<= (less than or equal to) | expression1 <= expression2 Compares two expressions to determine whether expression1 is less than or equal to expression2 in value. | 4 <= 4 returns true 5 <= 3 returns false |
>= (greater than or equal to) | expression1 >= expression2 Compares two expressions to determine whether expression1 is greater than or equal to expression2. | 8 >= 5 returns true 30 >= 30 returns true |
&& (logical AND) | expression1 && expression2 Performs a Boolean (true or false) operation on both expressions. Both expression1 and expression2 must be true for the operator to return a final result of true. |
x= 10; y= 20; if ((x == 10) && (y == 20)) { trace ("The Neptune Resorts are great!"); } The output window would display: The Neptune Resorts are great! |
|| (logical OR) | expression1 || expression2 Performs a Boolean (true or false) operation on both expressions. The operator will return a final result of true if either expression1 or expression2 is true. |
x = 10; y = 30; if ((x == 10) || (y == 20)) { trace ("The Neptune Resorts are great!"); } The output window would display: The Neptune Resorts are great! |
delete | delete (reference); Deletes the object or variable specified in reference. Useful for removing no-longer-needed variables from your ActionScript. |
x = 10; delete x; shark.teeth = "large"; delete shark.teeth; |
new | new constructor(arguments); Creates a new object, calls the function identified by the constructor argument and passes additional optional arguments in the parentheses. |
tigerShark = new Shark (large, mean); hammerHeadShark = new Shark (medium, aggressive); |