# Drag & Drop Problem

**URL:** <https://forum.kirupa.com/t/drag-drop-problem/306628>\
**Category:** Uncategorized\
**Created:** [March 18, 2010, 4:08pm UTC](https://forum.kirupa.com/t/drag-drop-problem/306628 "2010-03-18T16:08:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SLaY](https://avatars.discourse-cdn.com/v4/letter/s/ac91a4/32.png) [@SLaY](https://forum.kirupa.com/u/SLaY)\
**Post date:** [March 18, 2010, 4:08pm UTC](https://forum.kirupa.com/t/drag-drop-problem/306628/1 "2010-03-18T16:08:08Z")

</div>

Hey ppl I have a problem with drag & drop!

See this example in my attachment, when I drag the blue box to the yellow one or to whatever on stage it goes back to the initial position, it’s ok! But when i drag it to the red box (which is also a dragable object) they change positions ! Why does it happen ?

Here’s the code:

```auto

box1.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
box2.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);

box1.addEventListener(MouseEvent.MOUSE_UP, dropIt1);
box2.addEventListener(MouseEvent.MOUSE_UP, dropIt2);
var startX:Number;
var startY:Number;

function pickUp(event:MouseEvent):void {
	event.target.startDrag();
	startX = event.target.x;
	startY = event.target.y;
}

function dropIt1(event:MouseEvent):void
{

		if(box1.hitTestObject(hit))
	{
		event.target.x = startX;
		event.target.y = startY;
		event.target.stopDrag();	
	}
	

    else{		
		event.target.x = startX;
		event.target.y = startY;
		event.target.stopDrag();	
	}
		
		
}

function dropIt2(event:MouseEvent):void
{
	
		if(box2.hitTestObject(hit))
	{
		event.target.x = startX;
		event.target.y = startY;
		event.target.stopDrag();	
	}
	

    else{		
		event.target.x = startX;
		event.target.y = startY;
		event.target.stopDrag();	
	}
		
		
}

```

tks for the help
