How To Make the ActionScript 3.0 (AS3) TextArea Not Selectable
Here’s something I wasted like 45 minutes on, and it should be pretty trivial. I needed to make the TextArea component NOT selectable, yet still enabled (need the scrollbar to work).
I started digging around the TextArea.as class, because no matter what I did in my code (such as myTextArea.textField.selectable = false; ), the TextArea was still selectable. It appears that when the TextArea calls the draw() or setSize() methods, it updates the text field in the TextArea to be selectable depending on whether the TextArea is enabled or not.
Clearly, whoever designed the TextArea component didn’t give this much thought. In any case, the way I got around the issue is to attach to the Event.Render event of the text area. Therefore, after the render method is called (and the TextArea is drawn), I can update the textfield to not be selectable. Here is some sample code.You may need to attach to more events than just the render event, but the concept should work.
var DescriptionField:TextArea = getChildByName( "description" ) as TextArea;
DescriptionField.addEventListener( Event.RENDER, onDescriptionRender );
public function onDescriptionRender( evt:Event ):void
{
var textArea:TextArea = evt.target as TextArea;
textArea.textField.selectable = false;
}