我目前正在制作一个高分表,其中一个高分表是用于拼写测验的。
我有一个名为highscores.xml的本地文件,如下所示:
<highscores>
<spelling>
<first>0</first>
<second>0</second>
<third>0</third>
<fourth>0</fourth>
<fifth>0</fifth>
</spelling>
</highscores>这是AS3函数,在加载highscores.xml文件之后运行:
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];我不太擅长编程,似乎也搞不懂。
任何帮助都将不胜感激!
发布于 2013-09-14 14:05:49
也许这就是你所需要的:
var highScoresXML:XML =<highscores>
<spelling>
<first>0</first>
<second>0</second>
<third>0</third>
<fourth>0</fourth>
<fifth>0</fifth>
</spelling>
</highscores>;
var highScoresArray:Array = new Array();
var highScoresNamesArray:Array = new Array();
for (var i:uint = 0; i<highScoresXML.spelling.children().length(); i++){
highScoresArray.push(highScoresXML.spelling.children()[i]);
highScoresNamesArray.push(highScoresXML.spelling.children()[i].name() );
}
highScoresArray.push(100);
highScoresArray = highScoresArray.sort(Array.DESCENDING);
highScoresArray.pop();
highScoresXML.spelling = new XML();
for(i=0; i<highScoresNamesArray.length;i++)
highScoresXML.spelling.appendChild("<"+highScoresNamesArray[i]+">"
+highScoresArray[i]
+"</"+highScoresNamesArray[i]+">");https://stackoverflow.com/questions/18801944
复制相似问题