2 Replies Latest reply on Jan 3, 2007 7:47 AM by Pigg_Man

    expandItem not working

    Pigg_Man Level 1
      I have a .mxml app that extends a title Window class. This .mxml class contains a tree that I just dropped on the page. In the code behind I have a function that get's called on the class creationComplete(). The data that I use to populate the tree comes back in a callBack function that get's called in the creationComplete function. The data is xml and i convert it to an xml list and then an xmllistcollection
      function callBack (treeData:String) : void {
      if (treeData != null) {
      TreeCollection = new XMLListCollection (new XMLList (treeData));
      MyTree.expandItem (TreeCollection.getItemAt (0), true);
      MyTree.selectedIndex = 0;
      } else {


      The tree component is bound to TreeCollection... The data comes back and it get's populated with the correct data... Right after I put these lines of code.
      MyTree.expandItem (TreeCollection.getItemAt (0), true);
      MyTree.selectedIndex = 0;
      I did a trace statement on TreeCollection.getItemAt (0) and it is the right node... The selected Index code works but the expandItem gets hosed and it doesn't expand the node.. It fires an itemOpen event....
      I put the expand item code in a button click event and it works... it expands the node.. I'm thinking that the dataprovider is still loading the data or something.. it has to be some sort of timing issue. I've been beating my head on this for a long time ... Anyone understand timing of the dataprovider or loading dynamic stuff..
        • 1. Re: expandItem not working
          ntsiii Level 3
          Yeah, i wish I could give you a simple formula when this magic spell is required, but I can't. I Think you need to use callLater(). This method causes the call you pass to it to be deferred until the next "frame", and lets the tree get its act together before you start yelling at it. Here is an example. Where you are now calling expandItem, do:

          And that function looks like:
          /**called by callLater to ensure that the tree is ready to have expandItem called on it*/
          private function expandFirstNode():void
          myTree.expandItem(TreeCollection.getItemAt (0), true); //expand the node

          • 2. Re: expandItem not working
            Pigg_Man Level 1
            Thanks a ton.. this works!!!!