# What is the best way to do this drag and drop

**URL:** <https://forum.kirupa.com/t/what-is-the-best-way-to-do-this-drag-and-drop/329135>\
**Category:** flash\
**Created:** [July 24, 2012, 7:57pm UTC](https://forum.kirupa.com/t/what-is-the-best-way-to-do-this-drag-and-drop/329135 "2012-07-24T19:57:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![m2244](https://avatars.discourse-cdn.com/v4/letter/m/ac91a4/32.png) [@m2244](https://forum.kirupa.com/u/m2244)\
**Post date:** [July 24, 2012, 7:57pm UTC](https://forum.kirupa.com/t/what-is-the-best-way-to-do-this-drag-and-drop/329135/1 "2012-07-24T19:57:06Z")

</div>

Hello,

I am trying to create a drag/drop where when you drop the answer onto the question it senses the target and traces the name of the target. What am I doing wrong?

```auto

import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.utils.Dictionary;
var refDict:Dictionary = new Dictionary;
 / *************Set up the questions with text from the XML file.********************* /
 for(var i:int = 0; i < xmlFile.questions.question.length(); i++)
 { 
  var quesText:TextField = new TextField();
  quesText.defaultTextFormat=formatNormal;
  quesText.multiline=true;
  quesText.selectable=false;
  quesText.mouseEnabled = false;
  quesText.wordWrap=true;
  quesText.width=400;
  quesText.x = 20;
  quesText.y = 20 + (i * 60);
  quesText.autoSize=TextFieldAutoSize.LEFT;
  quesText.name = String(i); // Not sure why I did this.
  quesText.text = xmlFile.questions.question*.content;
  stage.addChild(quesText);
 }
 
 / *************Set up the draggers with text from the XML file.********************* /
 for(var n:int = 0; n < xmlFile.draggers.answer.length(); n++)
 {
  var ansBacking:mcDragger = new mcDragger();
  ansBacking.x = 650;
  ansBacking.y = 30 + (n * 70);
  ansBacking.buttonMode = true;
  ansBacking.txtAnswer.text = xmlFile.draggers.answer[n].content;
  ansBacking.mouseChildren = false;
  ansBacking.name = xmlFile.draggers.answer[n].content;
  ansBacking.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
  stage.addChild(ansBacking);
 }
 

function startDragging(evt:MouseEvent):void
{
 evt.target.removeEventListener(MouseEvent.MOUSE_DOWN, startDragging);
 evt.target.addEventListener(Event.ENTER_FRAME, checkHitTest);
 origLocatX = evt.target.x;
 origLocatY = evt.target.y;
 evt.target.startDrag(false);
 evt.target.parent.addChild(evt.target);
 evt.target.addEventListener(MouseEvent.MOUSE_UP, onDrop);
}
function onDrop(evt:MouseEvent):void
{
 
 evt.target.removeEventListener(MouseEvent.MOUSE_UP, onDrop);
 evt.target.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
 if([EMAIL="xmlFile.draggers.@multiUse"]xmlFile.draggers.@multiUse[/EMAIL] == true)
 {
  evt.target.x = origLocatX;
  evt.target.y = origLocatY;
 }
 else
 {
  stage.removeChild(DisplayObject(evt.target));
 }
 evt.target.stopDrag();
 
 if(evt.target.dropTarget != null)
 {
  evt.target.dropTarget.text += evt.target.txtAnswer.text;
 }
 else
 {
  //stage.removeChild(evt.target.parent);
 }
}
function checkHitTest(evt:Event):void
{
 /*if(evt.currentTarget.hitTestObject(quesText))
 {}*/
 if (evt.currentTarget.dropTarget != null)
 {
  trace(evt.currentTarget.dropTarget.parent);
 }
}

```
