Using operators to manipulate values in expressions 47
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 action.
For example, in the following script, if both expressions are true, the
if action will execute:
if (i > 10 && _framesloaded > 50){
play();
}
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:
Equality operators
You can use the equality (
==) operator to determine whether the values or identities of two
operands are equal. This comparison returns a Boolean (
true or false) value. If the operands are
strings, numbers, or Boolean values, they are compared by value. If the operands are objects or
arrays, they are compared by reference.
It is a common mistake to use the assignment operator to check for equality. For example, the
following code compares x to 2:
if (x == 2)
In that same example, the expression x = 2 is incorrect because it doesn’t compare the operands,
it assigns the value of 2 to the variable
x.
Operator Operation performed
&&
Logical AND
||
Logical OR
!
Logical NOT
Operator Operation performed
&Bitwise AND
|Bitwise OR
^Bitwise XOR
~Bitwise NOT
<< Shift left
>> Shift right
>>> Shift right zero fill