PDA

View Full Version : Accessing clips inside clips of dynamically generated clips


wolcotter
01-15-2009, 10:12 PM
Make sense? :)

So here's the code I'm working with. For loop generates clips containing clips. I need to access a specific clip (look_back) within the parent clip generated by the loop. Not sure how to do this.

Thanks // help appreciated

var spacing1:Number = 10;
var lookA:Array = new Array();
function buildLooks(lookNum:Number) {
var looks:MovieClip = new MovieClip();
addChild(looks);
looks.x = 644;
looks.y = 64;
////////////////////
for (var i:Number = 0; i < 4; i++) {
var look:MovieClip = new Lookmc();
look.y = i*(look.height + spacing1);
look.name = "look"+i;
looks.addChild(look);
lookA.push(look);

lookA[i].look_title_txt.text = externalXML.look[lookNum].product[i].titles;
lookA[i].look_copy_txt.text = externalXML.look[lookNum].product[i].copy;

var url:String = externalXML.look[lookNum].product[i].image;
var urlReq:URLRequest = new URLRequest(url);
var lookImg:Loader = new Loader();
lookImg.load(urlReq);
lookA[i].addChild(lookImg);

var proLink:String = externalXML.look[lookNum].product[i].link;
var request:URLRequest = new URLRequest(proLink);

lookA[i].addEventListener(MouseEvent.MOUSE_OVER, onBtn0_Over);
lookA[i].addEventListener(MouseEvent.MOUSE_OUT, onBtn0_Out);
lookA[i].addEventListener(MouseEvent.CLICK, onBtn0_Click);

}

}
var activeBtn:MovieClip;
function onBtn0_Over(evt:MouseEvent):void {
trace(evt.target);
evt.target.look_back.alpha =0; // failed attempt
}

function onBtn0_Out(evt:MouseEvent):void {
evt.target.look_back.alpha =0; // failed attempt
}

function onBtn0_Click(evt:MouseEvent):void {
navigateToURL(request, "_self");
}

rawmantick
01-16-2009, 06:06 AM
If you have a sub-movieclip of some mc as a class field (like the first one is a private/protected/public variable of the second), then you access it like this:

containerMovieClip.subMovieClip;

If you have the child movie clip as a child (dynamically added with addChild()/addChildAt() methods), you can only access that by its name:

containerMovieClip.getChildByName("blueCircle_01");

In the last case you should obviously have a string name assigned to your sub-movieclip:

var clip:MovieClip = new SomeMovieClipClass();
clip.name = "blueCircle_01";
containerMovieClip.addChild(clip);
//
containerMovieClip.getChildByname("blueCircle_01") // is your dynamically added clip

Don't mix two things: variable name and movie clip's name property's value.