4 Replies Latest reply on May 21, 2008 5:03 AM by Jeesmon

    Set Focus in AIR

      Hi there!

      My problem is this: In my Login Component there's a TextInput. If i put the setFocus() onto it, the cursor won't start to blink in it, but the TextInput is focused. And that's when the tricky part comes: If i switch to another window (using ALT+TAB, for example) and going back to the AIR application, voila, the blinking cursor is there, hand in hand with the focusing. Can someone help me out how this could happen, and/or how can i set the component's original focus (this.setFocus() on the start of the AS code doesn't working at all)
        • 1. Re: Set Focus in AIR
          Level 1
          You can add a creationComplete eventlistner for your TextInput and call the setFocus().

          textField.addEventListener(FlexEvent.CREATION_COMPLETE, function(event:Event):void {
          (event.currentTarget as TextInput).setFocus();
          • 2. Re: Set Focus in AIR
            Milo[HUN] Level 1
            I guess it won't work. As far as I know if I put a creatonComplete eventListener onto a component that created sooner than the whole application just won't work out well.

            (I tried, and it's not working)
            • 3. Re: Set Focus in AIR
              Milo[HUN] Level 1
              i went a bit further: the problem is that i'm working with <mx:Application> instead of WindowedApplication (visible tags in app.xml true), and because of this goes the caret away (or the Focus for the component).
              And that point i'm stucked again... :(
              • 4. Re: Set Focus in AIR
                Level 1
                Interesting. We are using this technique in many places in our app and it is working without any issue. We call setFocus directly on the TextInput creationcomplete event handler in some cases and for the parent container's (VBox) creationcomplete event handler in some other cases. Both worked just fine.

                You can see an example here:
                https://dev.eclipse.org/svnroot/technology/org.eclipse.higgins/trunk/app/org.eclipse.higgi ns.air/src/org/eclipse/higgins/cardselector/components/CredentialDialog.as