03.05.2013 Views

ActionScript 2.0 Language Reference - Adobe Help and Support

ActionScript 2.0 Language Reference - Adobe Help and Support

ActionScript 2.0 Language Reference - Adobe Help and Support

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

?: conditional operator<br />

expression1 ? expression2 : expression3<br />

Instructs Flash to evaluate expression1, <strong>and</strong> if the value of expression1 is true, it returns<br />

the value of expression2; otherwise it returns the value of expression3.<br />

Availability: <strong>ActionScript</strong> 1.0; Flash Player 4<br />

Oper<strong>and</strong>s<br />

expression1 : Object - An expression that evaluates to a Boolean value; usually a<br />

comparison expression, such as x < 5.<br />

expression2 : Object - Values of any type.<br />

expression3 : Object - Values of any type.<br />

Returns<br />

Object - The value of expression2 or expression3.<br />

Example<br />

The following statement assigns the value of variable x to variable z because expression1<br />

evaluates to true:<br />

var x:Number = 5;<br />

var y:Number = 10;<br />

var z = (x < 6) ? x: y;<br />

trace (z); // returns 5<br />

The following example shows a conditional statement written in shorth<strong>and</strong>:<br />

var timecode:String = (new Date().getHours() < 11) ? "AM" : "PM";<br />

trace(timecode);<br />

The same conditional statement could also be written in longh<strong>and</strong>, as shown in the following<br />

example:<br />

if (new Date().getHours() < 11) {<br />

var timecode:String = "AM";<br />

} else {<br />

var timecode:String = "PM";<br />

} trace(timecode);<br />

Operators 159

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!