我目前正在制作一张高分表,其中一张高分表用于拼写测验。
我有一个名为 的本地文件highscores.xml
,如下所示:
<highscores>
<spelling>
<first>0</first>
<second>0</second>
<third>0</third>
<fourth>0</fourth>
<fifth>0</fifth>
</spelling>
</highscores>
这是加载highscores.xml
文件后运行的 AS3 函数:
function highScoresLoaded(e:Event)
{
highScoresXML = new XML(urlLoader.data);
highScoresArray = new Array();
highScoresArray.push(highScoresXML.spelling.first);
highScoresArray.push(highScoresXML.spelling.second);
highScoresArray.push(highScoresXML.spelling.third);
highScoresArray.push(highScoresXML.spelling.fourth);
highScoresArray.push(highScoresXML.spelling.fifth);
highScoresArray.push(points);
highScoresArray = highScoresArray.sort(Array.DESCENDING);
highScoresArray.pop();
firstScoreTXT.text = highScoresArray[0];
secondScoreTXT.text = highScoresArray[1];
thirdScoreTXT.text = highScoresArray[2];
fourthScoreTXT.text = highScoresArray[3];
fifthScoreTXT.text = highScoresArray[4];
highScoresXML.spelling.first = highScoresArray[0];
highScoresXML.spelling.second = highScoresArray[1];
highScoresXML.spelling.third = highScoresArray[2];
highScoresXML.spelling.fourth = highScoresArray[3];
highScoresXML.spelling.fifth = highScoresArray[4];
trace(highScoresXML);
}
但是函数末尾的跟踪输出是这样的(我刚刚在测验中得了 4250):
<highscores>
<spelling>
<first>4250</first>
<second>0</second>
<third>0</third>
<first>4250</first>
<fifth>0</fifth>
</spelling>
</highscores>
当我删除这一行时,它工作正常:
highScoresXML.spelling.fourth = highScoresArray[3];
我不擅长编程,似乎无法弄清楚。
任何帮助,将不胜感激!