I'm not even sure if the title reflects what I want to do. Here's backstory. I have a movieclip with 5 'holder' movieclips in them. They are my containers for dynamically added movieclips.
The parent containers has an instance name of pyramid, the holder instance names are labeled after the 6 food groups, i.e., 'grainholder', 'fruitholder', 'vegetableholder', etc etc...
The holders are within the pyramid container, instance names as above, and the pyramid container is added to the display list. I have a addFoodToPyramid() function which adds 'foodMC' mc's to their respective holders. So an [object Apple] will be dynamically added by way of pyramid.fruitholder.addChild(Apple). The function also adds a listener. Heres the call and the function:
The call (I will use grains as example) is this:
addFoodToPyramid(grainArray, grainHolder, grainCounter);
And the function is:
function addFoodToPyramid(thisArray:Array, thisHolder:MovieClip, thisCounter:Number):void {
thisCounter = 0;
for (var f:Number=0; f<thisArray.length; f++)
{
trace(thisArray.length);
foodMC = (thisArray[f] as MovieClip);
trace(foodMC);
thisHolder.addChild(foodMC);
foodMC.addEventListener(MouseEvent.MOUSE_DOWN, startFoodDrag, false, 0, true);
thisMC.scaleX = thisMC.scaleY = .7;
thisMC.x = 60 * thisCounter;
thisCounter++;
}
}
Then I have a startDrag function:
function startFoodDrag(e:MouseEvent):void
{ foodDrag = e.target as MovieClip; foodDrag.startDrag(); foodPoint = new Point(foodDrag.x,foodDrag.y); stage.addEventListener(MouseEvent.MOUSE_UP, stopFoodDrag, false, 0, true); }
Then the drop function AND THE PROBLEM LIES HERE:
foodDrag = foodDrop;
stage.addEventListener(MouseEvent.MOUSE_UP, stopFoodDrag);
if(foodDrag.dropTarget.parent==myPlate){
//HERES THE PROBLEM removeChild(foodDrag); //obviously returns error because the foodDrag reference is wrong
}
Ok, so obviously the reference is not a direct removeChild() but a specific path. Like:
pyramid.*THE-HOLDER-OF-foodDRAG*.removeChild(foodDrag).
But I just can't get my head around how to do it. I've tried:
var mcParent:MovieClip=(foodDroppedMC.parent);
pyramid.mcParent.removeChild(foodDroppedMC);
// returns error 1118 Implicit Coercion
I've tried:
var mcParent:String=(foodDroppedMC.parent.name);
pyramid.getChildByName(mcParent).removeChild(foodDroppedMC);
// return 1061 Call to possibly undefined method removeChild with ref to static type etc etc
The fact that it's such a banal problem is what makes it so frustrating...
Any help would be appreciated. Thanks