3 Replies Latest reply on Aug 23, 2007 5:31 AM by vtxr1300

    get next item in tree

    vtxr1300 Level 1
      When I handle the change event on my tree how do I get to the next item in the tree? I have looked in the docs and I don't see an items collection to take the current selectedIndex and increment it. I tried tree.items[tree.selectedIndex+1] but that didn't work. Thanks.
        • 1. Re: get next item in tree
          batmitra Level 1
          hi
          I don't know why you wanna do that, but anyway, you can make what you want using these 2 methods:

          expandItem()
          expandChildreOf()
          • 2. Re: get next item in tree
            ntsiii Level 3
            I don't know a clean way to do this, but...
            Get the parent node using parent()
            get an xmllist using parentNode.children()
            loop over the children to find the index matching the selectedItem(might have to compare the two xml nodes by first converting to strings using toXMLString())

            Now you have the index, and the child list, so you can do whatever logic you want.

            Gotta be an easier way, but I would make it work this way while I was searching for a more elegant solution.

            Hmm, If you wrapped children() in an xmlListCollection, you could use the getChildIndex method. Also the getItemAt(index + 1) method. This might be better than looping.

            Tracy

            Tracy
            • 3. Re: get next item in tree
              vtxr1300 Level 1
              What I'm trying to do is have a tree of videos that can either be on the main root node or within categories that would be a node off of the root node. Something like..

              topic 1 - video
              topic 2 - video
              topic 3 - video
              topic 3a - video
              topic 3b - video
              topic 4 - video
              topic 4b - video

              So, when someone is watching video 3b, I want to put some text on the stage saying "coming up next: " + video title from topic 4. I'm getting there with my code, but I've still got a little ways to go in another function that actually selects the node in the tree. Here's where I'm at with the main function that tracks what's selected and what's next. If anyone has any ideas of a way to do it more elegently, please let me know. Thanks.

              private function LoadTopicInfo(tree:Tree, xl:XMLListCollection):void{
              var topictitle:String = tree.selectedItem.@topicname;
              var url:String = tree.selectedItem.@url;
              if (url.length > 0){

              lblTitle.text = "Now Playing: " + topictitle;
              if (vdTopic.playing)
              vdTopic.stop();
              vdTopic.source = url;
              vdTopic.play();
              btnPause.enabled = btnPlay.enabled = true;
              }

              var topicid:Number = tree.selectedItem.@id;
              var sComingUp:String = "";

              nParentFolderIndex = 0;
              nNextMovieIndex = 0;
              nNextId = 0;

              for (var i:Number = 0; i < xl.length; i++){
              var item:XML = xl.getItemAt(i);
              if (topicid == item.@id){ //this is the selected node
              nParentFolderIndex = i;
              if (item.children().length() > 0){
              var xlTmp:XMLList = item.children();
              //get first child and set as next video
              sComingUp = xlTmp[0].@topicname;
              nNextId = xlTmp[0].@id;
              }else{
              //set next node as next video
              if ( i+1 < xl.length){
              var item2:XML = xl.getItemAt(i+1);
              sComingUp = item2.@topicname;
              nNextId = item2.@id;
              }
              }
              break;
              }else if (item.children().length() > 0){
              //run same comparison
              var children:XMLList = item.children();
              for (var l:Number = 0; l < children.length(); l++){
              if (children[l].@id == topicid){
              nParentFolderIndex = i;
              nNextMovieIndex = l;
              //set next node as next video
              if (l == children.length()-1 && (i+1 < xl.length)){
              //need to set this to next leaf since this would be last child
              var item2:XML = xl.getItemAt(i+1);
              sComingUp = item2.@topicname;
              nNextId = item2.@id;
              }else{
              var xlTmp:XMLList = item.children();
              sComingUp = xlTmp[l+1].@topicname;
              nNextId = xlTmp[l+1].@id;
              nNextMovieIndex = l+1;
              }
              break;
              }
              }
              }
              }


              lblIndex.text = "Main Node: " + nParentFolderIndex + " Selected: " + nNextMovieIndex;
              lblUpNext.text = (sComingUp.length > 0) ? "Coming Up: " + sComingUp : "";
              btnNext.visible = (lblUpNext.text.length > 0) ? true : false;

              }