Non-Selectable TextArea for Flex 2

Bloke on the Flexcoders list needed a TextArea that wasn’t selectable. Editable didn’t work because you could still select text, and it showed the i beam cursor. Enabled didn’t work because it colored the text the wrong way, and forced him to use custom styling (or CSS selectors). TextArea doesn’t have a selectable property, and since it extends Sprite, not TextField, there is no property to hide. It utilizes mx.core.UITextField via composition, and the textField property is protected, so you CAN access it via inheritance. This example here shows how to override the selectable property and end up with a non-selectable TextArea.

Non-Selectable Text Area – App | Source

Zidane iPod, anyone?

12 Replies to “Non-Selectable TextArea for Flex 2”

  1. Huh? They guy asked for a TextArea that wasn’t selectable, so I coded him an example…???

  2. Jester, thanks so much. But I’m still getting an error:

    Attempted access of inaccessible property textField through a reference with static type…

    Obviously your code works, so I have to assume it’s because I’m running Beta 3 Flex. I’m upgrading in the next few days so I’ll let you know if it works then. Thanks again.

  3. Really? Hrm… I wonder if they made textField private in Beta 3, and then protected in the release version. That’s probably it. If not, hit us back and we’ll get it working.

  4. Good point! I think every Flex coder needs a non-selectable textarea every now and then! At least I needed one some days ago. Makes me wonder why Adobe hasn’t put it in as a property in the first place!

  5. Guys, this took 30 seconds to make. The email thread was going on for like 3 days, so I just whipped together an example. If you have suggestions on how to make it truly non-selectable, please feel free to leave a comment. My goal wasn’t to make a non-selectable TextArea, my goal was to make the TextArea act like selectable = false, and satisfy Jamie’s needs.

  6. Actually is not Jesse’s fault. I also tested and it seems that UITextField.selectable (at least inside TextArea) does not work as advertised:

    From LiveDocs:
    ‘If selectable is set to false, the text in the text field does not respond to selection commands from the mouse or keyboard, and the text cannot be copied with the Copy command.’

    It seems that even if set to false, it is still responding to keyboard selection and Copy. So it might be as well a small bug in the framework.

  7. Hi guys!! i too faced the same problem. and found this solution.

    TextAreaName.label.selectable = false;

    this seems to work in Flash 8.

    Cheers!

  8. Hi Jesse,

    I have a need for an Independent Consultant who knows Flex well. My client is moving towards Flex 2 as their strategic platform for rich Internet Applications Development.

    Please give me a call when you get a minute.

    Thanks

    Rob

    Rob Pierce

    Vice President

    eXperient

    404.812.4617

    http://www.eXperientcorp.com

  9. Dredging up an old thread here, but I found a workaround for this until TextArea is improved.
    You can set properties directly on a TextArea’s textField property, which exposes its UITextField.

    So, if you set textArea.textField.selectable = false, that appears to update itself properly.

    Also, the textArea.editable flag doesn’t appear to update well either. Instead, use

    textArea.textField.type = TextFieldType.INPUT; // == editable = true
    textArea.textField.type = TextFieldType.DYNAMIC; // == editable = false

    This is all hackery, but like many folks, I’ve burned more than enough days on trying to make TextArea behave. This works as far as I can tell.

  10. I thought this worked

    “Also, the textArea.editable flag doesn’t appear to update well either. Instead, use

    textArea.textField.type = TextFieldType.INPUT; // == editable = true
    textArea.textField.type = TextFieldType.DYNAMIC; // == editable = false”

    But that’s not the case…

Comments are closed.