0

When i access "numerText[i].text()" in function of circles[i]'s on click event handler firebug prompts error:"numberText[i] is undefined ". Actually I want to assign the text returned by calling "numerText[i].text()" to variable "score"

var score=0;
for(var i=0;i<3;i++){
//adding number text
    numberText[i]=new Kinetic.Text({
    x:circles[i].getX(),
    y:circles[i].getY(),
    text:i,
    fill:'white',
    name:'nText'
    });
  group[i].add(circles[i],numberText[i]);
  layer.add(group[i]);
 //zn click circles
 circles[i].on('click',function(){
score=numberText[i].text(); //here "numberText[i] is undefined"  error fires
scoreText.text(score);
layer.draw();
 }); 

}

Plz help me

  • possible duplicate of [How do JavaScript closures work?](http://stackoverflow.com/questions/111102/how-do-javascript-closures-work) – Jeremy J Starcher Jun 27 '14 at 17:54
  • This is a very common issue for folks new to JavaScript. You'll need to look at closures to fix your issue. The question that I linked to as a duplicate will explain it all. – Jeremy J Starcher Jun 27 '14 at 17:55

0 Answers0