Hello,
I want to set the unique variables for each cloned entities.
But, the variable is copyed to all of cloned entities.
How can I set the unique variables for each cloned entity?
i.e.
ROOT’s main.js
for(var i=0; i<100; i++){
var e = ENTITY.clone();
e.script.JS.setNum(i);
aPooledENTITY.push(e);
app.root.addChild(e);
}
console.log('aPooledENTITY[13]:myNum:'+aPooledENTITY[13].script.JS.checkNum()+', aPooledENTITY[14]:myNum:'+aPooledENTITY[14].script.JS.checkNum());
aPooledENTITY[13].script.JS.setNum(0);//set 0 to 13 in aPooledENTITY.
console.log('aPooledENTITY[13]:myNum:'+aPooledENTITY[13].script.JS.checkNum()+', aPooledENTITY[14]:myNum:'+aPooledENTITY[14].script.JS.checkNum());
ENTITY’s JS.js
ENTITY.prototype = {
initialize: function () {
var self = this;
var myNum;
},
setNum: function(NUM){
myNum =NUM;
},
checkNum: function(){
return myNum;
},
-> result
aPooledENTITY[13]:myNum:99, aPooledENTITY[14]:myNum:99
aPooledENTITY[13]:myNum:0, aPooledENTITY[14]:myNum:0
->my demand
aPooledENTITY[13]:myNum:13, aPooledENTITY[14]:myNum:14
aPooledENTITY[13]:myNum:0, aPooledENTITY[14]:myNum:14
Thanks.