joerrey Posted September 20, 2014 Share Posted September 20, 2014 Hey, I'm wondering why the key of the loop will be passed to the closure as a text object: this.skillSelection[key] The first log provides the expected string output of "key", e.g.: "Bash".But the log within the closure provides the this.skillSelection[key] object. //skillSelection this.skillSelection = {}; this.skillSelectionDistance = 20; for (var key in this.player.skills){ this.skillSelection[key] = game.add.text(this.skillSelectionDistance, 450, this.player.skills[key].name, { font: '16px Arial', fill: "#000000" }); this.skillSelection[key].inputEnabled = true; console.log(key) // "Bash" output this.skillSelection[key].events.onInputUp.add(function(key){ console.log(key) // text object ouput }, this); this.skillSelectionDistance += 60; } Link to comment Share on other sites More sharing options...
lewster32 Posted September 21, 2014 Share Posted September 21, 2014 You're overriding the value of 'key' with a parameter in the callback: "function(key) {" so 'key' is becoming whatever the onInputUp callback returns - in this case, the sprite that the input came from. joerrey 1 Link to comment Share on other sites More sharing options...
Recommended Posts