Flash:如何从Array Collection中获取变量

时间:2015-06-18 08:33:31

标签: flash mxml arraycollection

我如何获得存储在Array Collection中的变量,以便将其与玩家在游戏中获得的分数进行比较?

highScores是一个数组集合:

        if (highScores.length < 10 || (get score from 9th set of values Array collection) < playerscore){
            highScores.addItem({Name: playerName, Type: gameType, Score: playerscore});
            highScores.sort(orderScores);
            highScores.pop()
            externalScores.data.highScore = highScores;
        }

1 个答案:

答案 0 :(得分:0)

You can get it by

highscore[index].Score

So the code what you want is maybe like this.

var orderScores:Sort = new Sort();
orderScores.fields = [new SortField("Score", true, true)]; // index=0 is highest score

highScores.addItem({Name: "John", Type: "some game", Score: 100});
highScores.sort = orderScores;
highScores.refresh();

// For keeping TOP10 scores, delete 11th score if the length is over 10.
if (highScores.length == 11){
    highScores.removeItemAt(highScores.length-1);
}

highestScore = highScores[0].Score;