User Guide
110 Chapter 5: ActionScript Core Language Elements
Returns
A Boolean value.
Description
Operator (logical); evaluates expression1 (the expression on the left side of the operator) and
returns
true if the expression evaluates to true. If expression1 evaluates to false,
expression2 (the expression on the right side of the operator) is evaluated. If expression2
evaluates to
false, the final result is false; otherwise, it is true.
If you use a function call as
expression2, the function will not be executed by that call if
expression1 evaluates to true.
The result is
true if either or both expressions evaluate to true; the result is false only if both
expressions evaluate to
false. You can use the logical OR operator with any number of operands;
if any operand evaluates to
true, the result is true.
For more information, see “Operator precedence and associativity” on page 32.
Example
The following example uses the logical OR (||) operator in an if statement. The second
expression evaluates to
true, so the final result is true:
var x:Number = 10;
var y:Number = 250;
var start:Boolean = false;
if ((x>25) || (y>200) || (start)) {
trace("the logical OR test passed"); // output: the logical OR test passed
}
The message the logical OR test passed appears because one of the conditions in the if
statement is true (
y>200). Although the other two expressions evaluate to false, as long as one
condition evaluates to
true, the if block executes.
The following example demonstrates how using a function call as
expression2 can lead to
unexpected results. If the expression on the left of the operator evaluates to
true, that result is
returned without evaluating the expression on the right (the function
fx2() is not called).
function fx1():Boolean {
trace("fx1 called");
return true;
}
function fx2():Boolean {
trace("fx2 called");
return true;
}
if (fx1() || fx2()) {
trace("IF statement entered");
}
/* The following is sent to the log file:
fx1 called
IF statement entered
*/