I want to use a function inside a loop and here is my code:
for (var i =a ; i < a+s; i++){
this.mat[i].color.setHex(0xffffff)
this.mat[b].color.setHex(0xffffff)
this.domEvents.addEventListener(this.cases[i], 'click', function(event){
this.tween = new TWEEN.Tween(pions.position)
.to({ x: cases[i].position.x, y: cases[i].position.y, z: 5}, 10000)
.start();
}, false)
this.domEvents.addEventListener(this.cases[b], 'click', function(event){
this.tween = new TWEEN.Tween(pions.position)
.to({ x: cases[b].position.x, y: cases[b].position.y, z: 5}, 10000)
.start();
}, false)
b--
}
My problem is that in the function of the addEventListener
in case[i].position
. I want to use the i
from the this.cases[**i**]
, not the i
from the loop.