PDA

View Full Version : addChild and instance name



grinfax
October 16th, 2008, 07:08 PM
Hi,
I am trying to dynamically add a child to stage, this works. Then I try to access it using the instance name and I can’t. Why can’t I do this?




intro_btn.addEventListener(MouseEvent.CLICK, goIntro);

function goIntro(EVENT){
var intro:MovieClip;
intro = new Intro();
intro.name = "scr";
targetX_mc.addChild(intro);
targetX_mc.scr.sb.init(targetX_mc.scr.txt_mc, "easeOutBack",2,true,2);
}


Thank you,
Kim

mattkenefick
October 17th, 2008, 12:21 AM
Hi,
I am trying to dynamically add a child to stage, this works. Then I try to access it using the instance name and I can’t. Why can’t I do this?




intro_btn.addEventListener(MouseEvent.CLICK, goIntro);

function goIntro(EVENT){
var intro:MovieClip;
intro = new Intro();
intro.name = "scr";
targetX_mc.addChild(intro);
targetX_mc.scr.sb.init(targetX_mc.scr.txt_mc, "easeOutBack",2,true,2);
}


Thank you,
Kim

You can't access directly by name anymore. You have to use getDefinitionByName('scr')

grinfax
October 17th, 2008, 01:12 AM
This is still not working...


parent.getChildByName("scr") seems to work, but how do I drill one level deeper?





function goIntro(EVENT){
var intro:MovieClip;
intro = new txt();
intro.name = "scr";
addChild(intro);
parent.getChildByName("scr").sb.init(parent.getChildByName("scr").txt_mc, "easeOutBack",2,true,2);

}



Thank you,
Kim