10 Replies Latest reply on Oct 26, 2016 9:14 PM by kglad

    How can I make an MC dragging smoother by using "ease"?

    noppanatp30620432

      I have a dragging mc call "box"

       

      It can be drag but not very smooth. How can I make it a smooth drag by using "var ease".

       

      I try to put anywhere but not work.

       

      Anyone help me please.

       

      Here is my code.

       

       

      var topY:int = stage.stageHeight - box.height;

      var botY:int = 0;

      var ease:int = 6; // this is what I need to insert into the code below

       

      box.addEventListener(MouseEvent.MOUSE_DOWN, onDown);

      box.addEventListener(MouseEvent.MOUSE_UP, onUp);

      var constrainY:Rectangle = new Rectangle(box.x, topY ,0, box.y+ (box.height-stage.stageHeight)  );

      var dragxy:String = "";

      function onDown(e:MouseEvent):void

      {

          dragxy = mouseX + "_" + mouseY;

          e.currentTarget.startDrag(false, constrainY);

          removeEventListener(MouseEvent.MOUSE_DOWN, onDown);

          addEventListener(MouseEvent.MOUSE_UP, onUp);

      }

      function onUp(e:MouseEvent):void

      {

          e.currentTarget.stopDrag();

          addEventListener(MouseEvent.MOUSE_DOWN, onDown);

          removeEventListener(MouseEvent.MOUSE_UP, onUp);

      }

        • 1. Re: How can I make an MC dragging smoother by using "ease"?
          kglad Adobe Community Professional & MVP

          easing should play no role in dragging.  it's not what users expect unless you want to use easing when dragging is stopped.

           

          to smooth your dragging there are several things you can do.  in general the best is to enable cacheAsBitmap for your dragged object:

           

           

           

          var topY:int = stage.stageHeight - box.height;

          var botY:int = 0;

          var ease:int = 6; // this is what I need to insert into the code below

           

          box.cacheAsBitmap=true;

          box.addEventListener(MouseEvent.MOUSE_DOWN, onDown);

          box.addEventListener(MouseEvent.MOUSE_UP, onUp);

          var constrainY:Rectangle = new Rectangle(box.x, topY ,0, box.y+ (box.height-stage.stageHeight) );

          var dragxy:String = "";

          function onDown(e:MouseEvent):void

          {

          dragxy = mouseX + "_" + mouseY;

          e.currentTarget.startDrag(false, constrainY);

          removeEventListener(MouseEvent.MOUSE_DOWN, onDown);

          addEventListener(MouseEvent.MOUSE_UP, onUp);

          }

          function onUp(e:MouseEvent):void

          {

          e.currentTarget.stopDrag();

          addEventListener(MouseEvent.MOUSE_DOWN, onDown);

          removeEventListener(MouseEvent.MOUSE_UP, onUp);

          }

          • 2. Re: How can I make an MC dragging smoother by using "ease"?
            ClayUUID Adobe Community Professional

            First, you don't.

             

            Second, you don't.

             

            While it would be fairly trivial to average out the mouse movement to smooth a drag motion, this would be a wrong, terrible thing to do because it would make your interaction feel sluggish and laggy. Users would hate it. The proper way to make dragging feel more smooth is to increase the frame rate.

            • 3. Re: How can I make an MC dragging smoother by using "ease"?
              noppanatp30620432 Level 1

              Umm..What I meant here is " How can I make the dragging mc move slower than the mouse. The mouse go first  then follow by the dragging mc. Not go together at the same time.

              • 4. Re: How can I make an MC dragging smoother by using "ease"?
                kglad Adobe Community Professional & MVP

                that's a questionable idea, but you could use:

                 

                var speed:Number = .5;  // adjust as you want. close to 1, faster; closer to 0, slower

                 

                var topY:int = stage.stageHeight - box.height;

                var botY:int = 0;

                var ease:int = 6; // this is what I need to insert into the code below

                var dragged_mc:MovieClip;

                 

                box.cacheAsBitmap=true;

                box.addEventListener(MouseEvent.MOUSE_DOWN, onDown);

                box.addEventListener(MouseEvent.MOUSE_UP, onUp);

                var constrainY:Rectangle = new Rectangle(box.x, topY ,0, box.y+ (box.height-stage.stageHeight) );

                var dragxy:String = "";

                function onDown(e:MouseEvent):void

                {

                dragxy = mouseX + "_" + mouseY;

                // e.currentTarget.startDrag(false, constrainY);

                dragged_mc=MovieClip(e.currentTarget);

                removeEventListener(MouseEvent.MOUSE_DOWN, onDown);

                addEventListener(Event.ENTER_FRAME,loopF);

                addEventListener(MouseEvent.MOUSE_UP, onUp);

                }

                function loopF(e:Event):void{

                // if there were contraints, add here

                dragged_mc.x = speed*mouseX+(1-speed)*dragged_mc.x;

                dragged_mc.y = speed*mouseY+(1-speed)*dragged_mc.y

                }

                function onUp(e:MouseEvent):void

                {

                // e.currentTarget.stopDrag();

                removeEventListener(Event.ENTER_FRAME,loopF);

                addEventListener(MouseEvent.MOUSE_DOWN, onDown);

                removeEventListener(MouseEvent.MOUSE_UP, onUp);

                }

                • 5. Re: How can I make an MC dragging smoother by using "ease"?
                  noppanatp30620432 Level 1

                  Thank you KGLAD. But what I want is press the box mc and drag box mc up and down. And how far it can be draged is specify here "var constrainY:Rectangle = new Rectangle(box.x, topY ,0, box.y+ (box.height-stage.stageHeight) );"

                  • 6. Re: How can I make an MC dragging smoother by using "ease"?
                    kglad Adobe Community Professional & MVP

                    i said, add those constraints in loopF

                    • 7. Re: How can I make an MC dragging smoother by using "ease"?
                      noppanatp30620432 Level 1

                      Please show me the way. I'm really new to coding.

                      • 8. Re: How can I make an MC dragging smoother by using "ease"?
                        kglad Adobe Community Professional & MVP

                        :

                         

                        kglad wrote:

                         

                        that's a questionable idea, but you could use:

                         

                        var speed:Number = .5; // adjust as you want. close to 1, faster; closer to 0, slower

                         

                        var topY:int = stage.stageHeight - box.height;

                        var botY:int = 0;

                        var ease:int = 6; // this is what I need to insert into the code below

                        var dragged_mc:MovieClip;

                         

                        box.cacheAsBitmap=true;

                        box.origY = box.y;

                        box.addEventListener(MouseEvent.MOUSE_DOWN, onDown);

                        box.addEventListener(MouseEvent.MOUSE_UP, onUp);

                        var constrainY:Rectangle = new Rectangle(box.x, topY ,0, box.y+ (box.height-stage.stageHeight) );

                        var dragxy:String = "";

                        function onDown(e:MouseEvent):void

                        {

                        dragxy = mouseX + "_" + mouseY;

                        // e.currentTarget.startDrag(false, constrainY);

                        dragged_mc=MovieClip(e.currentTarget);

                        removeEventListener(MouseEvent.MOUSE_DOWN, onDown);

                        addEventListener(Event.ENTER_FRAME,loopF);

                        addEventListener(MouseEvent.MOUSE_UP, onUp);

                        }

                        function loopF(e:Event):void{

                        // if there were contraints, add here

                        //dragged_mc.x = speed*mouseX+(1-speed)*dragged_mc.x;

                        dragged_mc.y = speed*mouseY+(1-speed)*dragged_mc.y;

                        if(dragged_mc.y<box.origY){

                        dragged_mc.y=box.origY;

                        } else if(dragged_mc.y>stage.stageHeight-dragged_mc.height){

                        dragged_mc.y=stage.stageHeight-dragged_mc.height

                        }

                        }

                        function onUp(e:MouseEvent):void

                        {

                        // e.currentTarget.stopDrag();

                        removeEventListener(Event.ENTER_FRAME,loopF);

                        addEventListener(MouseEvent.MOUSE_DOWN, onDown);

                        removeEventListener(MouseEvent.MOUSE_UP, onUp);

                        }

                        • 9. Re: How can I make an MC dragging smoother by using "ease"?
                          noppanatp30620432 Level 1

                          Thank you very much for your help, but it is not working.

                          • 10. Re: How can I make an MC dragging smoother by using "ease"?
                            kglad Adobe Community Professional & MVP

                            what's not working?

                             

                            here it is working: drag_ease