Flash AS3: Switch/Case
// call switchCase(), pass in one number to execute a set of
// other functions or lines of code based on that number.
// limited error detection
function switchCase(num:Number=NaN) {
var num:Number=num;
if (isNaN(num)) {
throw new Error(â€no value definedâ€);
}
switch (num){
case 1:
trace(“#1”);
// someFunctionToCall();
break;
case 2:
trace(“#2”);
// someFunctionToCall();
break;
case 3:
trace(“#3”);
// someFunctionToCall();
// someFunctionToCall();
break;
}
}
This post is tagged: actionscript, code, flash