9 Replies Latest reply on May 26, 2008 2:35 AM by nif

    setFocus problem

    nif
      hi there,

      i have an application that calls a login component i've made. in the login component i have a function which i call with creationComplete. this function basically resets the login form... here it is:

      private function resetLogin():void {
      username.text = "";
      password.text = "";
      username.setFocus();
      //var fManager:FocusManager = new FocusManager(this);
      //fManager.setFocus(username);
      }

      my problem is that setting the focus, whether i use FocusManager or simply say username.setFocus() doesn't seem to work... the focusRect is drawn, but the cursor doesn't focus within the username textInput area, which is the whole purpose for me setting focus.

      i've even tried calling the resetLogin function from the creationComplete event of the Application, thinking that maybe this was an issue with the application completing after the login component and stealing focus for some reason. but it doesn't work.

      does anyone know what i am doing wrong?

      thanks,
      nikki
        • 1. Re: setFocus problem
          nif Level 1
          sorry... forgot to mention that when this method is called with a CloseEvent of an Alert, then it works perfectly fine. so the problem lies somewhere in the creationComplete area.
          • 2. Re: setFocus problem
            Mitek17 Level 1
            Hi Nikki,

            1. Do you call this component immediately at the startup of an application?
            2. Do you use Firefox?

            If yes - there is a porblem with Firefox - it does not pass a focus to the loaded SWF automatically. Yoiu have to click on it first (or call an Alert() and it will make the trick).
            It works under IE though.

            If no - you probably have another problem setting a focus.
            Please read these threads:
            http://tech.groups.yahoo.com/group/flexcoders/message/102706


            Cheers,
            Dmitri.
            • 3. Re: setFocus problem
              nif Level 1
              hi dimitri,

              thanks for the reply.
              mine is on startup, but not only happening in firefox, so i guess it must be one of the other issues.

              i will check out the those threads.

              thanks a mil',
              nikki
              • 4. Re: setFocus problem
                nif Level 1
                hi dimitri,

                i checked out that thread and tried the 2 suggested routes, but to no avail. the focusRect displays, but focus is still not in the textInput area that i am targetting.

                here is my code, can you see where i am going wrong?

                i call reset login from here:

                <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" width="258" height="76" creationComplete="resetLogin()" keyUp="trySubmit(event)">

                and then this is in a script block below:

                public function resetLogin():void {
                username.text = "";
                password.text = "";
                this.callLater(this.callLater,[setupFocus]);
                }

                public function setupFocus():void {
                var fm:FocusManager = new FocusManager(this);
                fm.setFocus(username);
                fm.showFocus();
                var sm:SystemManager = new SystemManager();
                sm.activate(this);
                }

                thanks,
                nikki
                • 5. Re: setFocus problem
                  Mitek17 Level 1
                  Nikki,

                  Do you create this canvas using PopUpManager?

                  I would try the following:

                  private function setupFocus():void
                  {
                  username.setFocus()
                  }

                  And call this function from both creationComplete and updateComplete eventHandlers.

                  PS In my quite complex case with multiple popups I ended up with simple component.setFocus() call, but I am calling it upon creationComplte/updateComplete with delay (callLater).

                  PPS Did you try InternetExplorer? AFAIK Safari has this problem too.
                  • 6. Re: setFocus problem
                    nif Level 1
                    hi dimitri,

                    i origionally had my code calling username.setFocus(), but graduated it to the higher grade focusManager version in a hope that it would work... i have reverted to the former with the delays in place, but to no avail.
                    i have also tried running it on updateComplete, also to no avail... oh boy this is frustrating!

                    also, to note, when i call the logout from elsewhere, like when i click on my logout button and thus return to the login screen, it works like a charm.

                    the canvas is called into the root level of the app (from my app's main mxml file)... i think this is the problem, that it is called at application initialization.

                    i have tried both ie and netscape... in fact i now compile into ie all the time as i was having speed issues with firefox on my box.

                    i think i am going to try and call the login via as on creationComplete of the app and not an mxml tag... perhaps that'll do it.

                    i will update here if it solves the problem... hold thumbs for me :)

                    thanks,
                    nikki

                    • 7. Re: setFocus problem
                      nif Level 1
                      *sigh*... nope, doesn't work. oh well, i guess the user will have to click in the username box when the app starts.
                      unless anyone has any other ideas?
                      • 8. Re: setFocus problem
                        Mitek17 Level 1
                        Nikki,

                        can you try to isolate the problem in you code and post it here?

                        PS Don't give up. It should have a solution :)


                        Cheers,
                        Dmitri.
                        • 9. Re: setFocus problem
                          nif Level 1
                          hi dimitri,

                          unfortunately i am stuck between a looming deadline and a hard place.
                          i fully intend to relook this once all my work is complete, but in terms of priorities, this one has had to take a back seat to the entire sections i still need to create and finish up by thursday morning... *groan*

                          when i relook, if i do find a solution, or at least figure out exactly what is causing the issue, i will definately post here.

                          thanks for all of your help!
                          nikki