我正在製作遊戲的排行榜。該排行榜從數組中獲得分數。但是當我添加eventListener時,我只能從數組中獲得一個對象。 這是我的對象數組:for循環中的addEventListener(object [i])給我一個對象不是多個
[{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跟蹤威爾伯特當我點擊文本框,其中威爾伯特是在文本字段被點擊和哈里當哈利的文本框是點擊
但它給了我joost當我點擊威爾伯特,但也當我點擊哈利或joost等。
我如何在toon2deSpeler中獲取正確的對象作爲參數?
非常感謝 – 2013-03-16 16:01:15