Scrolling to the end of a Spark List

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.