# Drag with inertia \_xmouse, \_ymouse problem

**URL:** <https://forum.kirupa.com/t/drag-with-inertia--xmouse--ymouse-problem/246539>\
**Category:** flash\
**Created:** [December 12, 2007, 3:43am UTC](https://forum.kirupa.com/t/drag-with-inertia--xmouse--ymouse-problem/246539 "2007-12-12T03:43:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![expansion17](https://avatars.discourse-cdn.com/v4/letter/e/c57346/32.png) [@expansion17](https://forum.kirupa.com/u/expansion17)\
**Post date:** [December 12, 2007, 3:43am UTC](https://forum.kirupa.com/t/drag-with-inertia--xmouse--ymouse-problem/246539/1 "2007-12-12T03:43:38Z")

</div>

I grabbed this script from [senocular.com](http://senocular.com) and modified it to suit what I am doing, which is creating draggable mc’s that slide after the mouse is release.  
The problem I am having, and can’t seem to solve, is that when you click on the mc it sets the \_ x and \_y to \_xmouse and \_ymouse. It is because of this part of the script:

\_x = \_parent.\_xmouse  
\_y = \_parent.\_ymouse

I really want it to act the same as the startDrag function, where the mc doesn’t reset its \_x and \_y coords to \_xmouse \_ymouse. If you modify it to be

\_x = \_parent.\_xmouse - \_x

I dunno how to record and execute the offset… I assume that will be the answer.

Please help  
Cheers  
Barton

Attach Code:  
on(press){  
vector = [-\_xmouse_2, \_ymouse_2.5]  
}else{  
thisPos = [\_x,\_y]  
dragging = true  
}  
}

onClipEvent(load){  
type = “throw”  
bounds = {left: 0, right: 1280-image.\_width\*2, up: 0, down: 768}  
vector = [0,0];

}  
onClipEvent(enterFrame) {  
if (dragging) {  
\_x = \_parent.\_xmouse  
\_y = \_parent.\_ymouse  
lastPos = thisPos  
thisPos = [\_x,\_y]  
dragVector = [thisPos[0]-lastPos[0],lastPos[1]-thisPos[1]]  
} else {  
\_x += vector[0]  
\_y -= vector[1]  
…  
…

on(release,releaseOutside){  
dragging = false  
vector = dragVector  
}
