5 Replies Latest reply on Jul 24, 2011 9:25 AM by Shongrunden

    Spark Scroller, scroller.viewport.horizontalScrollPosition changes after set!

    paulhart83 Level 1



      I have a Spark Scroller object I am trying to work with. The scroller contains a HGroup with the first 3 pages (All the pages are 800 px, the size of my Xoom). So if I scroll to the right 60+ px, I point the "mouseUp" event at endScroll function below. It figures out which page to go to and does animateToPage. The problem I am having is when I set the position to 800 it works the first time. Then when I set it to 0 (back to page 1), it will wind up at some mid point despite me not doing anything. When I trace the position right after I set it to what I want, it says the right location. But when I use a timeout and trace the position 1000 ms later, it states the new position which I am seeing visually (354), but my problem is I didn't enter or change with my finger.


      // ###### START PSUDO CODE #####


      public var pageWin:PageWin; //gets set to first page on init



      private function endScroll(event:MouseEvent):void {


           var currentPage:int = pageWin.pageNum; //use current pg pointer to get its num

           var nextPage:int = currentPage;

           var switchAt:int = 60;

           //pageWin is a pointer which updates to the current page, the x position in the HGroup

           var diff:Number = scroller.viewport.horizontalScrollPosition - pageWin.x;


           if(diff < -switchAt && currentPage > firstPage) { //previous page




           }else if(diff > switchAt && currentPage < lastPage) { //next page









      public function animateToPage(pageNumber:int):void {


           //update pointer to current page

           pageWin = getPageWin(pageNumber);


           //pg 1 = 0, pg 2 = 800, pg 3 = 1600, etc ...

           scroller.viewport.horizontalScrollPosition = pageWin.x;





      //checks HGRoup for a PageWin with the same pageNum and returns it (or null)

      private function getPageWin(pageNum:int):PageWin { .. }



      // ###### END PSUDO CODE #####


      The problem I am having is after setting the horizontalScrollPosition to 800, it all of a sudden bounces back with no interaction from the user to some odd number like 354.


      Why wont it stay where I put it!!!!


      Please help. thanks.