176
ActionScript language elements
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 Output panel: fx1 called IF statement entered
See also
! logical NOT operator
,
!= inequality operator
,
!== strict inequality
operator
,
&& logical AND operator
,
== equality operator
,
=== strict equality
operator
or logical OR operator
condition1
or
condition2
Deprecated
since Flash Player 5. This operator was deprecated in favor of the
|| (logical
OR)
operator.
Evaluates
condition1
and
condition2
, and if either expression is
true
, the whole expression
is
true
.
Summary of Contents for FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE
Page 1: ...ActionScript 2 0 Language Reference ...
Page 1352: ...1352 ActionScript classes ...