Skip to main content
May 20, 2011
Question

Buttons and text

  • May 20, 2011
  • 2 replies
  • 1157 views

Hello!

Can anyone explain me how to make my own button with a text label on it?

I've done the following:

created the button background and added the TextField on it called txt and packed it all to Button called MyButton. I added an instance of MyButton called btn to a stage and wrote in the main class: trace(btn.txt.text); - everything was fine. But when I added states of the button (Up, Down, Over and Hit) the txt field of buttons became null. But why?

This topic has been closed for replies.

2 replies

May 24, 2011

Thanks a lot to both of you guys! You really helped me very much! )

relaxatraja
Inspiring
May 20, 2011

You can't able to access textfield from the button for all events, Make it as a movieclip and make three frames for your up, over, down events and give stop command over there, for hit, make a button just with the hit on top layer within that movieclip, seperate the textbox in a single layer and expand it to the end of down event.

Often developers like to create products that can easily be used in a variety of languages. It is a relatively simple exercise to create an xml of strings and update dynamic text fields with the different language text. However, if youare using the “Simple Button” object, you will not be able to access and edit dynamic text fields inside simple buttons. Make sure to plan ahead and create your own MovieClip button object and associated class to handle roll-overs and click events

May 20, 2011

Thanks a lot for replying! )

OK

relaxatraja wrote:

You can't able to access textfield from the button for all events

But why? Can you explain it a little bit, please? ) And as it seems to me I don't get one important thing: for example, I have two frames both with a TextField on it with the same names - are they the same or are they different? how to get access to each one?

Is there a way to create a single MyButton class in the library and a variety of instances of that class on the stage but with the different values of TextField?

P.S. sorry for my English )

relaxatraja
Inspiring
May 20, 2011

simpleButton is not a display object container, so you can't target nested objects with actionscript. thatz the way adobe structured.