6 Replies Latest reply on Mar 15, 2011 9:42 AM by Flex harUI

    Focus Problem

    huangxinghui Level 1

      Hi,

       

      code:

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" width="400" height="300">
       <mx:Form>
        <mx:FormItem label="name:">
         <mx:TextInput/>
        </mx:FormItem>
       </mx:Form>
      </mx:TitleWindow>
      

       

      when i click the textinput, then i can not focus out

       

      see the FocusManager source code, find this:

       

      /**
           *  @private
           */
          private function getTopLevelFocusTarget(o:InteractiveObject):InteractiveObject
          {
              while (o != InteractiveObject(form))
              {
                  if (o is IFocusManagerComponent &&
                      IFocusManagerComponent(o).focusEnabled &&
                      IFocusManagerComponent(o).mouseFocusEnabled &&
                      (o is IUIComponent ? IUIComponent(o).enabled : true))
                      return o;
         // if we cross a boundry into a bridged application, then return null so
         // the target is only processed at the lowest level
         if (o.parent is ISWFLoader)
         {
          if (ISWFLoader(o.parent).swfBridge)
           return null; 
         }
                  o = o.parent;
                  if (o == null)
                      break;
              }
              return null;
          }
      


      can not set titlewindow focus in

       

      how to click other area except textinput to publish focus out event?

       

      Thanks a lot!

        • 1. Re: Focus Problem
          Flex harUI Adobe Employee

          Add a close or ok/cancel button(s)

          • 2. Re: Focus Problem
            huangxinghui Level 1

            Thanks, alex

             

            but i want click the blank area to publish focus out event

             

            because i set a validator on the textinput

             

            <mx:StringValidator source="{textInput}" property="text" triggerEvent="focusOut"/>
            
            • 3. Re: Focus Problem
              Flex harUI Adobe Employee

              I'm unclear how someone will close the TitleWindow.  Using the close button

              is a bit less usable because it is a small target and it isn't obvious what

              will happen when you click it.  Will it be the equivalent of "ok", "cancel"

              or will you get another dialog?

               

              So putting in buttons might be the best option.

               

              However, if you really must validating on clicking in the blank area, I

              would simply call the validator on CLICK if it didn't happen in the

              TextInput.

              • 4. Re: Focus Problem
                huangxinghui Level 1

                sorry, the titlewindow we set showCloseButton=true, this is only a example

                <mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" width="400" height="300"
                showCloseButton="true" close="closeHandler()" click="clickHandler(event)">
                
                <mx:Form>
                  <mx:FormItem label="name:">
                   <mx:TextInput/>
                  </mx:FormItem>
                 </mx:Form>
                
                <mx:Script>
                  <![CDATA[
                   import mx.managers.PopUpManager;
                   
                   private function closeHandler():void
                   {
                    PopUpManager.removePopUp(this);
                   }
                
                   private function clickHandler(event:MouseEvent):void
                   {
                    trace("Focus=" + focusManager.getFocus());
                   }
                 </mx:Script>
                
                </mx:TitleWindow>
                

                 


                then when focus out the textinput, we will call service to check input string is valid or not, so can not use button to check.

                 

                Thanks for your reply

                • 5. Re: Focus Problem
                  huangxinghui Level 1

                  so i extend the titlewindow add this code:

                   

                   

                  public function EnhancedTitleWindow()
                    {
                     super();
                     
                     showCloseButton = true;
                     
                     addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
                    }
                  
                  private function mouseDownHandler(event:MouseEvent):void
                    {
                     if (event.isDefaultPrevented())
                        return;    
                   
                     if (event.target == this)      
                        this.setFocus();
                    }
                  
                  

                   

                  give me some suggestions, Thanks a lot

                  • 6. Re: Focus Problem
                    Flex harUI Adobe Employee

                    I think I would just check if the TextInput contains the event.target and if

                    not, then call the validation method.

                    1 person found this helpful