问题描述:

why is this switch case not working... even if i pick the button monday it shows me default message..

switch (finalsave.weekday) {

case finalsave.weekday == 1:

trace ("monday");

break;

case finalsave.weekday== 2:

trace ("tuesday");

break;

case finalsave.weekday == 3:

trace ("wednesday");

break;

case finalsave.weekday == 4:

trace ("thursday");

break;

case finalsave.weekday == 5:

trace ("friday");

break;

default:

trace ("nothingness");

}

网友答案:

Or if you want to ditch that godawful switch-case altogether:

var weekdays: Array = [
    "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"
]

var index : int = finalsave.weekday -1;
trace( weekdays[ index ] );
网友答案:
switch (finalsave.weekday) {
    case 1:
    trace ("monday");
    break;

    case 2:
    trace ("tuesday");
    break;

    case 3:
    trace ("wednesday");
    break;

    ... etc.
}
网友答案:

After case, you should mention the possible value of your variable, Below is the syntax of switch case for action script, c/c++ , java and javascript:

Switch case using strings. view sourceprint?

switch("hello world")
{
case "hello":
trace("The man says hello");
break;

case "hello cat":
trace("The man says hello cat");
break;

case "hello world":
trace("The man says hello world");
break;

default:
trace("None of the above were met");
}

In this example the text "The man says hello world" is traced out. Switch Case using integers, what fun.

switch(1)
{
case 1:
trace("The Number 1");
break;

case 2:

case 3:
trace("The Number 2 or 3");
break;

default:
trace("None of the numbers above");
}

from http://www.how-to-code.com/as3-actionscript3/as3-conditionals/as3-switch-case.html

相关阅读:
Top