8 Replies Latest reply on Mar 3, 2011 5:19 AM by NeoRamza2

    Problem with setFocus() after addPopUp()

    NeoRamza2 Level 1

      I have 2 screens/forms. The first call the second one as modal using  PopUpManager.addPopUp() when a button is clicked;

       

      After that have a setFocus() to set a focus into a inputtext on the first screen, this because I need to have the focus on a specific field on first screen when the second screen be closed;

       

      But when I close the form something set the focus in the button whom called the second screen.

       

      I tried use callLater(), but the problem remains and I cant set the focus on the rigth inputtext.

       

      How can I fix this?

       

      Tanks.

        • 1. Re: Problem with setFocus() after addPopUp()
          Flex harUI Adobe Employee

          Where did you set up the callLater?  If you use it too soon or too late it

          won't work.

          • 2. Re: Problem with setFocus() after addPopUp()
            NeoRamza2 Level 1

            I just made a simple test calling the screen, and in the next line I put the callLater calling a function that only does a setFocus(); . Nothing more than this and dont work.

            • 3. Re: Problem with setFocus() after addPopUp()
              Flex harUI Adobe Employee

              I don't know what "calling the screen" means.  Using callLater after

              addPopUp is probably too soon.  Waiting for creationComplete might be

              better.

              • 4. Re: Problem with setFocus() after addPopUp()
                NeoRamza2 Level 1

                Sorry for my english. Saing "Calling a screen" I wanned to say "show the form" "display window" (something like this).

                 

                Now this worked using FlexEvent.REMOVE.

                 

                But in another situation this dont worked. I need to put all this code inside a generic function is a action script file (*.as). When I do this it work only  in the firt time I click in the button.

                 

                The first window have a button that do this:

                 

                 

                private function Button1Click():void{

                     generic.ShowWarng(getChildren(), this);

                }

                 

                 

                The function in the "generic.as" is that:

                 

                 

                public static function ShowWarng(children:Array,parent:DisplayObject):void{

                     function lastfunction():void{

                         var textinput:TextInput;

                 

                         for (var iChild:int = 0; iChild < children.length; iChild++)

                         {

                            if(children[iChild] is TextInput){

                                    textinput = children[iChild] as TextInput;

                                    if((textinput.id == "firstinput")&& textinput.visible && textinput.enabled){

                                         textinput.setFocus();

                                    }

                             }

                          }             

                 

                     }

                 

                     //begin

                     var f_war:F_war = new F_war();
                     f_war.addEventListener(FlexEvent.REMOVE, lastfunction);
                     PopUpManager.addPopUp(f_war, parent, true);
                     PopUpManager.centerPopUp(f_war);
                }
                The first time I click in the button and then close the window f_war, the focus is rigth setted in the "firstinput". But in the other times I click in the button the focus goes to the button.

                 

                Someting is setting the focus to the button after FlexEvent.REMOVE.

                 

                Its very weird.

                • 5. Re: Problem with setFocus() after addPopUp()
                  Flex harUI Adobe Employee

                  I believe I recommended the use of CREATION_COMPLETE and not "REMOVED".  I'm

                  surprised REMOVED gets called at all.

                  • 6. Re: Problem with setFocus() after addPopUp()
                    NeoRamza2 Level 1

                    CREATION_COMPLETE doesnt worked. The focus goes to the rigth input, but when the modal window are closed the focus goes back to the button.

                    Using "REMOVED everything works fine, but mysteriously, in the second time I click in the button it dont work anymore and the focus goes to the button. And this problem only ocour when the code are in a actionscript file, otherwise everything works fine.

                     

                    I dont know, but now I am thinking that it is a flex's bug.

                    • 7. Re: Problem with setFocus() after addPopUp()
                      Flex harUI Adobe Employee

                      The system is designed to return focus to the button.  Where else do you

                      want it to go?  Using REMOVED is not recommended.  Try using another

                      callLater when the popup closes to move focus to where you want it.

                      • 8. Re: Problem with setFocus() after addPopUp()
                        NeoRamza2 Level 1

                        This dont worked too, but I found another way to do that and worked:

                         

                        I put a variable of type "Function" on the second window, and I run its after "PopUpManager.removePopUp(this);"

                        So before do "addPopUp" I set in this variable a function that set he focus in the rigth component;

                         

                        Tanks to everyone whom helped me.