I’ve go some movieclips I dynamically placed on the stage in a loop using addChild(). The clips have there own class called DragAndDrop. Once the clips are are drop to the hitarea I want to deactivate them. The problem I’m having is when I run the function in the DrapAndDrop class it deactives not only the movieclip that was just dragged but the last one that was attached in the loop as well (ie I drop mc1 into the proper area mc1 and mc7 deactive, 7 being the final clip in the loop). Its frustrating me because I dont know why its happening and I dont know how to fix it?
Here is the loop that add all the clips to the stage:
private function createTerms():void
{
for (var i:Number = 0; i < termsArr.length; i++)
{
_dragHead = new DragAndDrop();
addChild(_dragHead);
_dragHead.name = "dh" + i.toString();
_dragHead._targetArea = "db" + i.toString();
_dragHead.addEventListener(MouseEvent.MOUSE_UP, dropClip);
_dragHead._HIT = i;
_dragHead.x = termOrgX;
_dragHead.y = termOrgY;
_dragHead.setTerm(termsArr*)
termOrgY += _dragHead.height + 15;
}
}
Here is the where I evaluate the hitTestObject and call the function disableClip() in the DragAndDrop class to disable it:
private function dropClip(event:MouseEvent):void
{
var instName:String = event.currentTarget._targetArea;
for(var k:Number = 0; k< capArray.length; k++) {
if(event.currentTarget.hitTestObject(capArray[k])){
if (event.currentTarget.hitTestObject(getChildByName(instName))){
event.currentTarget.x = capArray[k].x;
event.currentTarget.y = capArray[k].y;
capArray[k].capBodyGreen_mc.alpha = 1;
event.currentTarget.removeEventListener(MouseEvent.MOUSE_UP, dropClip);
event.currentTarget.disableClip();
}
break;
} else {
trace("nothing was hit");
}
}
}
And finally here is the disableClip(); function in the DragAndDrop Class:
public function disableClip():void
{
this.redHead_mc.alpha = 1;
this.removeEventListener(MouseEvent.MOUSE_DOWN, dragClip);
this.removeEventListener(MouseEvent.MOUSE_UP, dropClip);
this.hit_btn.mouseEnabled = false;
trace("disabled Clip");
}
I don’t understand why its disabling both the dropped clip and the last clip in the loop when supposedly event.currentTarget should only carry the value of the object being dropped and not the instance of the object.
Thanks in advance guys.