Further to my earlier posts about identifying and manipulating clips and subclips created in a [COLOR=“blue”]for [/COLOR]loop, I’m sure I’m still not using the best methods of identifying any given clip or it’s nested subclip. The following works, but I understand that naming clips and using [COLOR=“Blue”]getChildByName[/COLOR] are not best practice.
However it seems to me that using [COLOR=“blue”]getChildAt[/COLOR] could be cumbersome to keep track of, particularly if clips were to be added, removed or swapped during the course of the program.
I expected that clipArray[2].weeBox would have been sufficient to target that subClip in the object referenced in the third slot in that array, but that’s clearly not the case. Is this it, or is there a better approach?
var clipArray:Array = new Array();
var home:MovieClip=this;
for (var i:Number = 0; i < 4; i++) {
var myBox:MovieClip = new MovieClip();
myBox.name="myBox_"+i;
var box:MovieClip = new Box();
myBox.addChild(box);
myBox.x=100;
myBox.y = 50+(i*90);
var weeBox = new Box();
weeBox.name="weeBox"+i;
weeBox.height=weeBox.height/2;
weeBox.width=weeBox.width/2;
myBox.addChild(weeBox);
myBox.addEventListener(MouseEvent.MOUSE_OVER, whoAmI, false, 0, true);
clipArray.push(myBox);
addChild(myBox);
}
function whoAmI(evt:MouseEvent):void {
var mcName:String=evt.target.parent.name;
var mcNo:Number=Number(mcName.substr(6,1));
home.clipArray[mcNo].getChildByName("weeBox"+mcNo).x+=10;
}