Flash: How to get a variable from Array Collection

37 views Asked by At

How would I get a variable stored in a Array Collection so I can compare it to what score the player gets in the game?

highScores is an Array collection:

        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

There are 1 answers

0
Yasuyuki  Uno On

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;