# ActionScript 3 Drag and Drop

**URL:** <https://forum.kirupa.com/t/actionscript-3-drag-and-drop/331856>\
**Category:** flash\
**Created:** [November 8, 2013, 4:31pm UTC](https://forum.kirupa.com/t/actionscript-3-drag-and-drop/331856 "2013-11-08T16:31:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Colin7](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@Colin7](https://forum.kirupa.com/u/Colin7)\
**Post date:** [November 8, 2013, 4:31pm UTC](https://forum.kirupa.com/t/actionscript-3-drag-and-drop/331856/1 "2013-11-08T16:31:11Z")

</div>

[COLOR=#000000][FONT=Arial]I have this AS3 code:[/FONT][/COLOR]

```auto

circle_mc.addEventListener([COLOR=#2B91AF]MouseEvent[/COLOR].MOUSE_DOWN, drag);
square_mc.addEventListener([COLOR=#2B91AF]MouseEvent[/COLOR].MOUSE_DOWN, drag);
stage.addEventListener([COLOR=#2B91AF]MouseEvent[/COLOR].MOUSE_UP, drop);

[COLOR=#00008B]function[/COLOR] drag(e:[COLOR=#2B91AF]MouseEvent[/COLOR]):[COLOR=#00008B]void[/COLOR]
{
     e.target.startDrag([COLOR=#00008B]false[/COLOR], [COLOR=#00008B]new[/COLOR] [COLOR=#2B91AF]Rectangle[/COLOR]([COLOR=#800000]30[/COLOR],[COLOR=#800000]30[/COLOR],[COLOR=#800000]150[/COLOR],[COLOR=#800000]150[/COLOR]));
}

[COLOR=#00008B]function[/COLOR] drop(e:[COLOR=#2B91AF]MouseEvent[/COLOR]):[COLOR=#00008B]void[/COLOR]
{
     stopDrag();
}

```

[COLOR=#000000][FONT=Arial]Now, if I test the movie, if I click the circle or the square, they will jump in the stage, because I’m not allowed to move them out of that rectangle.[/FONT][/COLOR]

[LIST=1]  
[_]I want the script to allow me to drag the shapes anywhere (while the MOUSE\_DOWN event is active), but still not allow me to drop them out of it (on MOUSE\_UP).  
[_]How can I use an object instead of that rectangle stage?

[/LIST]
