Conqarous Posted March 21, 2015 Share Posted March 21, 2015 Hey guys, How can I get the 'index' attribute from a class to use it in a for loop? new stars are pushed into starsList = [];'p_id' here is compared to the 'index' value in starsList starsList.star.id or starsList.id do not work, what is the correct way? I'm a total newbie. Thanks in advance! function (p_id) { for (i = 0; i < starsList.length; i++) { if (p_id == starsList.star.id) { starsList.y = starsList.y - 10; break; } } } And here is the class: Star = function (index, game) { var x = 50; var y = 50; this.game = game; this.star = game.add.sprite(x, y, 'star', 'star1'); this.star.id = index; }; Link to comment Share on other sites More sharing options...
Recommended Posts