Conditional Switch Statements in AS3
This is something I wasn’t aware that you could do in a switch/case statement until recently. A lot of times developers will handle this with nested if/else statements.
For Example:
var myNum:Number = 7;
switch (true)
{
case (myNum < 5):
trace ("< 5")
break;
case (myNum > 5):
trace ("> 5")
break;
}
Using switch (true)/switch (false) is pretty cool. You can use it for any sort of true/false comparisons, including comparing strings. The first one to evaluate true will trip the statement.
Hey, that’s pretty cool! It’s just too bad switch is so slow: http://jacksondunstan.com/articles/793
True it is really slow so I would not use it in anything too performance intensive. I have made a number of small apps or widgets in the past where this would have been handy… :$ Thanks for the link!