# How to get the position of the movieclip after dragging by mouse

**URL:** <https://forum.kirupa.com/t/how-to-get-the-position-of-the-movieclip-after-dragging-by-mouse/29217>\
**Category:** flash\
**Created:** [August 24, 2003, 10:30am UTC](https://forum.kirupa.com/t/how-to-get-the-position-of-the-movieclip-after-dragging-by-mouse/29217 "2003-08-24T10:30:26Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![SBUH](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@SBUH](https://forum.kirupa.com/u/SBUH)\
**Post date:** [August 24, 2003, 10:30am UTC](https://forum.kirupa.com/t/how-to-get-the-position-of-the-movieclip-after-dragging-by-mouse/29217/1 "2003-08-24T10:30:26Z")

</div>

I have code like  
on (press) {  
startDrag(screen);  
}

on (release) {  
stopDrag();  
x\_value1=\_root.screen.\_x;  
y\_value1=\_root.screen.\_y;  
trace(x\_value1);  
trace(y\_value1);

}

But I found after dragging, x\_value1 and y\_value1 are always the initial value. So what is the right way to record the position then? thanks in advance !

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 24, 2003, 10:53am UTC](https://forum.kirupa.com/t/how-to-get-the-position-of-the-movieclip-after-dragging-by-mouse/29217/2 "2003-08-24T10:53:21Z")

</div>

I used

[AS]  
on (press) {  
startDrag(\_root.screen);  
}

on (release) {  
stopDrag();  
x\_value1=\_root.screen.\_x;  
y\_value1=\_root.screen.\_y;  
trace(x\_value1);  
trace(y\_value1);

}[/AS]

and it worked fine for me …

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 24, 2003, 11:07am UTC](https://forum.kirupa.com/t/how-to-get-the-position-of-the-movieclip-after-dragging-by-mouse/29217/3 "2003-08-24T11:07:59Z")

</div>

Thanks for that \_root.screen.

Actually, I want to record different position of movieclip when the button is clicked.

There are two buttons as front, back. I would like to when the front button is clicked. Drag the movieclip and record its position, then when I pressed the front button again, the position should still be there.

So I have something for the movieclip like  
on (press) {  
startDrag(\_root.screen);  
}

on (release) {  
stopDrag();  
}

onClipEvent (mouseUp) {

```
switch (state) {
case 1 :
	x_value1 = _root.screen._x;
	y_value1 = _root.screen._y;
	trace(_root.x_value1);
	trace(_root.y_value1);
	break;
case 2 :
	x_value2 = _root.screen._x;
	y_value2 = _root.screen._y;
	trace(_root.x_value2);
	trace(_root.y_value2);
	
	break;

```

}

Then for the front button,  
on (release)  
{  
\_root.screen.\_x=x\_value1;  
\_root.screen.\_y=y\_value1;

}  
for the back button,

on (release)  
{  
\_root.screen.\_x=x\_value1;  
\_root.screen.\_y=y\_value1;

}

But every time, when I click the front button again, the movieclip is at the initial position but not the position where I dragged.

What should I modify then. Do u have some good suggestion. Thanks much in advance!!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 24, 2003, 11:29am UTC](https://forum.kirupa.com/t/how-to-get-the-position-of-the-movieclip-after-dragging-by-mouse/29217/4 "2003-08-24T11:29:27Z")

</div>

I don’t get it :hair: Can you please explain more ?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 24, 2003, 11:39am UTC](https://forum.kirupa.com/t/how-to-get-the-position-of-the-movieclip-after-dragging-by-mouse/29217/5 "2003-08-24T11:39:02Z")

</div>

Hello, it is like this,

input textfield output textfieldinMovieclip

```
                                           front_btn back_btn

```

When I click the front\_btn, I write the text and drag it by mouse. And after I click the front\_btn again, the output textfield should still stay there.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 24, 2003, 11:43am UTC](https://forum.kirupa.com/t/how-to-get-the-position-of-the-movieclip-after-dragging-by-mouse/29217/6 "2003-08-24T11:43:15Z")

</div>

for the movieclip  
on (press) {  
startDrag(\_root.screen);  
}

on (release) {

```
if(_root.state==1) {
	
	x_value1 = _root.screen._x;
	y_value1 = _root.screen._y;
	trace(_root.x_value1);
	trace(_root.y_value1);
	stopDrag();
	
}
else if(_root.state==2) {
	stopDrag();
	x_value2 = _root.screen._x;
	y_value2 = _root.screen._y;
	trace(_root.x_value2);
	trace(_root.y_value2);
}

```

}

And for the front button, I have  
on (release)  
{  
\_root.state =1;  
\_root.screen.\_x=\_root.x\_value1;  
\_root.screen.\_y=\_root.y\_value1;  
}

for the back button I have  
on (release)  
{  
\_root.state =2;  
\_root.screen.\_x=\_root.x\_value2;  
\_root.screen.\_y=\_root.y\_value2;  
}

But again, the trace output of the \_x and \_y value are the initial value. What should I do then ? Am I made myself clear? Thanks !

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 24, 2003, 11:47am UTC](https://forum.kirupa.com/t/how-to-get-the-position-of-the-movieclip-after-dragging-by-mouse/29217/7 "2003-08-24T11:47:16Z")

</div>

No, I still don’t get it. I’m so confused !

What’s with the textfields !? Two minutes ago it was a screen !  
What is the back button supposed to do ?  
What should be written inside the two boxes ?  
Which text should you drag ?  
…

Please provide the FLA so I can have a look and maybe understand what you mean.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 24, 2003, 11:52am UTC](https://forum.kirupa.com/t/how-to-get-the-position-of-the-movieclip-after-dragging-by-mouse/29217/8 "2003-08-24T11:52:41Z")

</div>

You can try to input data when different button is clicked, e.g when front is clicked, or when back is clicked. You will see that the position of the screen is the same no matter what I dragged.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 24, 2003, 12:39pm UTC](https://forum.kirupa.com/t/how-to-get-the-position-of-the-movieclip-after-dragging-by-mouse/29217/9 "2003-08-24T12:39:52Z")

</div>

I don’t get what you are trying to accomplish here at all. Really, I don’t. Sorry man, but I am unable to help you.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 24, 2003, 12:41pm UTC](https://forum.kirupa.com/t/how-to-get-the-position-of-the-movieclip-after-dragging-by-mouse/29217/10 "2003-08-24T12:41:17Z")

</div>

Thanks anyway!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 24, 2003, 1:04pm UTC](https://forum.kirupa.com/t/how-to-get-the-position-of-the-movieclip-after-dragging-by-mouse/29217/11 "2003-08-24T13:04:46Z")

</div>

i don’t understand why you want to have a front and a back button, but have a look at my example. maybe this is in the lines of what you are looking for.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 24, 2003, 5:12pm UTC](https://forum.kirupa.com/t/how-to-get-the-position-of-the-movieclip-after-dragging-by-mouse/29217/12 "2003-08-24T17:12:55Z")

</div>

Thanks indeed for your code. That is much helpful! I do appreciate. Although it is not exactly the same, it gives me idea about that. Thanks again! Regards!
