views:

80

answers:

3

I'm trying to have a popup window with an immediately editable TextInput. This means that the user should be able to type inside the TextInput once the popup is displayed.

The problem is that I can't focus on the textInput. What happens is that when pressing a key for the first time, no text is inserted, only after a second key is pressed does the component gain focus and the user is able to type. For instance, typing "test" once the popup opened results in "est" being displayed...

For some reason the component only gains focus when the user explicitly clicks on it or types something. Programmaticaly setting the focus does not work.

Any ideas/suggestions?

Code:

<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns="mog.miss.component.*" xmlns:mx="http://www.adobe.com/2006/mxml" >

<mx:Script>
    <![CDATA[
        import mx.managers.IFocusManagerComponent;

        private function focus():void{
            focusManager.setFocus(commentTextInput as IFocusManagerComponent);
            commentTextInput.setSelection(commentTextInput.text.length,commentTextInput.text.length);
        }

    ]]>
</mx:Script>
<mx:TextInput id="commentTextInput" creationComplete="{focus()}" />

</mx:Panel>
A: 

It depends on how you try to do it. What works for me is handling the creationComplete Event of the popup:

private function onCreationComplete():void 
{
    focusManager.setFocus(this.mytextInput as IFocusManagerComponent);
}

PS: The "handler" in the example is added via mxml so it has no parameters.

bug-a-lot
That does not work as expected...
Tiago Pereira
Out of curiosity what OS and browser are you using?
bug-a-lot
A: 

Here's what works for me. In the creationComplete event of the pop up window:

private function onCreationComplete():void
{
  callLater(this.commentTextInput.setFocus);
}
Jason Towne
That does work... the problem was something else entirely. I was using the F10 key to trigger the popup. It just happens that F10 is system reserved. Using another key works fine.
Tiago Pereira
A: 

The problem was that I was triggering the popup call with the F10 key. The F10 is system reserved... it did trigger the handler and the popup was created but somehow the application lost focus. Using another key fixed it. The only reserved key is F10. More about that

Tiago Pereira