1 Reply Latest reply on Feb 4, 2010 9:49 PM by Gus Leo

    Vertical scroll up/down when expand or collapse tree items

    Gus Leo Level 1

      Hi everyone, I'm newbie in adobe flex. Is it possible to makes vertical scroll position automatically scroll up and down when tree component expand/collapse?

       

      I would like to make automatically scroll position likes in tree of windows explorer. Any idea to makes it work?

       


      Regards,

       

      Gus Leo

        • 1. Re: Vertical scroll up/down when expand or collapse tree items
          Gus Leo Level 1

          Yeah!!!after trial and error with this issue i find some logic to makes vertical scroll down automatically likes windos explorer.

          I'm attach some code with about this issue and hopes this will be useful for other developer.

           

          Put the code on ItemOpen on tree component

           

           

          private function onItemOpen(event:TreeEvent):void{
                                       
                         //rowHeight is default height of tree and +2 is my own logic, because they have a space between a tree
                              var _rowHeight:int = int(event.currentTarget.rowHeight) + 2;
                             
                              var posX:int = int(event.currentTarget.mouseY);
                              var _maxHeight:int = myTree.height;
                              var itemCount:int = int(event.item.children.length);
                             
                             
                             
                              //cheking the current position and calculation of droping index
                              if (((itemCount*_rowHeight) + posX) > _maxHeight){
                                  var _currpos:int = posX + _rowHeight;
                                  var _heightCount:int = _rowHeight;//default height count is the _rowHeight
                                 
                                  for (var i:int = 0;i<itemCount;i++){
             
                                      _currpos = _currpos + _rowHeight;
                                      _heightCount = _heightCount + _rowHeight;
                                     
                                      //if the the count of height itemschild > than the tree height so stop to add scrollposition
                                      if (_maxHeight < _heightCount ){
                                          break;
                                      }else if (_maxHeight < _currpos){
                                          myTree.verticalScrollPosition = myTree.verticalScrollPosition + 1;
                                      }
                                     
                                  }
                                 
                              }
                         
                         
                      }

           

          Message was edited by: Gus Leo