views:

593

answers:

2

Hi, folks!

Easy question, that I can't quickly find an answer to online - it seems this would be in tutorials everywhere - and probably is...

I have a MovieClip that has a Dynamic TextField: let's call the instance of the field txtName. I want to set the text field on the fly for txtName, so I add a little ActionScript (3!) that does it nice and easily: txtName.text = "Foo";

Great. Now why isn't it working when I try the same thing from a parent MovieClip which contains the MovieClip that has the dynamic text? Example:

Child MovieClip with TextField ActionScript 3 in Frame #1:

//------
function SetText(str:String):void {
   txtName.text = str;
}
//------

Parent MovieClip contains the above MovieClip (instance called movieChild) has the following ActionScript 3 in Frame #1:

//------
movieChild.SetText("Hello Child"); // Doesn't work
movieChild.txtName.text = "Hello Child"; // Doesn't work
MovieClip(movieChild).txtName.text = "Blah"; // Doesn't work

What simple thing am I missing? I know the text in the TextField actually gets set by checking it with a trace, but the display doesn't actually change.

Ready for an embarrasing and humbling answer.

Eddie

+1  A: 

It might just be that your function, SetText, isn't public. Stick 'public' before 'function', and try it again, should work :)

Might be the same issue for the second line where you try to set it directly; if the variable declaration for your text field isn't public.

debu
A: 

I'm sorry folks for the dumb question. I ran into a simple mis-naming issue. There was no error thrown, and all the traces that I did seemed to be right, but nothing was changing.

The root of the problem was that I decided to throw in a "HotSpot" rollover movieClip and ended up calling it the same thing as I did the Text movieClip. Should have stared at it a little closer before posting.

I'm still not sure why though it didn't throw an error. As far as using "public", doesn't that only work when you use an external Actionscript file, ie, not actions directly attached to a timeLine?

Thanks for the input!

Eddie
Yeah, I think that's true actually. I wasn't sure if it made a difference when everything you're dealing with is on the timeline, but thought it was worth a shot. Glad you fixed it anyway :)
debu
I also have run into the duplicate name issue MANY times. It drives me nuts that such a rich environment can't tell me if I have more than one asset with a duplicate name.... You can use the scene/asset viewer in the Actions panel... but it is TEDIOUS wen have tons of items on the stage...
exoboy