drag and drop interaction - logic flaw
Hi,
I'm hoping for some help in ironing out this small bit of code. My logic is somehow screwed up.
I have 10 clips and 10 targets. The user drags the clips to the targets, and when dropped on a target, the clip locks in place to the x and y coord of the target.
The code below only allows for the user to drop the clip on its cooresponding target; i.e.:
- droppedClip1 can only be dropped on hitTarget1
- droppedClip2 can only be dropped on hitTarget2
- etc.
How can I modify the code so that the droppedClip can be dropped on any of the 10 targets?
Ty for any help,
~chipleh
//droppedClip = movie clip the user just dropped
//totalClips = total number of draggable clips
function evaluateDroppedClip(droppedClip:Object,totalClips:String):void
{
for (var i:Number = 0;i<Number(totalClips);i++)
{
var hitTarget:Object = objectContainer.getChildByName("hitTarget" + i);
if(droppedClip.hitTestObject(hitTarget))
{
trace("hitTarget = " + hitTarget.name);
droppedClip.x = hitTarget.x;
droppedClip.y = hitTarget.y;
}else{
droppedClip.x = droppedClip.xPos;//the original position of the dropped clip
droppedClip.y = droppedClip.yPos;//the original position of the dropped clip
}
}
}