# Problem with game

**URL:** <https://forum.kirupa.com/t/problem-with-game/288434>\
**Category:** Uncategorized\
**Created:** [May 15, 2009, 3:32pm UTC](https://forum.kirupa.com/t/problem-with-game/288434 "2009-05-15T15:32:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![zibzed](https://avatars.discourse-cdn.com/v4/letter/z/c0e974/32.png) [@zibzed](https://forum.kirupa.com/u/zibzed)\
**Post date:** [May 15, 2009, 3:32pm UTC](https://forum.kirupa.com/t/problem-with-game/288434/1 "2009-05-15T15:32:48Z")

</div>

hi, im trying to give this game a few levels by copying and pasting the code into a new keyframe i’ve changed the code in the second level so they dont match but i keep getting the error

TypeError: Error #1009: Cannot access a property or method of a null object reference.  
at shipGame\_fla::MainTimeline/animShip()

i feel like im going crazy here.

heres the link:[http://rapidshare.com/files/233303461/shipGame.fla](http://rapidshare.com/files/233303461/shipGame.fla)

```auto
var speedVert:Number = 0;
var speedHoriz:Number = 0;
var goUp:Number = 0;
var death:int = 0;

gotoAndStop(1);

function startGame(evt:MouseEvent):void{
    mShip.x = 352;
    mShip.y = 82;
    mShip.gotoAndStop("normal");
    bGo.visible = false;
    mShip.addEventListener(Event.ENTER_FRAME, animShip);
    stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
    stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
}
bGo.addEventListener(MouseEvent.CLICK, startGame);

function animShip(evt:Event):void {
    
    mShip.y += speedVert;
    speedVert += .01;

    mShip.x += speedHoriz;
    
    mShip.y -= goUp;

    tVert.text = String(Math.floor(speedVert));
    tAlt.text = String(Math.floor(mLandingPad.y - mShip.y));
    tHoriz.text = String(Math.floor(speedHoriz));

    if (mShip.x > mLandingPad.x - mLandingPad.width/2 && mShip.x < mLandingPad.x + mLandingPad.width/2) {
        tPadStatus.text = "okay for landing";
    } else {
        tPadStatus.text = "not safe for landing";
    }
    if (mShip.hitTestObject(mCrashLeft) || mShip.hitTestObject(mCrashRight)||mShip.hitTestObject(tShape1)||mShip.hitTestObject(tShape2)||mShip.hitTestObject(mSky)|| 
    mShip.hitTestObject(tShape3)||mShip.hitTestObject(tShape4)||mShip.hitTestObject(tShape5)||mShip.hitTestObject(tShape6)){
        death += 1
        speedVert = 0;
        speedHoriz = 0;
        tDeath.text = String(death);
        tStatus.text = "crashed";
        mShip.gotoAndStop("crash");
        mShip.removeEventListener(Event.ENTER_FRAME, animShip);
        stage.removeEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
        stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
        //bGo.addEventListener(MouseEvent.CLICK, startGame);
        bGo.visible = true;
        gotoAndPlay(2);
    }
    if (mShip.y > mLandingPad.y) {
        tStatus.text = "landed safely";
        mShip.gotoAndStop("land");
        mShip.removeEventListener(Event.ENTER_FRAME, animShip);
        stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
        stage.removeEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
        bGo.visible = true;
        gotoAndStop(2);
    }
}

function keyDownHandler(evt:KeyboardEvent):void {
    //trace("Keycode =" + evt.keyCode + "charCode =" + evt.charCode + "keystring = " + String.fromCharCode(evt.charCode));
// tStatus.text = "Keycode =" + evt.keyCode + "charCode =" + evt.charCode + "keystring = " + String.fromCharCode(evt.charCode)
    if (evt.keyCode==32) {
        speedVert -= .1;
        mShip.gotoAndStop("up");
        tStatus.text = "main engine burn";
    } else if (evt.keyCode == 37) {
        speedHoriz -= 0.1;
        speedVert -= 0.1;
        mShip.gotoAndStop("left");
        tStatus.text = "positioning rocket left";

    } else if (evt.keyCode == 39) {
        speedHoriz += 0.1;
        speedVert -= 0.1;
        mShip.gotoAndStop("right");
        tStatus.text = "positioning rocket right";
    }
}

function keyUpHandler(evt:KeyboardEvent):void {
    mShip.gotoAndStop("normal");
    tStatus.text = "main engine off";

}
stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);

```
