User Guide
36 Chapter 1: ActionScript Basics
Logical operators
Logical operators compare Boolean values (
true and false) and return a third Boolean value.
For example, if both operands evaluate to
true, the logical AND (&&) operator returns true. If
one or both of the operands evaluate to
true, the logical OR (||) operator returns true. Logical
operators are often used with comparison operators to determine the condition of an
if
statement. For example, in the following script, if both expressions are true, the
if statement will
execute and the
myFunc() function will be called:
if (i > 10 && i <50){
myFunc(i);
}
Consider the order of operands, especially if you’re setting up complex conditions and you know
how often one condition is true compared with other conditions. In the previous example, if you
know that, in most cases,
i will be greater than 50, consider putting the condition i<50 first; the
condition
i<50 will be checked first, and the second condition doesn’t need to be checked in most
cases.
The following table lists the ActionScript logical operators:
Bitwise operators
Bitwise operators internally manipulate floating-point numbers to change them into 32-bit
integers. The exact operation performed depends on the operator, but all bitwise operations
evaluate each binary digit (bit) of the 32-bit integer individually to compute a new value.
The following table lists the ActionScript bitwise operators:
Operator Operation performed
&&
Logical AND: Returns true only if both the left and right operands are true.
||
Logical OR: Returns true if either the left or right operand is true.
!operand Logical NOT: Returns the logical (Boolean) opposite of the operand. The logical NOT
operator takes one operand.
Operator Operation performed
&Bitwise AND
|Bitwise OR
^Bitwise XOR
~Bitwise NOT
<< Shift left
>> Shift right
>>> Shift right zero fill