tags:

views:

3125

answers:

5

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 possible to auto-scroll to selected item ? Thanks !

+2  A: 

In flex-3 there is a scrollToIndex method and hence you can call

list.scrollToIndex(list.selectedIndex);

I believe this should work in flex-4 too.

Amarghosh
Unfortunately, no. There's no such method in Spark List, but it's there for Halo List component. Flex 4 is evolving and still in Beta, hope this issue will be resolved.
Rodion Bykov
A: 

you'll probably want to access the List's scroller directly and do something like:

list.scroller.scrollRect.y = list.itemRenderer.height * index;

hth

Seth

shi11i
+1  A: 

Try the s:List method : ensureIndexIsVisible(index:int):void

an0nym0usc0ward
Thanks, but it seems working in latest Flex 4 SDK builds only (Flex Builder 4 Beta 2). I realized I work with one of old builds that has no this method yet.
Rodion Bykov
A: 

You can multiply the height of an element by its index and pass this value to: yourListID.scroller.viewport.verticalScrollPositioin Works for me. FTQuest.

FT
A: 

I recently accomplished this in one of my projects by having a defined size for my items in the group..

<s:Scroller x="940" y="0" maxHeight="465" maxWidth="940" horizontalScrollPolicy="off" verticalScrollPolicy="off">
  <s:HGroup  id="tutPane" columnWidth="940" variableColumnWidth="false" gap="0" x="0" y="0">
  </s:HGroup>
</s:Scroller>

Following this my button controls for manipulation worked by incrementing a private "targetindex" variable, then I called a checkAnimation function, which used the Animate class, in combo with a SimpleMotionPath and a comparison between tutpane.firstIndexInView and target index. This modified the "horizontalScrollPosition" of the group.

This allowed separate controls to essentially act as a scroll bar, but I had the requirement of sliding the control to view the selected item.. I believe this technique could work for automated selection of items as well