Hi, I'm having problems with dragging and dropping of multiple objects that are spawned on the stage. I'm trying to make a game where players can drag the draggables between two boxes with slots that they are able to snap into.
This is the image of the stage.

The draggables that are spawned and slots on the stage are put in an array.
public var dropArray:Array = new Array(drop0,drop1,drop2,drop3,drop4);
public var snapArray:Array = new Array(snap0,snap1,snap2,snap3,snap4);
The codes for the snapping into place and the hittest object doesn't seem to work. It seems like the for loop is causing the problem.
private function snapBack(event:MouseEvent):void
{
for (var j:int=0; j<dropArray.length; j++)
{
var myTargetName:String=("drop"+j);
var myTarget
isplayObject=getChildByName(myTargetName);
var target:MovieClip = event.currentTarget as MovieClip;
target.stopDrag();
//http://www.ilike2flash.com/2011/04/drag-and-drop-in-as3-part-3.html
var dragIndex:int = dragArray.indexOf(event.currentTarget);
if (item(event.currentTarget).hitTestObject(myTarget)) {
target.x=myTarget.x;
target.y=myTarget.y;
trace("drop");
trace(item(event.currentTarget).name);
}
else
{
target.x = positionsArray[dragIndex].xPos;
target.y = positionsArray[dragIndex].yPos;
trace("back");
}
}
}
This is the image of the stage.

The draggables that are spawned and slots on the stage are put in an array.
public var dropArray:Array = new Array(drop0,drop1,drop2,drop3,drop4);
public var snapArray:Array = new Array(snap0,snap1,snap2,snap3,snap4);
The codes for the snapping into place and the hittest object doesn't seem to work. It seems like the for loop is causing the problem.
private function snapBack(event:MouseEvent):void
{
for (var j:int=0; j<dropArray.length; j++)
{
var myTargetName:String=("drop"+j);
var myTarget

var target:MovieClip = event.currentTarget as MovieClip;
target.stopDrag();
//http://www.ilike2flash.com/2011/04/drag-and-drop-in-as3-part-3.html
var dragIndex:int = dragArray.indexOf(event.currentTarget);
if (item(event.currentTarget).hitTestObject(myTarget)) {
target.x=myTarget.x;
target.y=myTarget.y;
trace("drop");
trace(item(event.currentTarget).name);
}
else
{
target.x = positionsArray[dragIndex].xPos;
target.y = positionsArray[dragIndex].yPos;
trace("back");
}
}
}
I'm also having problems to not allow them to snap to the slot that already have a draggable in it.
Anyone care to help? Thanks in advance.