6 Replies Latest reply on Oct 21, 2010 12:08 AM by Flex harUI

    Problem with TreeItemRenderer

    thenewmexican62 Level 1

      I'm having a problem with the TreeItemRenderer. All my renderer does is change the color of the label of a node (to red) if a given node has children.

      If not. The label color is black with a normal font. When I add a leaf to a given node. The expected behavior occurs. The node with the child

      changes color, and font.

       

      However, when I remove a leaf from a given node. The font is currectly rendered as normal font, however the color of the label remains red, unless

      I mouse over the given node in which the child leaf was removed, after which it correctly renders as normal font, and black color again.

       

      I have tried everything, invalidateList(),invalidateDisplayList(),invalidateProperties(). Nothing seems to work.

       


          public class MyTreeItemRenderer extends TreeItemRenderer{
             
             
              public function DayScheduleTreeItemRenderer(){
                      super();
              }
               // Override the set method for the data property
              // to set the font color and style of each node.       
              override public function set data(value:Object):void {
                  super.data = value;
                  if(value is DaySchedule){
                      if(DaySchedule(value).times.length >0){
                          setStyle("color", 0xff0000);
                          setStyle("fontWeight", 'bold');
                      }
                  }
                 
                  else {
                      setStyle("color", 0x000000);
                      setStyle("fontWeight", 'normal');
                  } 
             
              }
             
             
               // Override the updateDisplayList() method
              // to set the text for each tree node.     
              override protected function updateDisplayList(unscaledWidth:Number,unscaledHeight:Number):void {
            
                  super.updateDisplayList(unscaledWidth, unscaledHeight);
                  if(super.data){
                     
                      if(TreeListData(super.listData).hasChildren){
                     
                          if(TreeListData(super.listData).item.times.length >0){
                             
                             
                             
                              var myStr:int = TreeListData(super.listData).item.children.source.length;
                              super.label.text =  TreeListData(super.listData).label + "(" + myStr + ")";
                              setStyle("color", 0xff0000);
                              setStyle("fontWeight", 'bold');
                          }
                          else {
                             
                              setStyle("color", "0x000000");
                              setStyle("fontWeight", 'normal');
                              super.label.text =  TreeListData(super.listData).label;
                             
                          }
                       }
                      
                  }
                 
                 
                 
              }

          }

       

       

      Any help would be greatly appreciated.