You're almost there. You want to pass either target
or currentTarget
as the argument to addChild
. I think the following should do it (I've just posted the bits I've updated).
And there's a good explanation of the difference between target
and currentTarget
here.
var dirt:MovieClip;
function dragRed(e:Event):void {
// sounds like currentTarget and target will both work in your
// case, but stick to one or the other for consistency
dirt = e.currentTarget as MovieClip;
dirt.startDrag();
}
function dropRed(e:Event):void{
// assigning the currentTarget to your dirt variable means you don't
// keep needing to refer to e.currentTarget throughout the function
dirt = e.currentTarget as MovieClip;
dirt.stopDrag();
if (dirt.hitTestObject(drawer_mc)) {
// now you're always adding the instance that triggered
// the mouse up event
drawer_mc.addChild(dirt);
dirt.y=10;
}
}