What happens to dynamically declared variables when I'm not using them?
Hello, I'm making a game using Flash Pro cc. But I wonder what happens to aTile, which is dynamically declared MovieClip variable through a loop. And each aTile gets the 2 EventListener's.
for(var i:Number=0; i<pVector.length;i++){
var aTile:ATile=new ATile();
aTile.x=pVector.x;
aTile.y=pVector.y;
aTile.gotoAndStop(Math.ceil(Math.random()*Color));
nVector.push(aTile);
Spr.addChild(aTile);
aTile.addEventListener(MouseEvent.CLICK,Clicked,false,0,true);
aTile.addEventListener(Event.COMPLETE, stop,false,0,true);
// the current function ends here. what happens to aTile now ?? Is it going to be garbage collected? By the way, this piece of code runs whenever a player starts a new level of my game. And I don't make use of the aTile variable in other functions. I use only the nVector variable. And does declaring a dynamic variable in a loop mean a multiple of them are created? For example, if I loop the piece of code above 5 times, does it mean 5 aTile variables are created? Or each time you declare
var aTile:ATile=new ATile(); again, does it replace the 'old' aTile with the 'new' aTile and therefore only 1 aTile exists after the loop????
}
