1 Reply Latest reply on Dec 11, 2007 5:06 AM by markh

    Problem with Tree.expandItem

    markh Level 1
      I have defined a Tree in MXML. I update the dataProvider after I have grabbed some XML through the HTTPService and then I recursively go through the XML and look for a selected attribute and open the node if it has children, but it doesn't seem to work for me. The code is below. Any ideas what I'm doing wrong?

      static private function buildNavigation(navigation:XMLList, navigationTree:Tree):void{
      navigationTree.dataProvider=navigation.children();
      navigationTree.addEventListener(Event.CHANGE, function (event:Event):void {
      var selectedItem:XML=Tree(event.target).selectedItem as XML;
      Application.application.loadPage(selectedItem.@link);
      });
      openNodes(navigationTree, navigationTree.dataProvider.source);
      navigationTree.validateNow();
      }

      static private function openNodes(navigationTree:Tree, nodeList:XMLList):void{
      for(var i:int=0;i<nodeList.length();i++){
      if (nodeList .children().length()>0){
      if (nodeList
      .@selected=="true")
      navigationTree.expandItem(nodeList , true);
      openNodes(navigationTree, nodeList
      .children());
      }
      }
      }
        • 1. Re: Problem with Tree.expandItem
          markh Level 1
          I've found the solution, it should be:

          navigationTree.dataProvider=navigation.children();
          ...
          navigationTree.validateNow();
          openNodes(navigationTree, navigationTree.dataProvider.source);

          validateNow() should be called before you try and expand nodes (and after you update the dataProvider), not after.