In the following scenario I create 5 buttons dinamically.
Doing it with a regular function this way…
create() {
for (var a=1; a<=5; a++) {
var mybutton = this.add.image(a*50, 10, '').setInteractive();
mybutton.mydata = a;
mybutton.on('pointerup', function (e) {
console.log(this.mydata);
});
}
}
… since this here refers to the objects itself I can return their own properties with this.mydata.
But what if I try to do the same thing with an arrow function this way:
create() {
for (var a=1; a<=5; a++) {
var mybutton = this.add.image(a*50, 10, '').setInteractive();
mybutton.mydata = a;
this.mybutton.on('pointerup', (e) => {
// how to return the property value??
});
}
}
How would I return the properties of the objects in that case since this here is pointing to the parent context (scene)? Or in such specific case there is not a way of doing what I want?
Thanks!