5 Replies Latest reply on Jun 22, 2012 8:10 PM by vincent.racaza

    suggested workaround for list itemrenderer bug?


      Can someone point me in the right direction for a workaround for the problem described as Flex bug 28191:





      Steps to reproduce:


      1. Populate a Tree/List with data and provide a custom itemRenderer class factory.


      2. Change the class factory and dataProvider at the same time.


      3. List.createItemRenderer() will crash during since Factory is the key and it has been changed.

                      delete freeItemRenderersByFactory[factory][renderer];


      Actual Results:

      Crash because the renderer can not be found since it does not exist on that factory dictionary since the class factory was changed and the lookup is using the new factory.


      Expected Results:

      Not crash.


      Seems like a race condition, as sometimes during this process it skips that block of code but in other cases it falls into this block and fails.



      I need to change the data provider and item renderer of a tree control at runtime. Is there one or more methods I should run to prevent this? As the bug notes state, this is an intermittent problem. The error occurs here:


      if (factory == itemRenderer)


                  if (freeItemRenderers && freeItemRenderers.length)


                      renderer = freeItemRenderers.pop();

                      delete freeItemRenderersByFactory[factory][renderer];




        • 1. Re: suggested workaround for list itemrenderer bug?
          Flex harUI Adobe Employee

          How are you changing the classFactory?  Try calling validateNow() after changing it and before you set the dataprovider.

          • 2. Re: suggested workaround for list itemrenderer bug?
            Conanicut Level 1

            Thanks. Actually, I have been updating (not setting or changing) the tree's dataprovider, and then changing the classFactory like this:


            processesXML = event.result as XML;

            nodeTreeData.source = processesXML.children();


            if (treeMultiSelect)


            nodeTree.itemRenderer=new ClassFactory(renderers.TreeItemRendererV1);

            nodeTree.allowMultipleSelection = true;

            nodeTree.setStyle("selectionColor", "0xFFFFFF");

            nodeTree.setStyle("disclosureOpenIcon", MinusIcon);

            nodeTree.setStyle("disclosureClosedIcon", PlusIcon);





            nodeTree.itemRenderer=new ClassFactory(mx.controls.treeClasses.TreeItemRenderer);

            nodeTree.allowMultipleSelection = false;

            nodeTree.setStyle("selectionColor", "0x7FCEFF");

            nodeTree.setStyle("disclosureOpenIcon", OpenArrowIcon);

            nodeTree.setStyle("disclosureClosedIcon", ClosedArrowIcon);



            I had tried using validateNow after changing the ClassFactory before but did get the error again. I will try it again but update the data provider after. Since it's an intermittent error I'm finding it hard to know if a fix is really working.

            • 3. Re: suggested workaround for list itemrenderer bug?
              Flex harUI Adobe Employee

              Changing just the renderer, then calling validateNow() should set a flag that flushes the freeItemRenderers.  It is possible that if something else is dirty (new data for example) then other code might run before the renderers get flushed.


              There is a protected method called purgeItemRenderers() that actually does the flushing.  I supposed you could try subclassing and calling it directly.



              • 4. Re: suggested workaround for list itemrenderer bug?
                Conanicut Level 1

                Thank you. Can you point me in the right direction on how and where to call that method directly? I haven't gotten into subclassing. Can you recommend a tutorial that would be helpful? Am I subclassing the tree component or something else? Thanks again.

                • 5. Re: suggested workaround for list itemrenderer bug?

                  That is also my problem....


                  When I try to delete a row with itemrenderer from the datagrid, the row will be deleted. But when I try to add again a row, the property of last item renderer will not be flushed or deleted.


                  How to remove item renderers?