Loading vars into text->button

OK I have defined a variable say

test="what should I do?"

then I have a textfield with var name “test”. Now when I play the movie it will display “what should I do?” in the textfield, but what if I put the textfield inside a button? It won’t show! How do I change the actionscript so that it doesn’t think that the field is in _.root??

I tried this:

button1.test="what should I do?"

where button1 is the instance name of the button!
But this won’t work!

Please show me how to do it and give me a brief explanation so that I understand the code! :rambo:

buttons are not movieclips. Buttons are… buttons. They do not behave like movieclips nor are they supposed to. MX introduced the button to us as an object giving it many similar qualities to that of a movieclip, but it does not behave the same way. Buttons are actually very stubborn in their behavior and do not maintain instances (instance names) within themselves. So, if you were to have a movieclip within a button and it has the instance name “bob” you would not be able to reference that movieclip using buttonName.bob The button actually strips the instance names off of movieclips (and textfields) and reduses them to the default “instance1”, “instance2” etc. However, you cant just make an educated guess and assume that “Well thats the only instance I have in the button so I can reference it using ‘instance1’” because for each keyframe or change in button imagery/state, when that instance is re-displayed it is given a new instance name with the appended number incremented to reflect the newly created (displayed) symbol.

So what to do? Well there was a thread earlier where I covered this, but Im too lazy to find it so Ill just spit out the juice :wink: What youd need to do, or rather something you CAN do, is put your textField in a movieclip and place that movieClip in the button. Then in the first frame of that movieclip do something like.

_root.buttonTextClip = this; // or even the TextField itself

This will set a variable in _root called buttonTextClip which references that movieclip directly without the need to go through the button. Then, to get at that textField, you just do something like

_root.buttonTextClip.myTextField.text = “whatever”;

BUT you have to be aware that, as I mentioned before, at each point where that movieclip is removed from a button state, then recreated, you will have to re-assign that text because it more or less is a new clip thats being created to replace the old. In that case you might want to use that frame in the movieclip to actually assign the text instead of setting the variable in _root

myTextField.text = “whatever”; // or some other variable somewhere

Thanks for the explanation senocular! Didn’t think it was that complicated!:hangover:

Ok I got it working but I’m unsure what you mean by:

_root.buttonTextClip = this; // or even the TextField itself

Is this correct on the first frame of the movie clip I put this:

_root.buttonTextClip=TextField.text

Then I refer to the text field by:

Textfield.text

??:crazy:

Senocular??(-: