-1

为什么这个开关盒不起作用......即使我在星期一选择按钮,它也会向我显示默认消息..

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");
}
4

3 回答 3

3
switch (finalsave.weekday) {
    case 1:
    trace ("monday");
    break;

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

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

    ... etc.
}
于 2013-01-29T00:29:00.847 回答
2

或者,如果您想完全放弃那个可怕的开关盒:

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

var index : int = finalsave.weekday -1;
trace( weekdays[ index ] );
于 2013-01-29T06:55:53.347 回答
1

在 case 之后,您应该提及变量的可能值,以下是 action script、c/c++、java 和 javascript 的 switch case 的语法:

使用字符串切换大小写。查看源打印?

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");
}

在这个例子中,文本“The man says hello world”被追踪。Switch Case 使用整数,很有趣。

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");
}

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

于 2013-01-29T00:35:58.867 回答