Flex - overriding scrollToIndex in HorizontalList to animate scrolling

I'm not posting how to do it for list, as that's not what i was working on - but it should be fairly straight forward and should use very similar (if not the same code).

 
override public function scrollToIndex(index:int):Boolean{
//super.scrollToIndex(index);
var newVPos:int;
var newHPos:int;
 
var firstIndex:int = scrollPositionToIndex(horizontalScrollPosition, verticalScrollPosition);
var numItemsVisible:int = ((listItems.length - offscreenExtraRowsTop - offscreenExtraRowsBottom) *
(listItems[0].length - offscreenExtraColumnsLeft - offscreenExtraColumnsRight));
if (index >= firstIndex + numItemsVisible || index < firstIndex)
{
newVPos = Math.min(indexToRow(index), maxVerticalScrollPosition);
newHPos = Math.min(indexToColumn(index), maxHorizontalScrollPosition);
 
try
{
iterator.seek(CursorBookmark.FIRST, scrollPositionToIndex(horizontalScrollPosition, verticalScrollPosition));
//super.horizontalScrollPosition = newHPos;
//super.verticalScrollPosition = newVPos;
 
var p:Parallel = new Parallel(this);
var ap:AnimateProperty = new AnimateProperty(this);
var ap2:AnimateProperty = new AnimateProperty(this);
ap.property = 'verticalScrollPosition';
ap2.property = 'horizontalScrollPosition';
 
ap.toValue = newVPos;
ap2.toValue = newHPos;
 
p.addChild(ap);
p.addChild(ap2);
 
p.play();
 
}
catch(e:ItemPendingError)
{
}
return true;
}
return false;
}
 

Tags: , ,

3 Responses to “Flex - overriding scrollToIndex in HorizontalList to animate scrolling”


  1. » some good tutorial for flex list: Makin … Doing & Done
    on Feb 25th, 2009
    @ 1:20 pm

    [...] Flex - overriding scrollToIndex in HorizontalList to animate scrolling [...]


  2. Mister
    on Mar 4th, 2009
    @ 6:15 pm

    This is very interesting, been trying to get the HorizontalList control to scroll smoothly using external buttons. Your hack is pretty good for scrolling from left to right, but going backwards seems to blow up a bit. I looked at the code but couldn’t see exactly why scrolling back to the start of the list was hanging. Maybe you can post a working example, it could just be my implementation.


  3. Smooth Scrolling HorizontalList — Thanks, Mister!
    on Mar 4th, 2009
    @ 6:19 pm

    [...] Found an interesting post for overriding the scrollToIndex method of the HorizontalList control to allow for animated [...]

Leave a Reply