4 Replies Latest reply on Mar 16, 2011 4:08 AM by eprevot123

    ItemRenderer depending on other variable than data

    eprevot123

      I try to create a TreeItemRenderer to display each item according to the data and also to another variable that is in the component owning the Tree.

      For example, you have a comboBox to choose a letter in the alphabet, and a Tree that displays some words, and you want to display red all the nodes in the Tree whose label starts with the chosen letter.

      In my TreeItemRenderer I can get the first letter of the node using the "data" variable, but I don't know how to get the "firstLetter" variable of my application (the selectedItem in the comboBox), since I don't create an instance of my renderer but just give the class to the Tree : <mx:Tree itemRenderer="renderers.CustomTreeRenderer"/>

       

      I tried to create the renderer this way (this is called each time the selectedItem in comboBox changes) :

      var factory:ClassFactory = new ClassFactory(CustomTreeRenderer);

      factory.properties = {firstLetter : myComboBox.selectedItem};
      myTree.itemRenderer = factory;

       

      but this gives me an error at runtime :

      TypeError: Error #1010: A term is undefined and has no properties.
          at mx.controls::List/createItemRenderer()[E:\dev\hero_private_beta\frameworks\projects\mx\sr c\mx\controls\List.as:1951]

       

      Does someone know how to do this ? (I think it's the same problem with ItemRenderer in List)