title: simple drag and drop to target as3
body: <p>I'd like to make a draggable movieclip target another movieclip (drop target). </p>
  
  <p>It doesn't need to have a reusuable function (i.e. event.target not necessary) and it doesn't need to be part of an array. </p>
  
  <p>I can't see why the code below won't work. I've tried using an assign symbol (=) instead of equals (==) in places but this makes no difference.</p>
  
  <p>Any feedback much appreciated.  </p>
  
  <pre><code>//Creating variables to store original x/y position of draggable movieclip (my_mc2):
  var startX:Number;
  var startY:Number;
  
  //Enabling hand cursor over draggable mc:
  my_mc2.buttonMode = true;
  
  //Adding event listeners for mouse up and mouse down.
  my_mc2.addEventListener(MouseEvent.MOUSE_DOWN, drag);
  my_mc2.addEventListener(MouseEvent.MOUSE_UP, drop);
  
  //Drag function (mouse down):
  function drag(event:MouseEvent):void {
  startX = my_mc2.x;
  startY = my_mc2.y;
  my_mc2.startDrag();
  }
  
  //Drop function (mouse up):
  function drop(event:MouseEvent):void {
  my_mc2.stopDrag();
  if (my_mc2.x == target_mc2.x &amp;&amp; my_mc2.y == target_mc2.y) {
      my_mc2.removeEventListener(MouseEvent.MOUSE_DOWN, drag);
      } else {
      my_mc2.x == startX;
      my_mc2.y == startY;
      }
  }
  </code></pre>