3 Replies Latest reply on Apr 24, 2009 10:32 AM by m_hartnett

    Problem to reset VBox vertlcalScrollBar.scrollPosition

      Hey all,


      I am loosing my hair with a problem I have with a scrollbar.


      Here is my components

          <mx:HBox id="mainContainer"
              verticalScrollPolicy="off"    horizontalScrollPolicy="off"
              paddingLeft="170" paddingTop="207" width="100%" height="100%"
              horizontalAlign="left" verticalAlign="top">
              <mx:VBox name="mainContent" id="mainContent" styleName="listBackground"
                      width="100%" height="100%" verticalGap="10"
                      verticalScrollPolicy="off" horizontalScrollPolicy="off">
                  <mx:HBox width="740" height="26" verticalAlign="top">
                      <mx:Text id="ListTitle" text="{title}"
                          width="100%" styleName="listTitle" selectable="false" color="red" />
                      <mx:Button id="closeBtn" styleName="closeButton" label="Close" buttonMode="true"
                          height="21" click="onCloseClick(event)"/>
                  <mx:VBox id="listContainer" width="740" height="314" verticalScrollBarStyleName="ListScrollBar"
                      verticalScrollPolicy="on" horizontalScrollPolicy="off" verticalGap="2"
                      styleName="postText" />


      listContainer is updated each time the user come back to the page and I would like to reset the scrollbarposition to 0 but It seems like it does not work.

      I have made some trace to check what's happening


      if( listContainer.verticalScrollBar ){
           trace("listContainer.verticalScrollBar "+listContainer.verticalScrollBar.scrollPosition);                     listContainer.verticalScrollBar.scrollPosition =listContainer.verticalScrollBar.minScrollPosition;
           trace("listContainer.verticalScrollBar "+listContainer.verticalScrollBar.scrollPosition);


      and I get this :


      listContainer.verticalScrollBar 168
      listContainer.verticalScrollBar 0


      listContainer.verticalScrollBar 168
      listContainer.verticalScrollBar 0




      Hope someone can help me





        • 1. Re: Problem to reset VBox vertlcalScrollBar.scrollPosition
          m_hartnett Level 3

          if you are trying to manipulate the bar using listContainer.verticalScrollBar.scrollPosition try using the listContainer.verticalScrollPosition instead.

          if that doesn't work it may be a timing issue in event stream and you might want to post your code that does the bar modifications


          Small example that may not be useful.  Also if it is a timing issue you may be able to use the callLater method to delay the movement of the bar until your event processing has completed




















          <?xml version="1.0" encoding="utf-8"?>



          http://www.adobe.com/2006/mxml" layout="vertical"


          100%" height="100%" backgroundColor="#eaf1f6











          private function resetBarPos():void {

          listContainer.verticalScrollPosition = 0;











          <mx:HBox height="26" verticalAlign="top" width="348">



          <mx:Button id="closeBtn0" styleName="closeButton" label="reset bar" buttonMode="true"


          21" click="resetBarPos()"








          <mx:VBox id="listContainer" width="200" height="314" verticalScrollBarStyleName="ListScrollBar"


          on" horizontalScrollPolicy="off" verticalGap="2"





          <mx:Canvas width="200" height="200" backgroundColor="#DB5858">






          <mx:Canvas width="200" height="200" backgroundColor="#92D867">









          • 2. Re: Problem to reset VBox vertlcalScrollBar.scrollPosition
            Level 1

            Thanks very much it fixed it


            So what verticalScrollBar.scrollPosition is for?

            • 3. Re: Problem to reset VBox vertlcalScrollBar.scrollPosition
              m_hartnett Level 3

              the verticalScrollBar is a reference to the scrollBar object of the vBox.

              In fact you can use verticalScrollBar.scrollPosition to manipulate your scroll bar position in a container object though the documentation recommends that you should use the verticalScrollPosition to do this.


              You could replace the verticalScrollPosition with the verticalScrollBar.scrollPosition in the example I gave you and you would see it works.

              In your case I am guessing that there is an event issue you would be dealing with.


              If you were to need a ScrollBar object alone, then you would use the scrollPosition of the object to manipulate the position of the bar.  


              In any case, Adobe recommends that you use the scroll references of the container object to manipulate the scroll properties of either the horizontal or vertical scroll bars.


              Take a look at the api for a Container and read about the properties of the scrollBar and the attributes.