So I have this target movieclip and some dragable square movieclips that are created every 5 seconds, and I’m trying to removechild them when they touch the target but as soon as they appear on stage I get this evil error, and when I drag them onto the target nothing happens!
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Function/<anonymous>()
I’ve googled over 9000 times trying to figure out what’s causing it but everything i try doesn’t work! Or it just gives me another error in place of it.
Anyway this is (most of) the code
function addTarget(event:Event):void
{
var newTarg:targ1 = new targ1();
addChild(newTarg);
newTarg.x = 69;
newTarg.y = 175;
removeEventListener(Event.ENTER_FRAME, addTarget);
}
function AddBox(event:Event):void
{
//adds square to the stage
var newBox:Box1 = new Box1();
addChild(newBox);
//adds drag and drop functions
newBox.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
newBox.addEventListener(MouseEvent.MOUSE_UP, drop);
//makes it a button
newBox.buttonMode = true;
removeEventListener(Event.ENTER_FRAME, AddBox);
}
-This is the bit that causes the evil-
function BoxRemove(e:Event):void
{
if (newBox.hitTestObject(newTarg))
{
removeChild(newBox);
trace("yay");
}
}
addEventListener(Event.ENTER_FRAME, BoxRemove);
Thanks for the help