title: Flex Spark List scroll to bottom when new data is added
body: <p>I have a Spark List (<code>spark.components.List</code>) backed by an ArrayCollection for its dataProvider. The List has a vertical scrollbar when there's too many rows to display. What I want is when a new row is added to the List for it to scroll to the bottom to show that new row.</p>
  
  <p>I've tried calling List's <code>ensureIndexIsVisible</code> from a listener on the ArrayCollection. This doesn't work because the List hasn't yet fully rendered the new row. It will either scroll to the second from the last row, or throw the exception:</p>
  
  <pre><code>Error: invalidIndex
   at spark.layouts.supportClasses::LinearLayoutVector/start()[E:\dev\4.0.0\frameworks\projects\spark\src\spark\layouts\supportClasses\LinearLayoutVector.as:893]
   at spark.layouts.supportClasses::LinearLayoutVector/getBounds()[E:\dev\4.0.0\frameworks\projects\spark\src\spark\layouts\supportClasses\LinearLayoutVector.as:1117]
   at spark.layouts::VerticalLayout/getElementBounds()[E:\dev\4.0.0\frameworks\projects\spark\src\spark\layouts\VerticalLayout.as:852]
   at spark.layouts.supportClasses::LayoutBase/http://www.adobe.com/2006/flex/mx/internal::getScrollPositionDeltaToElementHelper()[E:\dev\4.0.0\frameworks\projects\spark\src\spark\layouts\supportClasses\LayoutBase.as:1367]
   at spark.layouts.supportClasses::LayoutBase/getScrollPositionDeltaToElement()[E:\dev\4.0.0\frameworks\projects\spark\src\spark\layouts\supportClasses\LayoutBase.as:1348]
   at spark.components::List/ensureIndexIsVisible()[E:\dev\4.0.0\frameworks\projects\spark\src\spark\components\List.as:2105]
  </code></pre>
  
  <p>I've made sure that my listener is added to the ArrayCollection after setting List's dataProvider. The hope is that I'd be calling <code>ensureIndexIsVisible</code> after the List got a chance to process the new row. My guess is that the List doesn't render the row until some redraw event that occurs later (after I've called <code>ensureIndexIsVisible</code>).</p>
  
  <p>I've also tried specifying a <code>VerticalLayout</code> and setting its <code>verticalScrollPosition</code> to an overly large number (like 99999). This has the same problem - it scrolls to the second from the last row.</p>
  
  <p>So, is there a way to scroll to a newly added row in a Spark List? The only I could find on the Internet is this <a href="http://www.pubbs.net/201002/flex/41604-flexcoders-scroll-to-bottom-on-a-spark-list-when-data-changes.html" rel="nofollow">poorly formatted flexcoders thread</a>.</p>