Trying to get a <s:List> to instantly scroll to the bottom kicked my ass for hours. I tried various hacks. Googled everything I could think of. Learned a lot in the process except how to get a damn <s:List> to scroll to the bottom. Eventually hit upon the perfect solution – search the flexponential.com website. Because if there’s an answer to a tough Flex/Spark question it’s probably there somewhere.
Here’s what Steven Shongrunden at flexponential.com came up with:
private function scrollToBottom():void {
// update the verticalScrollPosition to the end of the List
// virtual layout may require us to validate a few times
var delta:Number = 0;
var count:int = 0;
while (count++ < 10){
chatList.validateNow();
delta = chatList.layout.getVerticalScrollPositionDelta(NavigationUnit.END);
list.layout.verticalScrollPosition += delta;
if (delta == 0)
break;
}
}
Steven is an engineer on the Flex SDK team so it’s not going to get any better than this. Visit Scrolling to the bottom of a spark List to get the details directly from the developers blog. I know this stumped me and a few people on Twitter for a few days so it can’t hurt to give this a little more attention.
Hopefully we’ll have a scrollToBottom method on the <s:List> component someday that will do this without the need for this hack.
And their post on Saving scroll position between views in a mobile Flex Application is also a nice gem to read.




You you could do
list.dataGroup.verticalScrollPosition = list.dataGroup.contentHeight;
Tink recently posted..London Flash Platform User Group January 2012
That’s what I used initially. But it wasn’t reliable. In many instances it just wouldn’t reach the end and it was spotty. The solution that Flexponential has worked without fail, so far.
Because you doing it 10 times and forcing validation 10 times.
Let me look what I have in my ChatList class as it definitely isn’t that heavy.
Tink recently posted..London Flash Platform User Group January 2012
@Tink You did notice that one of the Flex SDK engineers came up with this, right? I think it’s a pretty shitty solution as well but nothing else works reliably.
Ok, thenks
Try what he said too, but it’s not reliable.