AS3 Change textfield inside movieclip added from l

2019-07-25 13:44发布

问题:

I'm trying to do the following:

I have an empty movieClip in my stage called zonaCentral_mc. I use a function that has this code:

zonaCentral_DescripcionProceso = new zonaCentral_DescripcionProceso_mc();
zonaCentral_mc.addChild(zonaCentral_DescripcionProceso);

It loads the MovieClip zonaCentral_DescripcionProceso from the library into the empty movieclip zonaCentral_mc. The loaded MC has a dynamic textfield called titulo_text inside. How can I change that text? I'm trying:

this["zonaCentral_mc"].getChildByName("zonaCentral_DescripcionProceso").getChildByName("titulo_text").text = "hello";

but I get the error: #1010: One term is not defined and has no properties

I've also tried the dot notation this["zonaCentral_mc"].zonaCentral_DescripcionProceso.titulo_text.text with the same result.

Am I accessing it the wrong way? Why isn't it defined, I believe that they're all defined and in the stage when I call the above statement.

回答1:

the MovieClip you instantiate doesn't have an instance name, that's why you can't access it through "getChildByName".

Try this:

zonaCentral_DescripcionProceso.name = "zonaCentralChildClip";
...
this["zonaCentral_mc"].getChildByName("zonaCentralChildClip").titulo_text.text = "hello";

But also, I am pretty sure you can access the text field as well:

zonaCentral_DescripcionProceso.titulo_text.text = "hello";

Please note, if you're zonaCentral_DescripcionProceso is a MovieClip, you can access the text field without the "getChildByName" method.

Cheers, Rob