9 Replies Latest reply on Aug 6, 2011 9:47 AM by Francisc

    Programatically set itemRenderer

    Francisc Level 3

      Hello,

       

      How can I itemRenderers programatically? The reason I need this is that want the same list to change renderers based on user input.

       

      I tried this and it didn't work:

       

      //FirstItemRenderer extends IconItemRenderer

      var itemRenderer:FirstItemRenderer=new FirstItemRenderer();
      itemRenderer.iconWidth=40;
      itemRenderer.iconScaleMode="letterbox";
      itemRenderer.setStyle('iconDelay',0);

      //data object contains name, icon and decorator properties; the last 2 are embedded resources
      itemRenderer.labelField="name";
      itemRenderer.iconField="icon";
      itemRenderer.decorator="decorator";
      list.itemRenderer=itemRenderer as IFactory;
      list.dataProvider=acDataProvider;

       

      I tried this and it works, but I can't figure out how to set all of the things I could set above like iconWidth and iconField:

      list.itemRenderer=new ClassFactory(FirstItemRenderer);
      list.labelFunction=getName;
      list.dataProvider=acDataProvider;


      Where getName is this:

      private function getNameitem:Object):String
      {
          if(item.alternateName){return item.alternateName;}
          else{return item.firstName+' '+item.lastName;}
      }

       

      Again, I need this because if the user clicks button 1 then FirstItemRenderer is set as the renderer for #list, while if the second button is clicked then SecondItemRenderer is set.

       

      Thank you.