AS3 If statement syntax shortcut
November 11, 2008 by jared
var v : Boolean = true;
var i : int;
v ? i = 0 : i = 1;
Is the same as
var v : Boolean = true;
var i : int;
if (v)
i = 0;
else
i = 1;
November 11, 2008 by jared
var v : Boolean = true;
var i : int;
v ? i = 0 : i = 1;
Is the same as
var v : Boolean = true;
var i : int;
if (v)
i = 0;
else
i = 1;
7 Responses to “AS3 If statement syntax shortcut”
Feel free to leave a comment...
and oh, if you want a pic to show with your comment, go get a gravatar!
You wouldn’t believe this! Just yesterday I was looking for this
and you can do this too:
i = v ? 0: 1;
also try this:
v ? [ trace( "this" ), trace( " is true" ) ] : [ trace( "DOH!" ) ] ;
or how about:
var v = false;
var a = [ c, d ];
var b = [ d, c ];
v ? a.forEach(e) : b.forEach(e);
function c():void{ trace( “c” ) }
function d():void{ trace( “d” ) }
function e(…args):void{ args[0]() }
some more random stuff:
var v = “testing”;
v is String ? [ c(), d()] : [ d(), c() ];
function c():void{ trace( “c” ) }
function d():void{ trace( “d” ) }
very nice.
if statement