为什么这个开关盒不起作用?

时间:2013-01-29 00:27:24

标签: actionscript-3 switch-statement

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

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

3 个答案:

答案 0 :(得分:3)

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

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

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

    ... etc.
}

答案 1 :(得分:1)

在案例之后,你应该提到变量的可能值, 下面是动作脚本切换案例的语法,c / c ++,java和javascript:

使用字符串切换案例。 查看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");
}

在这个例子中,文字“男人说你好世界”被追溯到了。 切换案例使用整数,有趣。

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

答案 2 :(得分:1)

或者如果你想完全抛弃那个神奇的转换案例:

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

var index : int = finalsave.weekday -1;
trace( weekdays[ index ] );