I'm using FB4 and apparently I need to use ensureIndexIsVisible()
to scroll to specific item in my s:List
. Anyway, the code below successfully scrolls to the item but does not scroll it to the top of the list (it's at the bottom, and cut off somewhat). Is there anyway to do that?
MXML:
<s:List id="Schedule" dataProvider="{schedule}" creationComplete="creationCompleteHandler(event)"/>
AS3:
protected function creationCompleteHandler(event:Event):void {
var d:Date = new Date();
var today:String = String((d.month + 1) + "/" + d.date + "/" + d.fullYear);
var dP:XMLListCollection = event.currentTarget.dataProvider;
for(var i:uint; i < dP.length; i++){
if(dP.child("date")[i] == today){
event.currentTarget.ensureIndexIsVisible(i);
}
}
}
Bad solution, but it's work for me
var pt:Point = list.layout.getScrollPositionDeltaToElement(i);
while (pt) {
list.validateNow();
if (pt.y > 0) {
var delta:int = list.layout.getVerticalScrollPositionDelta(NavigationUnit.DOWN);
} else {
delta = list.layout.getVerticalScrollPositionDelta(NavigationUnit.UP);
}
list.layout.verticalScrollPosition += delta;
pt = list.layout.getScrollPositionDeltaToElement(i);
}