title: Actionscript 3 drag and drop multiple objects to target with well done
body: <p>The drag and drop works, however, I have no idea how to create an if statement that goes to the next scene when all movieclips have been placed on the target.</p>
  
  <p>I've tried placing the instance names in an if statement with the hittestobject however, no luck.</p>
  
  <pre><code>import flash.events.TouchEvent;
  import flash.ui.Multitouch;
  import flash.ui.MultitouchInputMode;
  import flash.display.MovieClip;
  
  /* Touch and Drag Event
  Allows the object to be moved by holding and dragging the object.
  */
  var objectoriginalX:Number;
  var objectoriginalY:Number;
  Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
  
  var lemons:Array = [lemon1_mc, lemon2_mc, lemon3_mc, lemon4_mc, lemon5_mc];
  
  for each(var lemonMC:MovieClip in lemons)
  {
      lemonMC.buttonMode = true;
      lemonMC.addEventListener(TouchEvent.TOUCH_BEGIN, pickobject);
      lemonMC.addEventListener(TouchEvent.TOUCH_END, dropobject);
  
      lemonMC.startX = lemonMC.x;
      lemonMC.startY = lemonMC.y;    
  }
  var fl_DragBounds:Rectangle = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);    
  
  function pickobject(event:TouchEvent):void
  {
      event.target.startTouchDrag(event.touchPointID, false, fl_DragBounds);
      event.target.parent.addChild(event.target);
      objectoriginalX = event.target.x; 
      objectoriginalY = event.target.y;       
  }
  
  function dropobject(event:TouchEvent):void
  {
      if(event.target.hitTestObject(target_mc)){
          event.target.buttonMode = false;
          event.target.x = target_mc.x;
          event.target.y = target_mc.y;
          event.target.visible = false;           
      } else {
          event.target.x = event.target.startX;
          event.target.y = event.target.startY;
          event.target.buttonMode = true;
      }   
  }
  
  var melons:Array = [melon1_mc, melon2_mc, melon3_mc, melon4_mc, melon5_mc, melon6_mc, melon7_mc];
  for each(var melonMC:MovieClip in melons)
  {
      melonMC.buttonMode = true;
      melonMC.addEventListener(TouchEvent.TOUCH_BEGIN, pickobject2);
      melonMC.addEventListener(TouchEvent.TOUCH_END, dropobject2);
  
      melonMC.startX = melonMC.x;
      melonMC.startY = melonMC.y;    
  }
  var fl_DragBounds2:Rectangle = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);
  
  function pickobject2(event:TouchEvent):void
  {
      event.target.startTouchDrag(event.touchPointID, false, fl_DragBounds2);
      event.target.parent.addChild(event.target);
      objectoriginalX = event.target.x; 
      objectoriginalY = event.target.y;       
  }
  
  function dropobject2(event:TouchEvent):void
  {
      if(event.target.hitTestObject(target_null)){
          event.target.buttonMode = false;
          event.target.x = target_mc.x;
          event.target.y = target_mc.y;
          event.target.visible = false;           
      } else {
          event.target.x = event.target.startX;
          event.target.y = event.target.startY;
          event.target.buttonMode = true;
      }
  }
  </code></pre>