1 Reply Latest reply on May 19, 2009 10:41 AM by injpix

    Accessing ItemIndex in a Tree by ItemName

    Mohd Fayaz Level 1

      I have a tree as follows

       

       

      --> Production

           --> Person1

           --> Person2

      --> Test

            --> Person1

            --> Person2

       

      I have a variable dept:String that contains either "Production" or "Test" as values.

       

      How can I find out the index of  dept value in the Tree.

        • 1. Re: Accessing ItemIndex in a Tree by ItemName
          injpix Level 3

          Depending on your needs, this may work.  Let us know.

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="onCreationComplete()">
             
              <mx:Script>
                  <![CDATA[
                      import mx.controls.treeClasses.TreeItemRenderer;
                      import mx.collections.XMLListCollection;
                     
                      private function onCreationComplete():void
                      {
                          var parentNodes:XMLListCollection = tree.dataProvider as XMLListCollection;
                 
                          var dept:String = parentNodes[0].@label.toString();//returns: Production
                          var item:TreeItemRenderer = tree.itemToItemRenderer(parentNodes[0]) as TreeItemRenderer;//returns: itemRenderer
                          var index:int = item.listData.rowIndex;//returns: 0
                         
                          trace(index);
                      }
                  ]]>
              </mx:Script>
             
              <mx:XMLList id="treeData">
                  <node label="Production">
                      <node label="Person1"/>
                      <node label="Person2"/>
                  </node>
                  <node label="Test">
                      <node label="Person1"/>
                      <node label="Person2"/>
                  </node>  
              </mx:XMLList>

           

              <mx:Tree id="tree" dataProvider="{treeData}"  labelField="@label" width="200"/>
             
          </mx:Application>