|Text in Buttons|
I'm primarliy an ASPX developer, but I'm trying to learn a little flash. I've struck a problem, and was wondering if anyone could help!?
I have created a flash movie, and a button symbol. There is a text area in my button which I want to be able to change to say something different for each instance of the button.
I tried to do this by changing the text field in the button symbol to Dynamic Text and assigning it an instance name.
Then, from the action for a frame in the main timeline, I tried something like this...
this.ButtonInstance1.TextInstance.text = "This is a test";
... but this does nothing.
This seems like a really simple thing to want to do - anyone got any pointers on how to change the text for each instance of my button symbol?
If your text properties of the button (color, weight, etc.) aren't going to change when the button is rolled over or clicked, I would suggest just making the actual button, and NOT the text, the actual button symbol. Then in the movie frames you can just use the text tool to place the different text phrases over the various instances of the symbol.
That's the easiest way I can think to do it, short of having to create a different button symbol for each button.
Thanks for the suggestion, but I only want the text to appear in the over state of the button.
I can't believe that something as simple as this is so complicated! What's the point in creating a 'button' symbol, if every one has to look identical?
Actually, I suppose the fact that they look the same is exactly the point!
But you should at least be able to change the text on the buttons?! How far would user interface designers get if every dialog box could have buttons, but they all had to say the same thing!
"Would you like to delete this file? Click YES or YES to continue."
... anyway - this has turned into a rant! Any other ideas?!
You could try using actionscript to change the text of the button. Add a dynamic text box on the button and then just add a script on each button to display different text...
PizdusInc, read the first post ......
Balloon - your AS looks ok, but as your are putting it on the main timeline it maybe the reference to 'this' that is causing the problem.
_root.ButtonInstance1.TextInstance.text = "This is a test";
I do something like this with buttons in a flash animation I have.
I define the text in my button dynamic text and give it the variable lvlmenu0text
I put an action in the frame (still in the button_)that says
lvlmenu0text = lglmenu0text;
then.. in the instances of the button in my main movie .. I set the variable that's to be displayed.. as an action in the keyframe as:
lilmenu01.lglmenu0text = "some button text here";
lilmenu02.lglmenu0text = "more darn text";
where lilmenu01, lilmenu02 etc.. is the name of the instance of the button.
there are probably easier ways of doing it - but this seems to work for me.. oh.. and I think my button is actually defined as a movie clip - but I'm not sure if this matters..
hope this has helped
Stratus hit the nail on the head. You can not place text inside a button symbol and have it display dynamic text.It doesnt work. 99.9% of all flashers I know, including myself, build a movieClip with a button inside that. Inside the movieClip is where you put your dynamic text.
So, the AS would be:
The button AS would be:
//whatever action you want to happen