开发者

Fail to target a instance inside a MC in an Array

I can't trace whats inside holderMC, and its content. What's wrong h开发者_运维问答ere?

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

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

returned undefined.


try

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

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