# Drag and drop question

**URL:** <https://forum.kirupa.com/t/drag-and-drop-question/321478>\
**Category:** Uncategorized\
**Created:** [April 20, 2011, 9:50pm UTC](https://forum.kirupa.com/t/drag-and-drop-question/321478 "2011-04-20T21:50:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kbowk](https://avatars.discourse-cdn.com/v4/letter/k/9de053/32.png) [@kbowk](https://forum.kirupa.com/u/kbowk)\
**Post date:** [April 20, 2011, 9:50pm UTC](https://forum.kirupa.com/t/drag-and-drop-question/321478/1 "2011-04-20T21:50:12Z")

</div>

Hi there,

I used a tutorial to create a drag and drop facility on an application I am working on. This works fine, but I was wondering how I could extend this code to run a function or play a movie clip when all the movie clips are dragged to their correct places. I can’t figure out where in the code I should put this.

Any help would be appreciated, heres my drag and drop code:

```auto
package 
{
	import flash.display.*;
	import flash.events.*;
	import flash.text.*;

	public class BodyLanguageTTD extends Sprite
	{

		var xPos:int;//Stores the initial x position  
		var yPos:int;//Stores the initial y position  
		
		public function BodyLanguageTTD()
		{

			addEventListener(Event.ADDED_TO_STAGE, addedHandler);
			addEventListener(Event.REMOVED_FROM_STAGE, removedHandler);
			

		}
		private function addedHandler(event:Event):void
		{

			this.x = stage.stageWidth / 2;
			this.y = stage.stageHeight / 2;
			addListeners(redSquare, whiteSquare, greenSquare);

		}

		private function removedHandler(event:Event):void
		{

		}
		private function getPosition(target:Object):void
		{
			xPos = target.x;
			yPos = target.y;
		}
		private function dragObject(e:MouseEvent):void
		{
			getPosition(e.target);

			e.target.startDrag(true);
		}
		private function stopDragObject(e:MouseEvent):void
		{
			if (e.target.hitTestObject(getChildByName(e.target.name + "Target")))
			{
				e.target.x = getChildByName(e.target.name + "Target").x;
				e.target.y = getChildByName(e.target.name + "Target").y;
				trace("well done you got it right")

			}
			else
			{
				e.target.x = xPos;
				e.target.y = yPos;
			}

			e.target.stopDrag();
		}
		private function addListeners(... objects):void
		{
			for (var i:int = 0; i < objects.length; i++)
			{
				objects*.addEventListener(MouseEvent.MOUSE_DOWN, dragObject);
				objects*.addEventListener(MouseEvent.MOUSE_UP, stopDragObject);
			}

	}

}
}

```
