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 ch开发者_如何转开发ecking it with a trace, but the display doesn't actually change.
Ready for an embarrasing and humbling answer.
Eddie
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.
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!
精彩评论