Scroll to selected item in Flex 4 Spark List component

前端 未结 12 1462
感动是毒
感动是毒 2020-12-15 17:46

I\'m setting selected element in s:List component with Actionscript, it works, but List doesn\'t scroll to selected item -- need to scroll with scrollbar or mouse. Is it pos

12条回答
  •  醉梦人生
    2020-12-15 18:10

    I saw this basic idea here... http://arthurnn.com/blog/2011/01/12/coverflow-layout-for-flex-4/

    public function scrollGroup( n : int ) : void
    {
        var scrollPoint : Point = theList.layout.getScrollPositionDeltaToElement( n );
        var duration : Number = ( Math.max( scrollPoint.x, theList.layout.target.horizontalScrollPosition ) - Math.min( scrollPoint.x, theList.layout.target.horizontalScrollPosition )) * .01;
        Tweener.addTween(theList.layout,{ horizontalScrollPosition: scrollPoint.x , time:duration});
    }
    protected function theList_caretChangeHandler(event:IndexChangeEvent):void
    {
        scrollGroup( event.newIndex );
        event.target.invalidateDisplayList();
    }
    

提交回复
热议问题