views:

113

answers:

1

I have a VBox that I am populating programatically, After a particular event (dragDrop) I do some calculations, reorder some variables, then re-build the VBox. This all works great, but I want the VBox to scroll back to the correct verticalScrollPosition. I tried even the simplest thing:

myVBox.verticalScrollPosition = 200

But I just can't get it to set the scroll position after it's rebuilt. Any ideas?

Edit: per Franky's response I realized that my dragDrop function was calling the rebuilder function then the position setter function back to back, which means it wasn't done being built when it was trying to set. Now I'm passing the position I want the box set to to the rebuilder function which sets the scroll position at the end of building the VBox and everything works out great.

+1  A: 

Try adding this code, I'm at work so I can't verify if it works, hope so:

//Initialize the Vbox
public var myVbox:VBox = new VBox();
//Define the function which rebuilds the Vbox
public function rebuildVbox():VBox{  
myVbox.verticalScrollPosition=200;
return myVbox
}
//Define your event.complete function which sets the verticalScrollPosition  
//after the drag drop
public function setVerticalScrollPosition():void{
    myVbox.addEventListener(Event.COMPLETE,function(event:Event):void{
            rebuildVbox()
            });
    }
Franky
Got it, I don't know if your code works as is or not either since I had to adapt it to my functions anyway. Thanks, you helped me see that I was setting the position in the wrong function.
invertedSpear