views:

33

answers:

2

I can't trace whats inside holderMC, and its content. What's wrong here?

  instance.text="something"
   holderMC.addChild(instance)
   anArray.push(holderMC)
   addChild(holderMC)

   trace(anArray[anArray.length-1].instance.text);

returned undefined.

+2  A: 

try

instance.text="something"
instance.name = "instance"
holderMC.addChild(instance)
anArray.push(holderMC)
addChild(holderMC)

trace(anArray[anArray.length-1].getChildByName("instance").text);
mga
yes or:trace(anArray[anArray.length-1].getChildAt(0).text); //will be 0 if its the only other object
Allan
manage to target it but can't trace out what's his text
Hwang
should be my side problem cause the text is define from somewhere else. but this helps too. thanx!
Hwang
A: 

This should definitely work:

instance.text="something";
holderMC.addChild(instance);
anArray.push(holderMC);
addChild(holderMC);

trace("instance.text: " + instance.text);
trace("holderMC.instance: " + holderMC.getChildAt(holderMC.numChildren - 1));
trace("holderMC.instance.text : " + (holderMC.getChildAt(holderMC.numChildren - 1)as TextField).text);

You need to cast the Child to TextField, because it getChild... returns a DisplayObject.

This is all assuming that instance is a TextField or another component with a text property.

Lieven Cardoen