Make buttonMode enabled dynamic text fields with AS3

January 4th, 2010

This is a little niggling problem that I find myself rediscovering every now and then when working with dynamic text – particularly dynamic text as part of an interface. When you have a movieclip with buttonMode set to true, you expect the cursor to change to a pointing hand whenever it is over any part of the movieclip, as in this example:

Mousing over the button gives you a hand cursor, updates the button to it’s ‘over’ state, and changes the text at the top, all as expected. The problems arise when using a dynamic text field to label the button, like this:

Mousing over the button still changes it’s state and alters the text, and to a certain extent changes the cursor. However, when you move the cursor over the text field it goes back to a regular arrow, despite the fact that flash can clearly tell it’s still over the button, as evidenced by the ‘over’ state of the button, and the top text field.

So how do you fix this problem? One method I see suggested is setting ‘mouseChildren’ to false on the button movieClip. This will fix the problem, and it will do it for any and all dynamic text fields within the button movieClip at once. The problem with this method is that sometimes, you want the mouse to be enabled on some of the children, just not this one in particular. In these cases, a more precise approach is to simply set:

button.textfield.mouseEnabled = false;

And there you have it, a buttonMode enabled dynamic text field.

4 Responses to “Make buttonMode enabled dynamic text fields with AS3”

  1. Emmanuel says:

    Cheers Ed!

    I was having the same problem. A dynamic text field in a button movieclip. This fixes the problem beautifully!

  2. EddyB says:

    You’re welcome! Glad I could help.

  3. josh says:

    Perfect! I routinely forget this little line. Well put with the examples…

  4. jaime says:

    same here….many thanks.

Leave a Reply