0

I have 2 errors:

  1. TypeError: Error #1009: Cannot access a property or method of a null object reference. at BlowfishPong_fla::MainTimeline/countTime()[BlowfishPong_fla.MainTimeline::frame79:75]
  2. TypeError: Error #1009: Cannot access a property or method of a null object reference. at BlowfishPong_fla::MainTimeline/airScore()[BlowfishPong_fla.MainTimeline::frame79:131]

Look at this code:

timedScore = 0;
var goalScore: int = Math.floor(Math.random() * 101) + 20;
var speedSeconds = 0;
var speedMinutes = 0;

keyNum = 0;
var OxygenTime = 0;
var OxygenMaxTime = 5;
var goalKey: int = Math.floor(Math.random() * 10) + 3;
var ballSpeedXTimed: int = -3;
var ballSpeedYTimed: int = -2;
var cpuPaddleSpeedTimed: int = 3;

stopwatch.play();
oxygenGauge.stop();
var FiftyTimed: Boolean = false;
var plzStopTimed: Boolean = false;
helpContent_Timed.visible = false;

stopwatch.addEventListener(Event.ENTER_FRAME, countTime);
oxygenGauge.addEventListener(Event.ENTER_FRAME, airScore);

goalScore_txt.text = String(goalScore);
timedScore_txt.text = timedScore;
key_txt.text = keyNum + "/" + goalKey;
stage.addEventListener(Event.ENTER_FRAME, loopTimed);

function updateTextFieldsTimed(): void {
    goalScore_txt.text = String(goalScore);
    timedScore_txt.text = timedScore;
    key_txt.text = keyNum + "/" + goalKey;
}

function calculateBallAngleTimed(paddleY: Number, ballY: Number): Number {
    var ySpeed: Number = 5 * ((ballY - paddleY) / 25);
    return ySpeed;
}

function countTime(e: Event): void {
    if (stopwatch.currentFrame == 61) {
        speedSeconds++;
        if (speedSeconds > 59) {
            speedSeconds = 0;
            speedtimerSec_txt.text = "0" + speedSeconds;
            speedMinutes++;
            if (speedMinutes > 10) {
                speedtimerMin_txt.text = "" + speedMinutes;
            } else {
                speedtimerMin_txt.text = "0" + speedMinutes;
            }
            if (speedMinutes > 59) {
                stopwatch.stop();
                gotoAndPlay("gameover_Timed");
            }
        } else {
            if (speedSeconds >= 10) {
                speedtimerSec_txt.text = "" + speedSeconds;
            } else {
                speedtimerSec_txt.text = "0" + speedSeconds;
            }
        }
    }
}

function airScore(timedScore): void {
    if (timedScore == 50 && FiftyTimed == false) {
        character_TiedUp.gotoAndStop(2);
        FiftyTimed = true;
        oxygenGauge.play();
        OxygenTime++;
    } else if (timedScore == 150 && FiftyTimed == false) {
        character_TiedUp.gotoAndStop(2);
        FiftyTimed = true;
        oxygenGauge.play();
        oxygenGauge.frameRate = 1.5;
        OxygenTime++;

    } else if (timedScore == 300 && FiftyTimed == false) {
        character_TiedUp.gotoAndStop(2);
        FiftyTimed = true;
        oxygenGauge.play();
        OxygenTime++;

    } else if (timedScore == 450 && FiftyTimed == false) {
        character_TiedUp.gotoAndStop(2);
        FiftyTimed = true;
        oxygenGauge.play();
        OxygenTime++;

    } else if (timedScore == 600 && FiftyTimed == false) {
        character_TiedUp.gotoAndStop(2);
        FiftyTimed = true;
        oxygenGauge.play();
        OxygenTime++;
    }
    if (oxygenGauge.currentFrame == 505) {
        character_TiedUp.gotoAndStop(3);
        oxygenGauge.stop();
        oxygenGauge.gotoAndStop(1);
    }
}

