# Cannot access a property or method of a null object reference

**URL:** <https://forum.kirupa.com/t/cannot-access-a-property-or-method-of-a-null-object-reference/317631>\
**Category:** Uncategorized\
**Created:** [December 28, 2010, 8:06am UTC](https://forum.kirupa.com/t/cannot-access-a-property-or-method-of-a-null-object-reference/317631 "2010-12-28T08:06:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Petrie](https://avatars.discourse-cdn.com/v4/letter/p/7ba0ec/32.png) [@Petrie](https://forum.kirupa.com/u/Petrie)\
**Post date:** [December 28, 2010, 8:06am UTC](https://forum.kirupa.com/t/cannot-access-a-property-or-method-of-a-null-object-reference/317631/1 "2010-12-28T08:06:21Z")

</div>

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

```auto
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 🥚
