2 Replies Latest reply on Dec 18, 2010 1:07 PM by Shongrunden

    How to position content in a scroller by dragging content?

    Handycam Level 1

      I have a scroller with an image that is oversized.

       

      <s:Group id="clipWindow" width="720" height="480">
      <s:Scroller top="0" left="0" bottom="0" right="0">
           <s:Group id="bgimg" scaleX="{scaleSlider.value}" scaleY="{scaleSlider.value}">
                <local:BackgroundImage id="bg" />
           </s:Group>
      </s:Scroller>
      </s:Group>
      

       

      I'd like to allow the user to position the image by simply dragging it, instead of scrollbars.

       

      Can someone point me to how this is accomplished?

        • 1. Re: How to position content in a scroller by dragging content?
          Handycam Level 1

          I found this, but the scroller does not move.  I jumps like it is going to, but it snaps right back immediately:

          //in creation complete handler:
          bgimg.addEventListener(MouseEvent.MOUSE_DOWN,handleMouseDown);
          bgimg.addEventListener(MouseEvent.MOUSE_MOVE,handleMouseMove);
          
          
          
          
          
          
          private var mouseDownPositionX:Number = 0;
          private var mouseDownPositionY:Number = 0;
          
          
          private function handleMouseDown(event:MouseEvent):void {
               trace("mouse down");
               mouseDownPositionY = event.stageY;
               mouseDownPositionX = event.stageX;
          }
          
          private function handleMouseMove(event:MouseEvent):void {
               if (event.buttonDown){
                    // increment the scroll positions of the viewport
                    bgimg.verticalScrollPosition += (mouseDownPositionY - event.stageY);
                    bgimg.horizontalScrollPosition += (mouseDownPositionX - event.stageX);
                    
                    // update the mouse down position
                    mouseDownPositionY = event.stageY;
                    mouseDownPositionX = event.stageX;
               }
          }
          

          • 2. Re: How to position content in a scroller by dragging content?
            Shongrunden Adobe Employee

            I don't think you can set scaleX/scaleY on the viewport of a Scroller.  If I remove that this seems to work ok.