4 Replies Latest reply on Sep 24, 2011 11:17 AM by NeoRamza2

    FocusOut in a custom component

    NeoRamza2

      Hi.

       

      I made a custom component using a Canvas with a TextInput and a Button inside.

      I need to make a focusOut event to be called when the focus go out of my custom component, but not be called when the focus change beetween the inputtext and the button inside the canvas.

       

      How can I do that?

       

      Tanks.

        • 1. Re: FocusOut in a custom component
          Flex harUI Adobe Employee

          You can try stopping propagation on the event, but that might mess up other

          things in the focus management.  Why do you want to do this?  Maybe you can

          dispatch a custom event and use that to trigger whatever you want to happen.

          • 2. Re: FocusOut in a custom component
            NeoRamza2 Level 1

            How to do this custom event? Any ideas?

            • 3. Re: FocusOut in a custom component
              Sathyamoorthi Level 2

              Hi this is simple.Please try this sample.

               

              <?xml version="1.0" encoding="utf-8"?>
              <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                             xmlns:s="library://ns.adobe.com/flex/spark"
                             xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:Cn="*" creationComplete="Init()">
                            
                  <fx:Script>
                      <![CDATA[
                      import flash.events.Event;
                      import mx.controls.Alert;
                     
                      private function Init():void
                      {
                          objTemp.addEventListener("FocusOut", FocusOutHandler);
                      }
                     
                      private function FocusOutHandler(event:Event):void
                      {
                          trace("CanCom's focus out");
                      }
                      ]]>
                  </fx:Script>
                 
                  <fx:Declarations>
                      <!-- Place non-visual elements (e.g., services, value objects) here -->
                  </fx:Declarations>
                 
              <s:HGroup>
                  <s:TextInput></s:TextInput>
                  <Cn:CanCom id="objTemp"></Cn:CanCom>
                  <s:TextInput></s:TextInput>
              </s:HGroup>
                 
              </s:Application>

               

               

               

               

               

               

               

               

               

              _____________________________________ CanCom.mxml ______________________________________

               

              <?xml version="1.0" encoding="utf-8"?>
              <s:HGroup xmlns:fx="http://ns.adobe.com/mxml/2009"
                             xmlns:s="library://ns.adobe.com/flex/spark"
                             xmlns:mx="library://ns.adobe.com/flex/halo">

               

                  <fx:Script>
                      <![CDATA[
                      import flash.events.Event;   
                     
                      private function FocusOutHandler(event:Event):void
                      {
                          try{
                          if (this.getFocus() == btnTemp || this.getFocus().parent.parent == txtTemp)
                          {
                              return;
                          }
                          }catch (err:Error) { }
                         
                          dispatchEvent(new Event("FocusOut"));
                      }
                      ]]>
                  </fx:Script>

               

                  <s:TextInput id="txtTemp" focusOut="FocusOutHandler(event)"></s:TextInput>
                  <s:Button id="btnTemp" focusOut="FocusOutHandler(event)"></s:Button>   
              </s:HGroup>

              • 4. Re: FocusOut in a custom component
                NeoRamza2 Level 1

                getFocus()  completely solved my problem. Tanks.