# Drag with easing

**URL:** <https://forum.kirupa.com/t/drag-with-easing/205658>\
**Category:** Uncategorized\
**Created:** [October 31, 2006, 7:15pm UTC](https://forum.kirupa.com/t/drag-with-easing/205658 "2006-10-31T19:15:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bill\_Blast](https://avatars.discourse-cdn.com/v4/letter/b/b38774/32.png) [@Bill\_Blast](https://forum.kirupa.com/u/Bill_Blast)\
**Post date:** [October 31, 2006, 7:15pm UTC](https://forum.kirupa.com/t/drag-with-easing/205658/1 "2006-10-31T19:15:14Z")

</div>

I’d like to create a movie clip that can be dragged around a stage but when the user releases the mouse, I want the mc to ease out in the direction the person dragged it rather than just a hard drop! Hope you all can figure out what I mean.

Anyway, I’ve pretty much sorted out the code for that part:

\_root.myMC.ease = 2;  
\_root.myMC.onPress = function() {  
this.drag = true;  
}  
\_root.myMC.onEnterFrame = function() {  
if (this.drag == true) {  
this.targX = \_root.\_xmouse;  
this.targY = \_root.\_ymouse;  
}  
if (this.\_x != this.targX | this.\_y != this.targY) {  
this.\_x += (this.targX-this.\_x)/this.ease;  
this.\_y += (this.targY-this.\_y)/this.ease;  
}  
}  
\_root.myMC.onMouseUp = function() {  
this.drag = false;  
}

MY PROBLEM:  
The problem is the starting position of the mc. Everytime I test the movie, the drag-able mc moves to the top left corner of the stage. Why is this happening? How can I define the starting position for the drag-able mc?

Also, how can I constrain the mc to a specific boundry, I just realised that it is possible to throw the mc off the visible part of the stage (not good hehe).

I’ve attached the file.

Thanks guys!
