0
votes

I am trying to create a button using Actionscript. The only class which I found relevant was SimpleButton. When I had tried to insert a text field earlier, I found it was very simple and straighforward in that, I just created a text field, and added text to it. It got rendered fine.

However, when I tried to do something similar, I found that it wasn't getting rendered. I referred to the help document on the Adobe Site and pasted their sample code as a standalone file. It worked fine. However, the button was just coloured. I wanted to add some text on it - so I used the text field and overlaid it. Which looks fine. But now when I bring the mouse close to the text, the button's hover no longer works, nor does the click - This I believe is because of the text being over the button.

To summarise, how do I create a clickable button with text using Actionscript without problems?

2

2 Answers

2
votes

On your Textfield you can set a property:

myTextfield.mouseEnabled = false;

That way your textfield won't be preventing you from clicking.

1
votes

If you want to use graphic interface to create button(s) do the following:

  1. Open Components window and expand User interface section.
  2. You will find a Button component there
  3. Drag it to your stage
  4. Change the label, you can also change the 'skin'
  5. Enjoy

SimpleButton is an Actionscript class meant to facilitate programmatic creation of the buttons. If you find it more suitable for your needs just remember to set the overlaying text field to ignore the mouse events:

textField.mouseEnabled = false;