?: (conditional)
Availability
Flash Player 4.
Usage
expression1 ? expression2 : expression3
Parameters
expression1
such as
.
x < 5
,
expression2
expression3
Returns
The value of
expression2
Description
Operator; instructs Flash to evaluate
returns the value of
For more information, see "Operator precedence and associativity" in Using ActionScript in Flash.
Example
The following statement assigns the value of variable
evaluates to
true
var x:Number = 5;
var y:Number = 10;
var z = (x < 6) ? x: y;
trace (z); // returns 5
The following example shows a conditional statement written in shorthand:
var timecode:String = (new Date().getHours()<11) ? "AM" : "PM";
trace(timecode);
The same conditional statement could also be written in longhand, as shown in the following
example:
if (new Date().getHours()<11) {
var timecode:String = "AM";
} else {
var timecode:String = "PM";
}
trace(timecode);
52
Chapter 2: ActionScript Language Reference
An expression that evaluates to a Boolean value; usually a comparison expression,
Values of any type.
or
expression3
expression1
; otherwise it returns the value of
expression2
:
.
, and if the value of
to variable
x
is
expression1
true
.
expression3
because
z
expression1
, it
Need help?
Do you have a question about the FLASH MX 2004-ACTIONSCRIPT LANGUAGE and is the answer not in the manual?