views:

532

answers:

3

Hi

I am wondering how I would keep the focus/selection on a TextArea even when a button outside is clicked.

Like how the RichTextEditor does it.

A: 
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
    <mx:TextArea id="textArea" focusOut="{textArea.setFocus()}" />
    <mx:Button id="test" label="Test" />
</mx:Application>
PeZ
This sort of works. But when I select between two of the TextArea there is a overflow exception, prob because both are trying to take the focus.
James_Dude
Maybe something like this but it only uses setFocus if the next focus is the certain button. I might try that.
James_Dude
A: 

In the event handler for the click event you will want to stopImmediatePropagation() and preventDefault() and then do your business with the selection/focus.

Joel Hooks
Hi Joel. That didnt work, on the buttons click event I used those two events and the button still stole the focus from the TextArea.
James_Dude
A: 

It appears that the RichTextEditor is accomplishing its maintaining focus with the following line in setTextStyles():

callLater(textArea.setFocus)

I think any user interaction with the RTE's controls will lead through this method, so that returns focus after the control event has completed.

Michael Brewer-Davis