AS3中的switch case语句与XML无法正常工作

时间:2012-03-06 03:34:41

标签: xml actionscript-3 switch-statement

我正在制作一个switch case语句,它遍历我的XML文件中的季节标记,考虑到我的一个trace语句打印出4个季节中的1个,这个工作正常。但案件总是违约。但我不明白为什么。这个switch case stmnt在for循环中。

switch(seasonOn.season){
                case "spring":
                    springList.push(seasonOn.place);
                    break;
                case "summer":
                    summerList.push(seasonOn.place);
                    break;
                case "autumn":
                    autumnList.push(seasonOn.place);
                    break;
                case "winter":
                    winterList.push(seasonOn.place);
                    break;
                default:
                    trace("none of the above");
            }/*trace(seasonOn.season);
            trace(winterList.length);*/

1 个答案:

答案 0 :(得分:1)

工作得很好......

var seasonData:String = "<data><season>spring</season></data>"

var seasonOn = new XML(seasonData);

var currentSeason:String = seasonOn.season;

var springList:Array = [];
var summerList:Array = [];
var autumnList:Array = [];
var winterList:Array = [];

switch(currentSeason){
case "spring":
    springList.push(seasonOn.place);
    trace("spring");
break;

case "summer":
summerList.push(seasonOn.place);
    trace("summer");
break;

case "autumn":
    autumnList.push(seasonOn.place);
    trace("autumn");
break;

case "winter":
    winterList.push(seasonOn.place);
    trace("winter");
break;

default:
    trace("none of the above");
}