magnhan
magnhan

Reputation: 21

AS3: Changing a TextField in a MovieClip

I want to make a button with a TextField on it, a label if you'd like, that is changeable with AS3.

I've realised that I can not do this with a SimpleButton, but through using the MovieClip's timeline and navigating that back and forth, I've managed to change the button's texture when it is hovered over and clicked. I did make three TextFields on top of the button in each frame of the timeline, but I can't find a way to change the TextField(s) permanently.

btn is the MovieClip, l1 is the TextField for frame 1.

btn.l1.text = "label"

works until I touch the button (which changes the MovieClip's frame on the timeline), and when it returns to frame 1, its label is back to nothing.

What I essentially need to know is; how do I permanently change a TextField in a MovieClip which is changing frames?

Upvotes: 2

Views: 247

Answers (2)

Aaron Beall
Aaron Beall

Reputation: 52133

If your textfield only has 1 keyframe on its layer of the timeline it will keep the text value as you change frames. But any keyframe will re-create the textfield and reset the text when that frame is reached. If you're using keyframes to change the text color or filters, you can instead put the text field in a MovieClip and use keyframes with color tint on the MovieClip (as long as each keyframe uses the same instance name for the MovieClip it will not be re-created). So you'd change the text once with something like:

btn.labelMC.textField.text = "label";

If you're using keyframes to change text font or style (anything that a MovieClip cannot do), then the only way is going to be to reset the .text after every time you change the frame:

btn.gotoAndStop(2);
btn.l1.text = "label";

You can isolate this problem using a re-usable class.

Upvotes: 2

sfxworks
sfxworks

Reputation: 1091

Are your three frames different or the same? If they're different make sure you are changing each button's text field's text as different frames will have completely new objects.

Upvotes: 1

Related Questions