Because when you make the pointerup event on the button, you’re setting the scene as ‘this’. So what happens when you press the button, then it logs “Scene.myid”
mybutton.on("pointerup", function (e) {
console.log(this.myid);
});
just by removing the ‘this’ from the event, then it works.
Edit: You could also replace ‘this’ with ‘mybutton’, but that’d be the same as removing it.
‘this’ inside of the event, is the scope - in this case the button.
the other ‘this’ (3rd parameter), is to set the scope, so if you passed ‘this’, then you set the scope to be the scene.
tl;dr
do this.myid and dont put ‘this’ as a 3rd parameter
tl;dr;dr
mybutton.on("pointerup", function (e) {
console.log(this.myid);
});
Thenonamezz, it kind of fixed the issue but created me another one. I need the third this as parameter because it’s the only way of navigating between scenes. In fact I failed on not put the complete code before. My bad. Look that:
I don’t know if it will help some yet but I figured that if I do:
console.log(this.children.list[index].myid);
Where “index” is the value of the button in the array, it will return me the desired contents. However to do that I would need to get “index” from somewhere and I couldn’t find any identifier in this wich provides it.
A few seconds before to see your post and after to understand that the third this parameter referred to the scope of the project (I really didn’t know that, thank you very much for putting a light over that) I had the idea of replace the this with the game var (from game = new Phaser.Game(config)). So instead of: