I have an array of 8 movie clips which can be dragged and dropped onto an MC that is their common hitObject.
I would like whichever mc is being dragged to be added as the child of the hitObject MC when it is dropped, however I am having troubles setting up the code. Currently, only one specific instance will be added as a child of the hitObject because I don't know what to write inside the addChild() parameter aside from a specific instance name (none of the following are acceptable: e.target, the array name, the MovieClip name).
Here's my code --any and all help will be most appreciated:
import flash.events.MouseEvent;
import flash.display.MovieClip;
var redArray:Array = [red,red1,red2,red3,red4,red5,red6,red7];
redArray.forEach(setupDrag);
function setupDrag(dragger:MovieClip, index:int, array:Array):void {
dragger.addEventListener(MouseEvent.MOUSE_DOWN, dragRed);
dragger.buttonMode=true;}
redArray.forEach(setupDrop);
function setupDrop(dropper:MovieClip, index:int, array:Array):void {
dropper.addEventListener(MouseEvent.MOUSE_UP, dropRed);
dropper.buttonMode=true;}
var dirt:MovieClip
function dragRed(e:Event):void{
dirt = e.currentTarget as MovieClip;
e.target.startDrag();
}
function dropRed(e:Event):void{
e.target.stopDrag();
if (e.target.hitTestObject(drawer_mc))
{
drawer_mc.addChild(red1);
red1.y=10;
}
}
Thanks in advance!