8 Replies Latest reply on Jan 12, 2010 1:19 AM by stephgravity

    How to prevent itemFocusOut event of DataGrid, which is being fired twice?

    megharajdeepak Level 1

      Hi,

       

      I came across this problem, where the function defined for itemFocusOut is triggered twice!!! I'm goin' crazy....

      here's my test code:

       

       

           <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

       

      <mx:Script>
          <![CDATA[
              import mx.events.DataGridEvent;
             
              private function onFocusOut(event:DataGridEvent):void{
                 
                  trace("event called...");
              }
          ]]>
      </mx:Script>
          <mx:DataGrid x="204" y="140" itemFocusOut="onFocusOut(event)" editable="true">
              <mx:dataProvider>
                  <mx:ArrayCollection>
                      <mx:Object col1="" col2="" col3=""/>
                      <mx:Object col1="" col2="" col3=""/>
                      <mx:Object col1="" col2="" col3=""/>
                      <mx:Object col1="" col2="" col3=""/>
                  </mx:ArrayCollection>
              </mx:dataProvider>
              <mx:columns>
                  <mx:DataGridColumn headerText="Column 1" dataField="col1"/>
                  <mx:DataGridColumn headerText="Column 2" dataField="col2"/>
                  <mx:DataGridColumn headerText="Column 3" dataField="col3"/>
              </mx:columns>
          </mx:DataGrid>
         
         
         
      </mx:Application>

       

      This is my output:

       

      [SWF] D:\workspace\testothers\bin-debug\testDG.swf - 979,723 bytes after decompression
      event called...
      event called...

       

       

      How can I prevent it? I searched forum for solution, but couldn't find any.....

       

      Appreciate your help

       

      --Deepak

        • 1. Re: How to prevent itemFocusOut event of DataGrid, which is being fired twice?
          Flex harUI Adobe Employee

          I see it once per click or tab.  What version of the SDK are you using?

           

          Alex Harui

          Flex SDK Developer

          Adobe Systems Inc.

          Blog: http://blogs.adobe.com/aharui

          • 2. Re: How to prevent itemFocusOut event of DataGrid, which is being fired twice?
            megharajdeepak Level 1

            Hi Alex,

             

            I'm working on 3.2. And I get that problem on mouse click, tab and enter.

             

            --Deepak

            • 3. Re: How to prevent itemFocusOut event of DataGrid, which is being fired twice?
              Flex harUI Adobe Employee

              I tried your code in 3.2 and don't see the problem.

               

              Alex Harui

              Flex SDK Developer

              Adobe Systems Inc.

              Blog: http://blogs.adobe.com/aharui

              • 4. Re: How to prevent itemFocusOut event of DataGrid, which is being fired twice?
                megharajdeepak Level 1

                I still have the same problem

                Is there some kind of compiler settings or complier arguments, I'm suposed to follow?

                 

                Meanwhile I was downloading SDK 3.5 from here: http://opensource.adobe.com/wiki/display/flexsdk/download?build=3.5.0.12683&pkgtype=1 . Hope it works there atleast.....

                • 6. Re: How to prevent itemFocusOut event of DataGrid, which is being fired twice?
                  Flex harUI Adobe Employee

                  Maybe try tracing mouseDown/mouseUp and keyDown/keyUp and see if you really

                  are getting two-for-one

                  • 7. Re: How to prevent itemFocusOut event of DataGrid, which is being fired twice?
                    megharajdeepak Level 1

                     

                    it's still getting fired twice...... I can still manage this, I don't have any problem with the event being triggered twice. In my application on whcih I'm working on, I'm calling a function on itemFocusOut which works fine for the first time. But when it gets triggered for the second time(which has been a problem for me), it calls some destroyItemEditor() and i get a error stack.

                     

                    Here's my code:

                     

                    private function onItemFocusOut (event:DataGridEvent):void{
                                   
                                 
                                   
                                    if(event.currentTarget.editedItemPosition.columnIndex == 3){   //if the selected cell is from Date column
                                       
                                        var splitEnteredDate:Array = event.target.itemEditorInstance.text.split( '.' );
                                       
                                       
                                       
                                        var todayDate:Date = new Date();
                                        var sixMonthDelayDate:Date = new Date();
                                       
                                        var todayDateString:String = dateFormatter.format(todayDate);
                                       
                                        var splitTodayDate:Array = todayDateString.split( '.' );
                                       
                                        //enteredDate = new Date(splitEnteredDate[2], splitEnteredDate[1]-1, splitEnteredDate[0]);
                                        sixMonthDelayDate = new Date(splitTodayDate[2], splitTodayDate[1]-1, splitTodayDate[0]);
                                        sixMonthDelayDate.month = sixMonthDelayDate.getMonth() - 6;
                                                          
                                       
                                        var enteredDateString:String = event.target.itemEditorInstance.text;
                                        var sixMonthDelayDateString:String = dateFormatter.format(sixMonthDelayDate);

                     

                                        //See if the entered date is less than 6months from today's date


                                         if(DateField.stringToDate(enteredDateString,"DD.MM.YYYY") <= DateField.stringToDate(sixMonthDelayDateString,"DD.MM.YYYY")){
                                           
                                            event.currentTarget.itemEditorInstance.errorString = "Date cannot be less than 6 months from today's date.";
                                                                 
                                            Alert.show("Date cannot be less than 6 months from today's date. You entered "+enteredDateString+".", "Invalid date");
                                           
                                        }
                                       
                                       
                                       
                                    }
                                   
                    }       

                     

                    This is the error message:

                     

                    Error: Error #1009: Cannot access a property or method of a null object reference.
                         at mx.controls::DataGrid/destroyItemEditor()[C:\autobuild\3.2.0\frameworks\projects\framewor k\src\mx\controls\DataGrid.as:4000]
                         at mx.controls::DataGrid/itemEditorItemEditEndHandler()[C:\autobuild\3.2.0\frameworks\projec ts\framework\src\mx\controls\DataGrid.as:4897]
                         at flash.events::EventDispatcher/dispatchEventFunction()
                         at flash.events::EventDispatcher/dispatchEvent()
                         at mx.core::UIComponent/dispatchEvent()[C:\autobuild\3.2.0\frameworks\projects\framework\src \mx\core\UIComponent.as:9298]
                         at mx.controls::DataGrid/endEdit()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\c ontrols\DataGrid.as:4041]
                         at mx.controls::DataGrid/mouseDownHandler()[C:\autobuild\3.2.0\frameworks\projects\framework \src\mx\controls\DataGrid.as:4296]

                     

                    Here, with that error, if I say, "Continue", I get the Alert message twice.

                     

                    Since, itemFocusOut was triggering twice, and which I thought was root causel, I thought of testing it in some test application before, which was posted earlier.

                    • 8. Re: How to prevent itemFocusOut event of DataGrid, which is being fired twice?
                      stephgravity Level 1

                      maybe try to remove the listener when the event is caught the first time and readd-it after you process something

                       

                      Stephanie