1 Reply Latest reply on Feb 3, 2014 6:21 AM by kglad

    iPhone Scrolling Emulator

    VLJ26

      Could anyone tell me how allow "click and drag" scrolling, simulating the way phones do it. In Flash?

       

      Got an AI file that I want people to be able to scroll through on a iphone screen border, but having trouble working out how to get the scroll to work.

       

      Also, I'm very new to flash so If anyone knows, please please put it in the simplist most idiot proof way.

       

      Thanks

        • 1. Re: iPhone Scrolling Emulator
          kglad Adobe Community Professional & MVP

          there is no simple way to emulate the scrolling and you can't use as2 to create an iphone app.  here's the code in as3 just to show the complexity of emulating the easing and bounce:

           

          private function listTouchBeginF(e:TouchEvent):void{

                      if(this.listP.height>this.mask_mc.height){

                          stage.addEventListener(TouchEvent.TOUCH_END,listTouchEndF,false,0,true);

                          if(!this.listP.cacheAsBitmap){

                              this.listP.cacheAsBitmap = true;

                          }

                          // 150 and 300 are to allow drag beyond listP borders and allow tween back to borders.

                          dragRect.y = this.mask_mc.y-this.listP.height+this.mask_mc.height-150;

                          dragRect.height = this.listP.height-this.mask_mc.height+300;

                          this.listP.startTouchDrag(e.touchPointID,false,dragRect);

                          //startDragY = this.listP.y;

                          //startDragTime = getTimer();

                          this.listP.addEventListener(Event.ENTER_FRAME,listTouchMoveF,false,0,true);

                      }

                  }

                  private function listTouchMoveF(e:Event):void{

                      startDragY = this.listP.y;

                      startDragTime = getTimer();

                  }

                  private function listTouchEndF(e:TouchEvent):void{

                      stage.removeEventListener(TouchEvent.TOUCH_END,listTouchEndF,false);

                      this.listP.removeEventListener(Event.ENTER_FRAME,listTouchMoveF,false);

                      this.listP.stopTouchDrag(e.touchPointID);

                      dragTime = getTimer()-startDragTime;

                      // predict end point, duration.  if abs <500, converge slowly.  if abs>900, converge quickly

                      velocity = 1000*(this.listP.y-startDragY)/dragTime;

                     

                      if(velocity>0){

                          // lowerLimit = this.mask_mc.y, assigned in init()

                          endY = Math.min(lowerLimit,this.listP.y+velocity);

                      } else if(velocity<0){

                          // this.listP.height changes depending on expanded/contracted titles

                          upperLimit = this.mask_mc.y+this.mask_mc.height-this.listP.height;

                          endY = Math.max(upperLimit,this.listP.y+velocity);

                      } else {

                          // velocity = 0;

                          upperLimit = this.mask_mc.y+this.mask_mc.height-this.listP.height;

                          endY = Math.min(lowerLimit,this.listP.y);

                          endY = Math.max(upperLimit,endY);

                      }

                      //trace(velocity,this.listP.y,endY,upperLimit)

                     

                      if( (velocity>=0 && endY==lowerLimit) || (velocity<=0 && endY==upperLimit) ){

                          duration = 1;

                          TweenLite.to(this.listP,duration,{y:endY,ease:Quint.easeOut});

                      } else {

                          duration = (endY-this.listP.y)/velocity;

                          TweenLite.to(this.listP,duration,{y:endY,ease:Quint.easeOut});

                      }

                  }