Duplicating Children with For Loop But Need each object to have a Unique Name
I'm duplicating a sprite with this for loop and placing them sequentially on the stage. However they all seem to have the same name.
Any help on how to get them to be have unique "instance" names so I can access them individually or populate them with unique content?
public function galleryItem():void{
for (var i:uint=1; i<=5; i++) {
thumbBox.name = "thumbBox"+i;
thumbBox.graphics.beginFill(gBgColor, 1);
thumbBox.graphics.drawRect((gPosX+gWidth)*i, gPosY, gWidth, gHeight);
thumbBox.graphics.endFill();
thumbBox.alpha = .5;
thumbBox.buttonMode = true;
trace("ThumBoxNum: "+thumbBox.name);
addChild(thumbBox);
}
thumbBox.addEventListener(MouseEvent.CLICK,countIt );
}
public function countIt(event:MouseEvent):void{
trace("Clicked: "+thumbBox.name);
}
}
So, when I trace before the addChild I get: ThumBoxNum: thumbBox1 | thumbBox2 | etc...
when I trace it in the countIt function I get: Clicked: thumbBox5 for each object on the stage.
And if this is possible it would be ideal to set up a single event listener for each:
thumbBox[i].addEventListener(MouseEvent.CLICK,countIt);
Obviously I'm new to AS3 and trying to make the switch, have mercy :).
thanks