function addClip(e:MouseEvent):void { trace("Stage clicked");
addedClip = new newClip(); containerClip.addChild(addedClip); with (addedClip) { x = stage.mouseX; y = stage.mouseY; addEventListener(MouseEvent.MOUSE_DOWN,removeMe,false,0,true); } }
function removeMe(e:MouseEvent):void { trace("Removed me"); e.currentTarget.removeEventListener(MouseEvent.MOUSE_DOWN,removeMe); e.currentTarget.parent.removeChild(e.currentTarget); }
Last edited by fruitbeard; 07-11-2014 at 01:18 PM.
How can I change that removeme listener to be a hitest, im trying to get gravity to work on the movieclips so they fall down as you click, and they will hit some other movieclip under em to delete them
function addClip(e:MouseEvent):void
{
trace("Stage clicked - clip added");
addedClip = new newClip();
containerClip.addChild(addedClip);
with (addedClip)
{
x = stage.mouseX;
y = stage.mouseY;
addEventListener(Event.ENTER_FRAME,removeMe,false,0,true);
}
}
function removeMe(e:Event):void
{
e.currentTarget.y += 5;
if (e.currentTarget.hitTestObject(someOtherMovieClip))
{
e.currentTarget.removeEventListener(Event.ENTER_FRAME,removeMe);
e.currentTarget.parent.removeChild(e.currentTarget);
trace("Removed me");
}
}
TypeError: Error #1034: Type Coercion failed: cannot convert someOtherMovieClip$ to flash.display.DisplayObject.
at gravitydrops_fla::MainTimeline/removeMe()
The error code is telling you that it is coming from the removeMe() function, obviously it wont remove it.
you can either look up the error codes and work it out for yourself or attach your *.fla file, even a skeleton version if needed, as it works with my test example.