AdenForshaw.com Behind the curtain of Affiliate Marketing

28Jan/0944

AS3 TextField buttonMode or useHandCursor?

Unfortunatly, no method exits on the TextField class in AS3 as it does not extend the Sprite class, which contains the buttonMode property.

This is most apparent with the annoying problem of having a TextField inside your Sprite/MovieClip you;re trying to use as a button, where even after setting buttonMode = true on the button, rolling over the textfield inside the button will revert the Cursor back to default.

To get round this simply use the mouseChildren = false property on your Sprite/Movieclip button.

i.e.

myTextFieldContainingSprite.buttonMode = true;

myTextFieldContainingSprite.mouseChildren = false;

myTextFieldContainingSprite.addEventListener(MouseEvent.MOUSE_DOWN ...... etc

Comments (44) Trackbacks (2)
  1. hey thanks this is awesome!!

  2. Thanks for the tip. Worked like a charm and cured some headaches :)

    Cheers

  3. Thanks you just saved my day!

  4. You saved my day, thanks :)

  5. god bless you brother!

  6. Most useful! Thank you!

  7. Doesn’t the following shorter thing, also work?
    myTextField.mouseEnabled=false;
    :-)

  8. This worked great when “mouseEnabled = false” on my textField did not. Thanks!

    You might run into problems if you have the class add both the graphic for the button and the text field. In that case, you have to do some restructuring by having the button class have a subclass that sets “mouseChildren = false” and then creates the textField.

  9. Absolutely wiseful.
    Thanks a lot.

  10. Thanks a lot dude :)

  11. thank you:)

  12. That’s sweet!
    Work like a charm!

    thanks!

  13. thanks! this is exactly what i was looking for.

  14. Thanks for this tip. My custom buttons final behave like buttons should.

  15. Thanks a billion, this belongs in a sticky somewhere.

  16. Thank you so much for this info, it helped me alot. How frustrating it was!! :)

  17. that was a hard to find tip but it is precious, thank you man

  18. just plain great

  19. Merci beaucoup !

  20. Great, just what I needed!
    thnx!
    Regards
    Eric

  21. You saved my life!!!

  22. “just saved my day” number 4276993775

  23. Excelent!!!
    Thanks for your help y very cool :)

  24. This saved my bacon! Thanks

  25. thank you very much!!!
    it’s exactly what I was looking for!

  26. Tanks a lot !!!!

    Save me hours of search in the Web ;)

  27. Thanks, you saved my day!

  28. Tanks a lot from Brazil! You save the day!

    Cheers!

  29. That’s a good one. Thanks

  30. Aweeeeeeeeeesome! Thx

  31. Thanks! quick and effective!

  32. Use Listeners for mouse over and mouse out and switch the cursor with Mouse.cursor = MouseCursor.BUTTON;

    It’s simpler!

  33. Thanks Dude! Saved my day too :)

    peace..

  34. I have both

    public var mRowNo:TextField = new TextField();

    mRowNo.mouseEnabled = false;

    mShape.addChild(mRowNo);

    mShape.mouseChildren = false;

    and my cursor doesnt change but I cant point at the shape properly, the cursor is off, it reacts to the shape next to it. as soon as I take the textfield off it works properly. Any ideas ?

  35. Thanks for mouseEnabled=false (@ e-builds) and mouseChildren=false.
    Simple but useful and makes frustrated :D

  36. There’s an easier way to do this with the TextFormat class:

    var fmt:TextFormat = new TextFormat();
    fmt.url = ‘asfunction:’;
    var text:TextField = new TextField();
    text.defaultTextFormat = fmt;

    The only drawback is that the hand is shown only when the cursor’s over the TEXT. So if your TextField’s size is bigger than the actual text in it the hand cursor will not be shown on the part of the TextField with no text.

  37. e-builds: your method works for me! The author’s does not…
    It could be because I don’t have an mc with a textfield inside, but I rather have a textfield that I have added to the stage.

    Thanks!

  38. Thanks! helped me allot!!!


Leave a comment

(required)