46 Chapter 2: ActionScript Basics
The following table lists the ActionScript numeric operators:
Comparison operators
Comparison operators compare the values of expressions and return a Boolean value (
true or
false). These operators are most commonly used in loops and in conditional statements. In the
following example, if the variable
score is 100, a certain SWF file loads; otherwise, a different
SWF file loads:
if (score > 100){
loadMovieNum("winner.swf", 5);
} else {
loadMovieNum("loser.swf", 5);
}
The following table lists the ActionScript comparison operators:
String operators
The
+ operator has a special effect when it operates on strings: it concatenates the two string
operands. For example, the following statement adds "Congratulations," to "Donna!":
"Congratulations, " + "Donna!"
The result is "Congratulations, Donna!" If only one of the + operator’s operands is a string,
Flash converts the other operand to a string.
The comparison operators
>, >=, <, and <= also have a special effect when operating on strings.
These operators compare two strings to determine which is first in alphabetical order.
The comparison operators only compare strings if both operands are strings. If only one of
the operands is a string, ActionScript converts both operands to numbers and performs a
numeric comparison.
Operator Operation performed
+
Addition
*
Multiplication
/
Division
%
Modulo (remainder of division)
-
Subtraction
++
Increment
--
Decrement
Operator Operation performed
<
Less than
>
Greater than
<=
Less than or equal
>=
Greater than or equal