# Error #1009: Cannot access a property or method of a null object reference

**URL:** <https://forum.kirupa.com/t/error-1009-cannot-access-a-property-or-method-of-a-null-object-reference/329452>\
**Category:** Uncategorized\
**Created:** [August 30, 2012, 8:47pm UTC](https://forum.kirupa.com/t/error-1009-cannot-access-a-property-or-method-of-a-null-object-reference/329452 "2012-08-30T20:47:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hq231](https://avatars.discourse-cdn.com/v4/letter/h/d26b3c/32.png) [@hq231](https://forum.kirupa.com/u/hq231)\
**Post date:** [August 30, 2012, 8:47pm UTC](https://forum.kirupa.com/t/error-1009-cannot-access-a-property-or-method-of-a-null-object-reference/329452/1 "2012-08-30T20:47:50Z")

</div>

So, I’m trying to remove an object after it has exceeded set x and y coordinates but i keep getting this error:

Error #1009: Cannot access a property or method of a null object reference.

I used the same code for another object and it worked fine. The error is coming from line 45 of my ship code which is: parent.removeChild(this);

and line 72 of my Level code which is: ships[count].update();

Here is my Level code :  
package  
{

```
import flash.display.MovieClip;
import flash.events.Event;
import flash.ui.Mouse;

public class Level extends MovieClip
{

    var ships:Array;
    var bullets:Array;
    public var avatar:Avatar;

    public function Level()
    {

        avatar = new Avatar();
        addChild( avatar );

        avatar.x = mouseX;
        avatar.y = mouseY;

        //addEventListener(Event.ENTER_FRAME, loop);
        ships = new Array ;
        bullets = new Array ;
        
        addEventListener(Event.ENTER_FRAME, update);

    }
    function update(e:Event)
    {
        avatar.x = mouseX;
        avatar.y = mouseY;
        Mouse.hide();
        
        
        
        

        if (numChildren&lt;5)
        {

            var s = new Ship();

            addChild(s);

            s.x = Math.random() * stage.stageWidth;
            s.y = -30;
            //s.rotation = Math.random() * 360;
            ships.push(s);

        }
        for (var bcount=0; bcount&lt;bullets.length; bcount++)
        {
            bullets[bcount].update();
            if (bullets[bcount].parent == null)
            {
                bullets.splice(bcount, 1);
                bcount--;
            }
        }
        for (var count = 0; count&lt;ships.length; count++)
        {
            ships[count].update();
            for (bcount=0; bcount&lt;bullets.length; bcount++)
            {
                if (ships[count].hitTestObject(bullets[bcount]))
                {
                    trace ("HIT");
                    removeChild(ships[count]);
                    ships.splice(count, 1);
                    removeChild(bullets[bcount]);
                    bullets.splice(bcount,1);
                    
                    
                }
                
            }
        }
    }
}

```

}

Here is my ship code:  
package  
{

```
import flash.display.Sprite;
import flash.events.Event;
import flash.display.Stage;

public class Ship extends Sprite
{

    private var speed:int;
    var rotateSpeed:Number;
    var size:Number;
    
    
    

    public function Ship()
    {

        speed = 2+Math.random()*5;
        rotateSpeed = 15;
        size = 5
        this.scaleX = Math.random()* size;
        this.scaleY = this.scaleX;
        trace("Made a Ship")
        
    }
    function update()
    {
        this.rotation += rotateSpeed;
        y = y + speed;
        if (x&lt;0 || x &gt;500 || y &lt; 0 || y &gt; 500)
        {
            

            parent.removeChild(this);
        

    }
    
    }
}

```

}

Thanks in advance
