Conditional Operator - MACROMEDIA FLASH 8-FLASH LITE 2.X ACTIONSCRIPT LANGUAGE Reference

Flash lite 2.x actionscript language reference
Hide thumbs Also See for FLASH 8-FLASH LITE 2.X ACTIONSCRIPT LANGUAGE:
Table of Contents

Advertisement

?: conditional operator

expression1 ? expression2 : expression3
Instructs Flash to evaluate
the value of
expression2
Availability: ActionScript 1.0; Flash Lite 1.0
Operands
expression1 :
Object
usually a comparison expression, such as
expression2 :
Object
expression3 :
Object
Returns
- The value of
Object
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);
, and if the value of
expression1
; otherwise it returns the value of
-
An expression that evaluates to a Boolean value;
expression1
x < 5
- Values of any type.
- Values of any type.
or
expression2
expression3
expression1
expression3
.
.
to variable
x
z
is
, it returns
true
.
because
expression1
Operators
141

Advertisement

Table of Contents
loading

Table of Contents