4 Replies Latest reply on Jun 6, 2010 4:07 AM by Scott R. Hamilton

    Event handler function triggered multiple times

    Scott R. Hamilton Level 1

      I've writeen an even handler for the itemFocusOut of a datagrid.
      The event handler fires multiple times each time a cell in the
      grid is tabbed out of.

       

      Could this be because the event handler changes the contents of
      the row in which the itemFocusOut was triggered?

       

      What must I do to prevent this from happening? Must the event
      handler de-register itself at the beginning and the re-register
      itself as the last statment before returning?

       

      Below is the trace output of the event handler function eventually a run time

      error is provoked.

       

       

      disableEditMode(): Entry Point - event type: itemFocusOut   target control: EditRecipe2_515.Canvas517.dgRecIngr
      disableEditMode(): Entry Point - event type: itemFocusOut   target control: EditRecipe2_515.Canvas517.dgRecIngr
      disableEditMode(): Entry Point - event type: itemFocusOut   target control: EditRecipe2_515.Canvas517.dgRecIngr
      disableEditMode(): Entry Point - event type: itemFocusOut   target control: EditRecipe2_515.Canvas517.dgRecIngr
      disableEditMode(): Entry Point - event type: itemFocusOut   target control: EditRecipe2_515.Canvas517.dgRecIngr
      disableEditMode(): Entry Point - event type: itemFocusOut   target control: EditRecipe2_515.Canvas517.dgRecIngr
      disableEditMode(): Entry Point - event type: itemFocusOut   target control: EditRecipe2_515.Canvas517.dgRecIngr
      Converting: 1/8
      disableEditMode(): Entry Point - event type: itemFocusOut   target control: EditRecipe2_515.Canvas517.dgRecIngr
      Converting: 1/8
      ParseAndConvertFraction returns: 0.125
      disableEditMode(): Entry Point - event type: itemFocusOut   target control: EditRecipe2_515.Canvas517.dgRecIngr
      Converting: 1/8
      ParseAndConvertFraction returns: 0.125
      disableEditMode(): Entry Point - event type: itemFocusOut   target control: EditRecipe2_515.Canvas517.dgRecIngr
      Converting: 1/8
      ParseAndConvertFraction returns: 0.125
      disableEditMode(): Entry Point - event type: itemFocusOut   target control: EditRecipe2_515.Canvas517.dgRecIngr
      Converting: 1/8
      ParseAndConvertFraction returns: 0.125
      disableEditMode(): Entry Point - event type: itemFocusOut   target control: EditRecipe2_515.Canvas517.dgRecIngr
      Converting: 1/8
      ParseAndConvertFraction returns: 0.125
      disableEditMode(): Entry Point - event type: itemFocusOut   target control: EditRecipe2_515.Canvas517.dgRecIngr
      Converting: 1/8
      ParseAndConvertFraction returns: 0.125
      disableEditMode(): Entry Point - event type: itemFocusOut   target control: EditRecipe2_515.Canvas517.dgRecIngr
      Converting: 1/8

       

      .

       

      .

       

      .

       

       

      undefined
          at ModuleManagerImpl/getAssociatedFactory()[C:\autobuild\3.5.0\frameworks\projects\framework \src\mx\modules\ModuleManager.as:150]
          at mx.modules::ModuleManager$/getAssociatedFactory()[C:\autobuild\3.5.0\frameworks\projects\ framework\src\mx\modules\ModuleManager.as:64]
          at mx.core::UIComponent/getClassStyleDeclarations()[C:\autobuild\3.5.0\frameworks\projects\f ramework\src\mx\core\UIComponent.as:7682]
          at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::initThemeColor()[C:\autobuild\3.5.0\frameworks \projects\framework\src\mx\core\UIComponent.as:8025]
          at mx.core::UIComponent/styleChanged()[C:\autobuild\3.5.0\frameworks\projects\framework\src\ mx\core\UIComponent.as:5661]
          at mx.controls::Button/styleChanged()[C:\autobuild\3.5.0\frameworks\projects\framework\src\m x\controls\Button.as:1632]
          at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::addingChild()[C:\autobuild\3.5.0\frameworks\pr ojects\framework\src\mx\core\UIComponent.as:5255]
          at mx.core::UIComponent/addChild()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\c ore\UIComponent.as:4966]
          at mx.controls.alertClasses::AlertForm/createButton()[C:\autobuild\3.5.0\frameworks\projects \framework\src\mx\controls\alertClasses\AlertForm.as:472]
          at mx.controls.alertClasses::AlertForm/createChildren()[C:\autobuild\3.5.0\frameworks\projec ts\framework\src\mx\controls\alertClasses\AlertForm.as:176]
          at mx.core::UIComponent/initialize()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx \core\UIComponent.as:5381]
          at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::childAdded()[C:\autobuild\3.5.0\frameworks\pro jects\framework\src\mx\core\UIComponent.as:5278]
          at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::childAdded()[C:\autobuild\3.5.0\frameworks\pro jects\framework\src\mx\core\Container.as:3348]
          at mx.core::Container/addChildAt()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\c ore\Container.as:2260]
          at mx.core::Container/addChild()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\cor e\Container.as:2183]
          at mx.controls::Alert/createChildren()[C:\autobuild\3.5.0\frameworks\projects\framework\src\ mx\controls\Alert.as:713]
          at mx.core::UIComponent/initialize()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx \core\UIComponent.as:5381]
          at mx.core::Container/initialize()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\c ore\Container.as:2569]
          at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::childAdded()[C:\autobuild\3.5.0\frameworks\pro jects\framework\src\mx\managers\SystemManager.as:2131]
          at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::rawChildren_addChildAt()[C:\autobuild\3.5.0\fr ameworks\projects\framework\src\mx\managers\SystemManager.as:2181]
          at mx.managers::SystemManager/addChildAt()[C:\autobuild\3.5.0\frameworks\projects\framework\ src\mx\managers\SystemManager.as:1702]
          at mx.managers::SystemManager/addChild()[C:\autobuild\3.5.0\frameworks\projects\framework\sr c\mx\managers\SystemManager.as:1685]
          at mx.managers::PopUpManagerImpl/addPopUp()[C:\autobuild\3.5.0\frameworks\projects\framework \src\mx\managers\PopUpManagerImpl.as:309]
          at mx.managers::PopUpManager$/addPopUp()[C:\autobuild\3.5.0\frameworks\projects\framework\sr c\mx\managers\PopUpManager.as:169]
          at mx.controls::Alert$/show()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\contro ls\Alert.as:519]
          at EditRecipe2/ParseAndConvertFraction()[C:\Users\Scott\Documents\Flex Builder 3\Culinaria\src\EditRecipe2.mxml:338]
          at EditRecipe2/disableEditMode()[C:\Users\Scott\Documents\Flex Builder 3\Culinaria\src\EditRecipe2.mxml:298]
          at EditRecipe2/__dgRecIngr_itemFocusOut()[C:\Users\Scott\Documents\Flex Builder 3\Culinaria\src\EditRecipe2.mxml:547]
          at flash.events::EventDispatcher/dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at mx.core::UIComponent/dispatchEvent()[C:\autobuild\3.5.0\frameworks\projects\framework\src \mx\core\UIComponent.as:9440]
          at mx.controls::DataGrid/destroyItemEditor()[C:\autobuild\3.5.0\frameworks\projects\framewor k\src\mx\controls\DataGrid.as:4024]
          at mx.controls::DataGrid/itemEditorItemEditEndHandler()[C:\autobuild\3.5.0\frameworks\projec ts\framework\src\mx\controls\DataGrid.as:4934]
          at flash.events::EventDispatcher/dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at mx.core::UIComponent/dispatchEvent()[C:\autobuild\3.5.0\frameworks\projects\framework\src \mx\core\UIComponent.as:9440]
          at mx.controls::DataGrid/endEdit()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\c ontrols\DataGrid.as:4085]
          at mx.controls::DataGrid/collectionChangeHandler()[C:\autobuild\3.5.0\frameworks\projects\fr amework\src\mx\controls\DataGrid.as:4282]
          at flash.events::EventDispatcher/dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at mx.collections::ListCollectionView/dispatchEvent()[C:\autobuild\3.5.0\frameworks\projects \framework\src\mx\collections\ListCollectionView.as:879]
          at mx.collections::ListCollectionView/replaceItemsInView()[C:\autobuild\3.5.0\frameworks\pro jects\framework\src\mx\collections\ListCollectionView.as:1510]
          at mx.collections::ListCollectionView/listChangeHandler()[C:\autobuild\3.5.0\frameworks\proj ects\framework\src\mx\collections\ListCollectionView.as:1116]
          at flash.events::EventDispatcher/dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at mx.collections::ArrayList/setItemAt()[C:\autobuild\3.5.0\frameworks\projects\framework\sr c\mx\collections\ArrayList.as:267]
          at mx.collections::ListCollectionView/setItemAt()[C:\autobuild\3.5.0\frameworks\projects\fra mework\src\mx\collections\ListCollectionView.as:462]
          at EditRecipe2/disableEditMode()[C:\Users\Scott\Documents\Flex Builder 3\Culinaria\src\EditRecipe2.mxml:316]
          at EditRecipe2/__dgRecIngr_itemFocusOut()[C:\Users\Scott\Documents\Flex Builder 3\Culinaria\src\EditRecipe2.mxml:547]
          at flash.events::EventDispatcher/dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at mx.core::UIComponent/dispatchEvent()[C:\autobuild\3.5.0\frameworks\projects\framework\src \mx\core\UIComponent.as:9440]
          at mx.controls::DataGrid/destroyItemEditor()[C:\autobuild\3.5.0\frameworks\projects\framewor k\src\mx\controls\DataGrid.as:4024]
          at mx.controls::DataGrid/itemEditorItemEditEndHandler()[C:\autobuild\3.5.0\frameworks\projec ts\framework\src\mx\controls\DataGrid.as:4934]
          at flash.events::EventDispatcher/dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at mx.core::UIComponent/dispatchEvent()[C:\autobuild\3.5.0\frameworks\projects\framework\src \mx\core\UIComponent.as:9440]
          at mx.controls::DataGrid/endEdit()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\c ontrols\DataGrid.as:4085]
          at mx.controls::DataGrid/collectionChangeHandler()[C:\autobuild\3.5.0\frameworks\projects\fr amework\src\mx\controls\DataGrid.as:4282]
          at flash.events::EventDispatcher/dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at mx.collections::ListCollectionView/dispatchEvent()[C:\autobuild\3.5.0\frameworks\projects \framework\src\mx\collections\ListCollectionView.as:879]
          at mx.collections::ListCollectionView/replaceItemsInView()[C:\autobuild\3.5.0\frameworks\pro jects\framework\src\mx\collections\ListCollectionView.as:1510]
          at mx.collections::ListCollectionView/listChangeHandler()[C:\autobuild\3.5.0\frameworks\proj ects\framework\src\mx\collections\ListCollectionView.as:1116]

        • 1. Re: Event handler function triggered multiple times
          Flex harUI Adobe Employee

          Set a breakpoint and examine the callstack.  It might give you a clue as to

          how to prevent a callback.  You can always set a flag to ignore other calls.

          • 2. Re: Event handler function triggered multiple times
            Scott R. Hamilton Level 1

            Hi Alex,

             

            Thanks for your reply.

             

            I am not sure how to implement your suggestion of using a flag to

            prevent callbacks from occurring.

             

            Presumably the flag variable would be defined globally within the

            component so that it would be visible from within the event handler

            function.

             

            How and when would this flag be set and unset and how would this

            prevent the callback from occurring?

             

             

            Scott

            • 3. Re: Event handler function triggered multiple times
              Flex harUI Adobe Employee

              Class Foo

              {

                  private var inMyHandler:Boolean;

               

                  private function myHandler(event:Event):void

                  {

                      if (inMyHandler) return;

               

                      inMyHandler = true;

               

                      // do whatever

               

                      inMyHandler = false;

                  }

              }

              • 4. Re: Event handler function triggered multiple times
                Scott R. Hamilton Level 1

                Hi Alex,

                 

                I tired this and now I'm getting a runtime error. The trace ouptput is below

                 

                The first two lines of output is the function printing its signature and state.

                As soon as the function starts to do some work the error occurs.

                 

                After I stop execution in the debugger I can see that the function has run

                correctly and I can make another change in the datagrid and the function will be

                called again and run without error.

                 

                Scott

                 

                 

                 

                 

                 

                disableEditMode(): Entry Point - selectedIndex: 1    selectedItem: [object Object]
                disableEditMode(): Entry Point - bFuncBlock = TRUE
                TypeError: Error #1009: Der Zugriff auf eine Eigenschaft oder eine Methode eines null-Objektverweises ist nicht möglich.
                    at mx.controls::DataGrid/destroyItemEditor()[C:\autobuild\3.5.0\frameworks\projects\framewor k\src\mx\controls\DataGrid.as:4026]
                    at mx.controls::DataGrid/itemEditorItemEditEndHandler()[C:\autobuild\3.5.0\frameworks\projec ts\framework\src\mx\controls\DataGrid.as:4934]
                    at flash.events::EventDispatcher/dispatchEventFunction()
                    at flash.events::EventDispatcher/dispatchEvent()
                    at mx.core::UIComponent/dispatchEvent()[C:\autobuild\3.5.0\frameworks\projects\framework\src \mx\core\UIComponent.as:9440]
                    at mx.controls::DataGrid/endEdit()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\c ontrols\DataGrid.as:4085]
                    at mx.controls::DataGrid/findNextItemRenderer()[C:\autobuild\3.5.0\frameworks\projects\frame work\src\mx\controls\DataGrid.as:3990]
                    at mx.controls::DataGrid/keyFocusChangeHandler()[C:\autobuild\3.5.0\frameworks\projects\fram ework\src\mx\controls\DataGrid.as:4747]