在"重播游戏中,在ActionScript3上接收#1009的类型错误代码"功能,如何解决此错误?

时间:2017-04-29 22:37:31

标签: actionscript-3 flash

我是一名大学生,目前正在自行完成一项任务,使用Animate CC上的ActionScript 3为Android创建Flash游戏。

我是ActionScript 3的初学者,发现自己陷入了我正在制作的游戏的最后一点。

在游戏的屏幕上,我有一个按钮,允许用户再次玩游戏(重启游戏),这就是问题发生的地方。按下再次播放按钮并开始游戏的那一刻,所有内容都被冻结,但评分系统正在运行。

我想要做的是,当用户按下"再次播放"按钮,它将带他/她进入屏幕,它允许您选择难度,只是简单地重播游戏。

这是我的游戏如何运作的结构:

  • 简介屏幕(播放按钮和说明按钮)
  • 按播放按钮 - >选择级别屏幕
  • 选择级别屏幕(简单或困难)
  • 如果您轻松或努力地按下它将进入相应难度游戏的屏幕
  • 一旦你输了,它就会带你进入Game Over屏幕。
  • Game Over屏幕可以选择Play Again

这些是我在下面收到的一些错误:

  

TypeError:错误#1009:无法访问null的属性或方法   对象参考。在   AndroidSnowballShooterSanta_fla :: MainTimeline / startGameInEasyMode()

     

TypeError:错误#1009:无法访问null的属性或方法   对象参考。在   AndroidSnowballShooterSanta_fla :: MainTimeline / moveSantaMCTowardMouse()

     

TypeError:错误#1009:无法访问null的属性或方法   对象参考。在   AndroidSnowballShooterSanta_fla :: MainTimeline / moveSantaMCTowardMouse()

我用于Game Over屏幕的代码用于启用重放游戏的功能:

//Option button to let the user play Game again

