# Drag n' drop problems (script inside)

**URL:** https://forum.kirupa.com/t/drag-n-drop-problems-script-inside/65266
**Category:** flash
**Created:** [September 24, 2004, 2:53pm UTC](https://forum.kirupa.com/t/drag-n-drop-problems-script-inside/65266 "2004-09-24T14:53:58Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![EricLanteigne](https://avatars.discourse-cdn.com/v4/letter/e/b5ac83/32.png) [@EricLanteigne](https://forum.kirupa.com/u/EricLanteigne)
#### Post date: [September 24, 2004, 2:53pm UTC](https://forum.kirupa.com/t/drag-n-drop-problems-script-inside/65266/1 "2004-09-24T14:53:58Z")

</div>

[font=Arial]Hi all!

I have a problem with my drageable object when the users drag the object outside the limit of the Flash stage in a HTML page. It seem like it lose it’s \_.x and .\_y coordonates. It will followed the cursor when it returns to the stage but it can be drop anywhere on the stage after that.

Anybody have a solution to how I could detect when the piece is going outside the stage and make it return to its original place?

Here’s the script on my object :

on (press) {  
this.startX = this.\_x;  
this.startY = this.\_y;  
this.startDrag();  
}  
on (release) {  
this.stopDrag();  
if (getProperty("/b", \_droptarget) eq “/b1”) {  
this.\_x = eval(this.\_droptarget).\_x+0;  
this.\_y = eval(this.\_droptarget).\_y;  
} else {  
this.\_x = this.startX;  
this.\_y = this.startY;  
}  
}

Here’s the Flash movie in question : [/font][[font=Tahoma][color=#004477]Drag Drop Flash Movie[/color][/font]](http://www10.brinkster.com/EricLanteigne/FlashProblem.htm)

[font=Arial]Do you have a better way to script an drag n’ drop object that doesnt need absolute positioning?

Thanks,  
Eric Lanteigne [/font]

---

<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: [September 24, 2004, 3:09pm UTC](https://forum.kirupa.com/t/drag-n-drop-problems-script-inside/65266/2 "2004-09-24T15:09:15Z")

</div>

instead of just

this.startDrag();

put:

this.startDrag(true, 10, 10, 10, 10),

the numbers go in order (left, top, right bottom)

It constrains where you can drag your movie clip to on the stage,

You will have to adjust your numbers, I just put 10 for all of them in this example. Hope this helps.

---

<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: [September 24, 2004, 3:59pm UTC](https://forum.kirupa.com/t/drag-n-drop-problems-script-inside/65266/3 "2004-09-24T15:59:44Z")

</div>

> [@Gumby19](#):
>
> instead of just
> 
> this.startDrag();
> 
> put:
> 
> this.startDrag(true, 10, 10, 10, 10),
> 
> the numbers go in order (left, top, right bottom)
> 
> It constrains where you can drag your movie clip to on the stage,
> 
> You will have to adjust your numbers, I just put 10 for all of them in this example. Hope this helps.

Thank you!

Eric

---

<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: [September 24, 2004, 4:12pm UTC](https://forum.kirupa.com/t/drag-n-drop-problems-script-inside/65266/4 "2004-09-24T16:12:57Z")

</div>

you say you think it’s losing it’s \_x and \_y vars when the mouse is off of the flash movie… that is exactly what is happening 🙂

---

<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: [September 24, 2004, 4:25pm UTC](https://forum.kirupa.com/t/drag-n-drop-problems-script-inside/65266/5 "2004-09-24T16:25:26Z")

</div>

> [@cyberathlete](#):
>
> you say you think it’s losing it’s \_x and \_y vars when the mouse is off of the flash movie… that is exactly what is happening 🙂

I still have some questions 🙂 :

EDIT : It’s weird, if I set the first parameter to true, when I click on my MC, there’s an offset with my cursor. Is there a way to get rid of that mouse/MC offset? If I use false, everything work fine except if I drop my MC on another MC. The cursor still have the focus on the MC and moving it, it can be dropped anywhere. :S

Why does my MC still get outside the stage but only from the left position? The others border works fine but the left positioning is not working when I put 0 for value.

If my Flash movie is 750x270 and I want a 10 px margin from everyside, what are the value parameter, I should use? It seem like wider MC still goes outside. Does it have anything to do with the rotating point (center) of my MC? All my MC are not the same size.

Thanks,  
Eric

---

<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: [September 24, 2004, 8:50pm UTC](https://forum.kirupa.com/t/drag-n-drop-problems-script-inside/65266/6 "2004-09-24T20:50:05Z")

</div>

could you upload the fla? it would be easier to see what’s going on if you did. 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: [September 27, 2004, 11:25am UTC](https://forum.kirupa.com/t/drag-n-drop-problems-script-inside/65266/7 "2004-09-27T11:25:10Z")

</div>

> [@cyberathlete](#):
>
> could you upload the fla? it would be easier to see what’s going on if you did. thanks

[www.ericlanteigne.ca/1-3-9 (750x270).fla]([http://www.ericlanteigne.ca/1-3-9](http://www.ericlanteigne.ca/1-3-9) (750x270).fla)

Another link : [http://www10.brinkster.com/EricLanteigne/1-3-9%20(750x270).fla](http://www10.brinkster.com/EricLanteigne/1-3-9%20(750x270).fla)

Can somebody help me 🙂

Thanks,  
Eric

---

<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: [September 27, 2004, 12:55pm UTC](https://forum.kirupa.com/t/drag-n-drop-problems-script-inside/65266/8 "2004-09-27T12:55:17Z")

</div>

It won’t let me access the file. I don’t know if it is my computer or not. Is anybody else able to access this file??

---

<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: [September 27, 2004, 1:33pm UTC](https://forum.kirupa.com/t/drag-n-drop-problems-script-inside/65266/9 "2004-09-27T13:33:08Z")

</div>

> [@Gumby19](#):
>
> It won’t let me access the file. I don’t know if it is my computer or not. Is anybody else able to access this file??

It must be Brinkster causing this problem ☹ Wait i’m gonna create a page for downloading it.

Fixed : [http://www10.brinkster.com/EricLanteigne/1-3-9.html](http://www10.brinkster.com/EricLanteigne/1-3-9.html)

My biggest problem now is when my MC is dragged over another draggeable MC or over an already placed MC in my table.
