我正在为游戏制作排行榜。此排行榜从数组中获取分数。但是当我添加 eventListener 时,我只从数组中得到一个对象。这是我的对象数组:
[{gamenr:1,naam:"wilbert", score:60},{gamenr:1,naam:"joost", score:20},
{gamenr:2,naam:"harry", score:50},{gamenr:2,naam:"john", score:10},
{gamenr:3,naam:"carl", score:30},{gamenr:3,naam:"dj", score:16}]
代码:
public function toonHighscoreArray():Array {
highScoreTabel.sortOn(["score"], [Array.NUMERIC]).reverse();//get highest score on top
var returnArray:Array = new Array();
for ( var i:int = 0; i < 6; i++ ) {
var scores:TextField = new TextField();
scores.addEventListener(MouseEvent.CLICK, function(e:MouseEvent){toon2deSpeler(highScoreTabel[i])});
scores.y = (i * 50) - 50;
scores.height = 50;
scores.text = "" + (i + 1) + ".\t" + highScoreTabel[i].naam + " met " + highScoreTabel[i].score + " punten.";
scores.autoSize = "left";
returnArray.push(scores);
}
return returnArray;
}
private function toon2deSpeler(score:Object) {
trace(score.naam);
}
我希望函数 toon2deSpeler 在单击 wilbert 在文本字段中的文本字段时跟踪 wilbert 并在单击 harry 的文本字段时跟踪 harry
但是当我点击 wilbert 时它给了我 joost,当我点击 harry 或 joost 等时它也给了我 joost。
如何在 toon2deSpeler 中获取正确的对象作为参数?