playAgainButton.addEventListener(MouseEvent.MOUSE_UP, restartGame);
function restartGame(evt:MouseEvent)
{
     playAgainButton.removeEventListener(MouseEvent.MOUSE_UP, restartGame);
     gotoAndPlay(1,"Choose Level");

---------------------------- 
//The code used in the Choose Level Screen looks like this

    stop();

    easyButton.addEventListener(MouseEvent.MOUSE_UP, startGameInEasyMode);
    function startGameInEasyMode(evt:MouseEvent)
    {
        gotoAndPlay(1,"GameEasy");
         easyButton.removeEventListener(MouseEvent.MOUSE_UP, startGameInEasyMode);

    }

    hardButton.addEventListener(MouseEvent.MOUSE_UP, startGameInHardMode);
    function startGameInHardMode(evt:MouseEvent)
    {
        gotoAndPlay(1, "GameHard");
         hardButton.removeEventListener(MouseEvent.MOUSE_UP, startGameInHardMode);

    }

    DifficultiesBackButton.addEventListener(MouseEvent.MOUSE_UP, returnToHome);
    function returnToHome(evt:MouseEvent)
    {
         gotoAndPlay(1,"Intro");
          DifficultiesBackButton.removeEventListener(MouseEvent.MOUSE_UP, returnToHome);

    }

    -------------------------------------


    //GAME EASY

    stop();

    import flash.events.Event;

    var myStartTime = getTimer();

    var bottomEdge = 0;
    var topEdge = 800;
    var leftEdge = 0;
    var rightEdge = 480;

    var SantaMCSpeed = 0.7;

    addEventListener(Event.ENTER_FRAME,moveSantaMCTowardMouse);
    function moveSantaMCTowardMouse(e:Event)
    {
        var angleInRad = Math.atan2((mouseY-SantaMC.y),(mouseX-SantaMC.x));
        SantaMC.rotation = (90 + angleInRad * 180/Math.PI);

        var distanceX = SantaMC.x - mouseX;
        var distanceY = SantaMC.y - mouseY;
        SantaMC.x -= (distanceX / 5) * SantaMCSpeed;
        SantaMC.y -= (distanceY / 5) * SantaMCSpeed;
    }

    // defining SnowCannonMC1
    SnowCannonMC1.x = 50;
    SnowCannonMC1.y = 800;
    SnowCannonMC1.pointing = "up";
    SnowCannonMC1.increment = 7;

    //moving Cannon 1
    addEventListener(Event.ENTER_FRAME, moveSnowCannonMC1);
    function moveSnowCannonMC1(evt:Event)
    {
        if (SnowCannonMC1.x < leftEdge)
        {
            SnowCannonMC1.pointing = "right";
        }
        if (SnowCannonMC1.x > rightEdge)
        {
            SnowCannonMC1.pointing = "left";
        }
        if (SnowCannonMC1.pointing == "right")
        {
            SnowCannonMC1.x +=  SnowCannonMC1.increment;
        }
        else
        {
            SnowCannonMC1.x -=  SnowCannonMC1.increment;
        }

    }


    //making the Snow Cannons shoot at random
    var SnowCannonShootRate = 65;
    var snowBallMCCount = 0;

    var shootingSound = new cannonShotSound();

    addEventListener(Event.ENTER_FRAME, shootSnowballCannon);
    function shootSnowballCannon(evt:Event)
    {
        var SnowCannonMC1ShootValue = Math.ceil(Math.random() * SnowCannonShootRate);

        if (SnowCannonMC1ShootValue <= 1)
        {
            shoot(SnowCannonMC1);
        }
    }

    function shoot(aSnowBall)
    {
        shootingSound.play();
        snowBallMCCount++;
        var newSnowBallMC = root["snowBallMC" + snowBallMCCount]=this.addChild(new Snowball());

        newSnowBallMC.width = 19;
        newSnowBallMC.height = 19;

        newSnowBallMC.rotation = aSnowBall.rotation;
        newSnowBallMC.x = aSnowBall.x;
        newSnowBallMC.y = aSnowBall.y;
    }

    //moving snowBallMCs
    var score;
    var finalScore;
    addEventListener(Event.ENTER_FRAME, moveSnowBallMC);
    function moveSnowBallMC(evt:Event) {

    score = getTimer() - myStartTime;
    timeBoxEasy.text = String(Math.ceil((score)/1000));
    var speed:Number = 0.70;


       for (var i=1; i<=snowBallMCCount; i++) {
          var snowBall = root["snowBallMC"+i];  

          if(snowBall.rotation == 0) 
          {
            snowBall.y += -10 * speed;
          }

          else 
          {
            snowBall.x += 10 * speed;
          }

          if(snowBall.hitTestObject(SantaMC))
          {

            //var SantaShotDeadSound = new objectShotDeadSound();
            //SantaShotDeadSound.play();

            removeEventListener(Event.ENTER_FRAME,moveSantaMCTowardMouse);
            removeEventListener(Event.ENTER_FRAME, moveSnowCannonMC1);
            removeEventListener(Event.ENTER_FRAME, shootSnowballCannon);
            removeEventListener(Event.ENTER_FRAME, moveSnowBallMC);

            finalScore= score;

            gotoAndPlay(1,"Game Over")
            break;

          }
       }
    }

    // adding the scores to the highscores table

    var scoreTable = SharedObject.getLocal("data"); 

    if((scoreTable.data.nameArray==undefined)||(scoreTable.data.scoreArray==undefined)){
        scoreTable.data.nameArray = new Array();
        scoreTable.data.scoreArray = new Array();
    }

    function displayScoreTable() {
        sortScores();
        var temp ="LEADERBOARD \n";
        var nameArray = scoreTable.data.nameArray;
        var scoreArray = scoreTable.data.scoreArray;

        for (var nameCount = 0; nameCount < nameArray.length; nameCount++) {
            temp += nameArray[nameCount] + " ----- " + String(Math.ceil((scoreArray[nameCount])/1000)) +"\n";
        }
        scoreTableBox.text = temp;
    }


    function sortScores(){

        var nameArray = scoreTable.data.nameArray;
        var scoreArray = scoreTable.data.scoreArray;
        var len = nameArray.length;
        var tempName;
        var tempScore;

        for (var count1=0; count1 < len - 1; count1++){
            for (var count2=count1+1; count2 < len; count2++){
                if(scoreArray[count1]<scoreArray[count2]){
                    tempName=nameArray[count1];
                    nameArray[count1]=nameArray[count2];
                    nameArray[count2]=tempName;
                    tempScore=scoreArray[count1];
                    scoreArray[count1]=scoreArray[count2];
                    scoreArray[count2]=tempScore;
                }
            }
        }
    }

0 个答案:

没有答案