function loopTimed(event: Event): void {
    if (plzStopTimed == false) {
        playerPaddle.y = mouseY;
        keyPong.x += ballSpeedXTimed;
        keyPong.y += ballSpeedYTimed;

        //check left and right boundaries
        if (keyPong.x <= keyPong.width / 2) {
            keyPong.x = keyPong.width / 2;
            ballSpeedXTimed *= -1;
            keyNum++;
            BingTimed.play();
            if (goalKey == keyNum) {
                key_txt.textColor = 0x00FF00;
            }
            updateTextFieldsTimed();
        } else if (keyPong.x >= stage.stageWidth - keyPong.width / 2) {
            keyPong.x = stage.stageWidth - keyPong.width / 2;
            ballSpeedXTimed *= -1;
            BingTimed.play();
            if (keyNum > 0) {
                keyNum--;
            }
            if(goalKey < keyNum) {
                key_txt.textColor = 0xFFFFFF;
            }
            updateTextFieldsTimed();
        }

        if (keyPong.y <= keyPong.height / 2) {
            keyPong.y = keyPong.height / 2;
            ballSpeedYTimed *= -1;
            gameBounceTimed.play();
        } else if (keyPong.y >= stage.stageHeight - keyPong.height / 2) {
            keyPong.y = stage.stageHeight - keyPong.height / 2;
            ballSpeedYTimed *= -1;
            gameBounceTimed.play();
        }

        if (cpuPaddle.y < keyPong.y - 10) {
            cpuPaddle.y += cpuPaddleSpeedTimed;
        } else if (cpuPaddle.y > keyPong.y + 10) {
            cpuPaddle.y -= cpuPaddleSpeedTimed;
        }

        if (playerPaddle.y - playerPaddle.height / 4 < 0) {
            playerPaddle.y = playerPaddle.height / 4;
        } else if (playerPaddle.y + playerPaddle.height / 4 > stage.stageHeight) {
            playerPaddle.y = stage.stageHeight - playerPaddle.height / 4;
        }

        if (playerPaddle.paddle.hitTestObject(keyPong) == true) {
            if (ballSpeedXTimed > 0) {
                ballSpeedXTimed *= -1;
                ballSpeedYTimed = calculateBallAngleTimed(playerPaddle.y, keyPong.y);
                timedScore++
                gameHitTimed.play();
                airScore(timedScore);
                if (goalKey == keyNum) {
                    if (goalScore == timedScore) {
                        stage.removeEventListener(Event.ENTER_FRAME, loopTimed);
                        gotoAndStop("gameover_Timed");
                        return;
                    }
                }
                updateTextFieldsTimed();
            }
        } else if (cpuPaddle.paddle.hitTestObject(keyPong) == true) {
            if (ballSpeedXTimed < 0) {
                ballSpeedXTimed *= -1;
                ballSpeedYTimed = calculateBallAngleTimed(cpuPaddle.y, keyPong.y);
                timedScore++;
                gameHitTimed.play();
                airScore(timedScore);
                if (goalKey == keyNum) {
                    if (goalScore == timedScore) {
                        stage.removeEventListener(Event.ENTER_FRAME, loopTimed);
                        gotoAndStop("gameover_Timed");
                        return;
                    }
                }
                updateTextFieldsTimed();
            }
        }
    }
}

Can anyone how to fix these?

  • The message says your errors are on lines **75** and **131**. What are the codes at those lines? – VC.One Apr 03 '22 at 14:14
  • Then, If the keyNum to equals goalKey, then timedScore is less than goalScore until its equals to the goalScore and it moved to the next frame. Then, if the timedScore is equals to goalScore, keyNum is less than goalKey until its equals to the goalKey and it also moved to the next frame. – Isaac Yeap Jie Ling Apr 03 '22 at 15:24
  • Can you please write two comments? **(1)** `This is code for line 75` and show that code... **(2)** Next comment is `This is code for line 131` and show that code... **(3)** I cannot run your AS (no IDE here), also in a text editor line 131 shows an empty space (or line) between two codes. – VC.One Apr 03 '22 at 16:43
  • PS: Is `keyNum = 0;` and `timedScore = 0;` supposed to variables that are declared somewhere else? I mean, did you already write `var keyNum : uint;` somewhere else? If not then declare it properly as `var keyNum :uint = 0;`. **(2)** Is `oxygenGauge` an MC? If yes, where is the extra `.framerate` property coming from? Did you add it to code of that MC (MovieCip)? **(3)** For text you need to **cast** your numbers as **String**, try as: `key_txt.text = ( String( keyNum ) + "/" + String( goalKey ) );`... – VC.One Apr 03 '22 at 16:56
  • .Yes, oxygenGauge is MC, and the .framerate is to test the speed of the gauge. And it is already import flash.display.MovieClip; – Isaac Yeap Jie Ling Apr 04 '22 at 03:07

0 Answers0