Well, i thought i would answer myself... I certainly cannot find a 
built in way to automatically scroll to a display object inside a 
VBox.

So, here's my hack at it:

private function scrollObjectIntoView
(vBox:VBox,scrollToObject:DisplayObject):void
{
    var startViewPosition:int   = vBox.verticalScrollPosition;
    var endViewPosition:int     = vBox.verticalScrollPosition + 
vBox.height;                            
    var scrollToObjectPosition:int      = 0;

    // determine intended scroll position of the input DisplayObject
    // just sum up the virtual Y position of the child display object
    for each (var displayObj:DisplayObject in vBox.getChildren())
    {
        if (displayObj == scrollToObject) break;
        scrollToObjectPosition += displayObj.height;
    }

    // is already in view if the scroll to position is 
    // between the start and end current view position
    if (scrollToObjectPosition > startViewPosition && 
scrollToObjectPosition < endViewPosition) return;

    // don't let the scroll to postion be greater than 
    // the max scroll to position, could also use a Math.max here.
    if (scrollToObjectPosition > vBox.maxVerticalScrollPosition) 
        scrollToObjectPosition = vBox.maxVerticalScrollPosition;

    // set the scroll to positin.
    vBox.verticalScrollPosition = scrollToObjectPosition;
}                       




--- In flexcoders@yahoogroups.com, "scott_flex" <[EMAIL PROTECTED]> wrote:
>
> 
> 
> Is there no automatic way to scroll to a particualar child object 
> inside a VBox?
> 
> I'm writing a tool that allows the user to select a child control 
in 
> a vbox, (it get highlighted just like a row in a datagrid) and then 
> give them an up and down arrow to move the object up or down.
> 
> However, when you move a question up (using the vbox's 
setChildIndex 
> method) it's moved up or below the window i want to programatically 
> scroll the selected child into view but only if it needs to.
> 
> Right now i've just writing my own code, basically reading the 
scroll 
> postion of the vertical scroll bar and all the heights of the child 
> object in the vbox.... it's a hack though.
> 
> I think i've see a "scrollIntoView" method somewhere but it's not 
> listed on the VBox ui object.
> 
> Thanks for anyones help.... i could be missing something really 
easy.
>


Reply via email to