![]() ![]() | |
Flash Player 4.
expression1 || expression2
expression1,expression2 A Boolean value or an expression that converts to a Boolean value.
A Boolean value.
Operator (logical); evaluates expression1 and expression2. 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.
With non-Boolean expressions, the logical OR operator causes Flash to evaluate the expression on the left; if it can be converted to true, the result is true. Otherwise, it evaluates the expression on the right and the result is the value of that expression.
Usage 1: The following example uses the || operator in an if statement. The second expression evaluates to true so the final result is true:
x = 10
y = 250
start = false
if(x > 25 || y > 200 || start){
trace('the logical OR test passed');
}
Usage 2: This example demonstrates how a non-Boolean expression can produce an unexpected result. If the expression on the left converts to true, that result is returned without converting the expression on the right.
function fx1(){
trace ("fx1 called");
returns true;
}
function fx2(){
trace ("fx2 called");
return true;
}
if (fx1() || fx2()){
trace ("IF statement entered");
}
// The following is sent to the Output panel:
// fx1 called
// IF statement entered
![]() ![]() | |