Hi. I need to reposition the slider on a scrollbar programatically (not move the scrollbar, just the slider; i.e. reset it to top or left, etc.). Anybody figured this out? TIA- Perflexed
+3
A:
I was going to mention programmatic skinning, but on second thought, it sounds like what you're trying to do is just set the scroll position of the component. Is that right? If so, it depends on what kind of control you're using, and what kind of scrollig you want to do (e.g., to an item in a list, or just to a horizontal or vertical position):
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
private function scrollToIndex():void
{
ls.scrollToIndex(15);
}
private function scrollToPoint():void
{
cv.verticalScrollPosition += 20;
}
]]>
</mx:Script>
<mx:VBox width="300">
<mx:List id="ls" width="100%" rowCount="5">
<mx:dataProvider>
<mx:Array>
<mx:String>Item 1</mx:String>
<mx:String>Item 2</mx:String>
<mx:String>Item 3</mx:String>
<mx:String>Item 4</mx:String>
<mx:String>Item 5</mx:String>
<mx:String>Item 6</mx:String>
<mx:String>Item 7</mx:String>
<mx:String>Item 8</mx:String>
<mx:String>Item 9</mx:String>
<mx:String>Item 10</mx:String>
<mx:String>Item 11</mx:String>
<mx:String>Item 12</mx:String>
<mx:String>Item 13</mx:String>
<mx:String>Item 14</mx:String>
<mx:String>Item 15</mx:String>
<mx:String>Item 16</mx:String>
<mx:String>Item 17</mx:String>
<mx:String>Item 18</mx:String>
<mx:String>Item 19</mx:String>
<mx:String>Item 20</mx:String>
</mx:Array>
</mx:dataProvider>
</mx:List>
<mx:Button label="Scroll" click="scrollToIndex()" />
<mx:Canvas id="cv" width="100%" height="200">
<mx:TextArea width="100%" height="600" verticalScrollPolicy="off">
<mx:text>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
</mx:text>
</mx:TextArea>
</mx:Canvas>
<mx:Button label="Scroll" click="scrollToPoint()" />
</mx:VBox>
</mx:Application>
The verticalScrollPosition and horizontalScrollPosition properties (available on all implementations of the Container class), and the scrollToIndex method (for lists) are probably what you're looking for. This example illustrates both. Hope it helps!
Christian Nunciato
2009-01-22 05:26:50
Thanks, Christian. Problem solved.
Bob Spidell
2009-01-22 17:29:33
Awesome, glad it worked out for ya.
Christian Nunciato
2009-01-22 18:23:39