0

hy, i have a piece of code using easeljs library , i want to make a letter that change when it clicked , but i'm have a problem to get a local variable ,or the event not change the variable anymore

i have tried to make a code like this,

function start(){
    var letter=["A","B","C"];//only example
    i=0; console.log(i);
    var change=new quote(letter[i]);//i made a class with display the text and quote grapichs vector
    change.addEventListener("click",function(A){
                  i++;console.log(i)//it change});
    stage.addChild(change);
}

but when i click the text not change, and the i value not change too

1 Answers1

0

The variable passed into the "quote" object will not be passed by reference, so updating it might update the "i" value in the function, but it won't change the value passed into the quote. Primitives (boolean, string, number) are not passed by reference.

Instead, maintain a reference to the quote object, and expose an API to set the value in the function callback.

Lanny
  • 11,244
  • 1
  • 22
  • 30
  • i still dont understand , i'm noob in javascript yesterday i have realize about variable is much rule in javascript this is my quote class how can i fix it ? [link](http://dl.dropbox.com/s/9ngo64m269dkfmq/class.js)[/link] – user3128435 Dec 24 '13 at 02:04