3 Replies Latest reply on Sep 13, 2017 7:38 AM by kglad

    Draggable object jumps down away from mouse - Adobe Animate cc using Javascript

    keelym35886708 Level 1

      Hi there,

       

      I'm working on a project in Adobe Animate cc 2017 where I have a movieclip that I'd like to drag along the Y axis using the mouse. I was able to get a draggable object within a bounding box with the help I received on an earlier forum post - Createjs - dragging an object within a bounding box . I didn't notice anything strange with the dragging function then, however now I'm doing a new project which also needs a draggable object and it works, but when I click on the movieclip to drag it, the movieclip will jump down a bit from the mouse - since I'm dragging within a bounding box this becomes an issue when the movieclip jumps down to the bottom of the bounding box and is difficult to drag back up. Any ideas why the movieclip is 'jumping' away from the mouse when I click it on it to drag it? It's like there is some invisible offset between where the mouse is on the stage and the movieclip.

       

      Here is the code I'm using: (my movieclip instance name is 'yoke').

      var yokeHeight = 2; //actually half the height
      
      var bounds = {x:65, y:415, width:220, height:60};
      var yoke = this.yoke;
      
      var sliderBoundary = new createjs.Shape();
      sliderBoundary.graphics.beginStroke("#999")
      .setStrokeStyle(0)
      .drawRect(bounds.x, bounds.y, bounds.width, bounds.height);
      this.stage.addChild(sliderBoundary); 
      
      sliderBoundary.visible = false;
      
      this.yoke.addEventListener("pressmove", fl_MouseClickHandler_2.bind(this));
      function fl_MouseClickHandler_2(evt){
      evt.currentTarget.y = Math.max(bounds.y + yokeHeight, Math.min(bounds.y + bounds.height - yokeHeight, evt.stageY));
      
      }
      
      
      yoke.x = 160;
      yoke.y = bounds.y + bounds.height / 2;
      

       

       

      Any help is much appreciated!

      Thanks.