I’m building a drag and drop quiz. each draggable mc (drag#) has a base class of DragDrop. I want to detect when an drag mc has been dropped on a target
if(this.hitTestObject(target))
{}
and then add a new drag from the drops Array. so that each time a drag finds its target a new one appears. I tried to make a public var named dropped to switch from “yes” to “no” in the drop function. and even tried making the drop function public. I’m stuck and really want to figure this out any help would be much appreciated.
this code is on the timeline
stop();
var drag1:Drag1;
drag1 = new Drag1;
addChild(drag1);
drag1.x = 100;
drag1.y = 100;
var drag2:Drag2;
drag2 = new Drag2;
drag1.x = 100;
drag1.y = 200;
var drag3:Drag3;
drag3 = new Drag3;
drag3.x = 100;
drag3.y = 300;
var drag4:Drag4;
drag4 = new Drag4;
drag4.x = 100;
drag4.y = 400;
var drag5:Drag5;
drag5 = new Drag5;
drag5.x = 100;
drag5.y = 400;
var dragdrop:DragDrop;
var drops:Array = [drag1,drag2,drag3,drag4,drag5];
var targets:Array = [target1, target1, target2, target2, target2];
var markers:Array = [marker1, marker2,marker3,marker4, marker5];
function assingTargets():void{
for(var i:uint = 0; i< drops.length; i++) // i = 0
{
dragdrop = drops*;
dragdrop.target = targets*;
dragdrop.marker = markers*;
}
}
assingTargets()
dragdrop.drop.addEventListener(MouseEvent.MOUSE_UP, dropped);
function(){
trace("dropped");
addChild(drag2);
}
this code is in the external class DragDrop
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class DragDrop extends MovieClip
{
public var target:MovieClip;
public var marker:MovieClip;
private var originalX:Number;
private var originalY:Number;
public var dropped = "no";
public function DragDrop()
{
this.addEventListener(MouseEvent.MOUSE_DOWN, drag);
}
private function drag(event:MouseEvent):void
{
originalX = this.x;
originalY = this.y;
this.startDrag();
this.addEventListener(MouseEvent.MOUSE_UP, drop);
}
private function drop(event:MouseEvent):void
{
dropped = "yes";
this.stopDrag();
this.removeEventListener(MouseEvent.MOUSE_UP, drop);
if(this.hitTestObject(target))
{
this.x = marker.x;
this.y = marker.y;
}
else{
dropped = "no";
this.x = originalX;
this.y = originalY;
}
}
}
}
thank you!