我的游戏玩完一次后,我的计时器会加快速度,为什么?

My timer increases speed after a single play through of my game why?

我继续收到错误 类型错误:错误 #1009:无法访问空对象引用的 属性 或方法。 在 ChazS1127_win_loose_screen_fla::MainTimeline/updateTime() 在 flash.utils::Timer/_timerDispatch() 在 flash.utils::Timer/tick() 这是我的主游戏代码

stop();
import flash.events.MouseEvent;
import flash.ui.Mouse;
import flash.events.TimerEvent;
import flash.utils.Timer;

var timer:Timer = new Timer(1000, 9999);
timer.addEventListener(TimerEvent.TIMER, updateTime);

var timeRemaining = 30;
timerBox.text = timeRemaining;

function updateTime(evt:TimerEvent)
{
    timeRemaining--;
    timerBox.text = timeRemaining;
    if(timeRemaining <= 0)
{

       gotoAndStop(1, "Loose Screen");
}
}

addEventListener(MouseEvent.CLICK, onMouseClick);

var score = 0 ;
function onMouseClick(evt:MouseEvent)
{
        if(evt.target.name == "playBtn") 
    {
        texts.visible = false;
        playBtn.visible = false;
        backpackss.visible = false;
        backgrounds.visible = false;
        timer.start();
    }
     if(evt.target.name == "Backpack")
     {
    Backpack.visible = false;
    message.text = "A backpack is a necessity for carrying all your items.";
    score = score + 1;
    scoredisplay.text = "score:" + score;

0
}
if(evt.target.name == "Bandage")
{
    Bandage.visible = false;
    message.text = "Bandages for cuts and scraps and to keep from bleeding out.";
    score = score + 1;
    scoredisplay.text = "score:" + score;
}
if(evt.target.name == "Brace")
{
    Brace.visible = false;
    message.text = "A brace is good for a sprain or even a break in a bone allow you to keep going.";
    score = score + 1;
    scoredisplay.text = "score:" + score;
}
if(evt.target.name == "canned")
{
    canned.visible = false;
    message.text = "Canned foods are a good resource as food will be scarce in situations.";
    score = score + 1;
    scoredisplay.text = "score:" + score;
}
if(evt.target.name == "Compass")
{
    Compass.visible = false;
    message.text = "Going the wrong direction in a survival situation can be your downfall.";
    score = score + 1;
    scoredisplay.text = "score:" + score;
}
if(evt.target.name == "Flashlight")
{
    Flashlight.visible = false;
    message.text = "A flashlight can help you see at night and help you stay sane.";
    score = score + 1;
    scoredisplay.text = "score:" + score;
}
if(evt.target.name == "Iodine")
{
    Iodine.visible = false;
    message.text = "An ioddine purfication kit can assist in keeping water clean for drinking.";
    score = score + 1;
    scoredisplay.text = "score:" + score;
}
if(evt.target.name == "Lighter")
{
    Lighter.visible = false;
    message.text = "A windproof lighter for even the windest of days to light fires.";
    score = score + 1;
    scoredisplay.text = "score:" + score;
}
if(evt.target.name == "Radio")
{
    Radio.visible = false;
    message.text = "A radio to help keep up to date on news around if it's still brodcasting.";
    score = score + 1;
    scoredisplay.text = "score:" + score;
}
if(evt.target.name == "Sewing")
{
    Sewing.visible = false;
    message.text = "A sewing kit for salvaging clothes and for patching up wounds.";
    score = score + 1;
    scoredisplay.text = "score:" + score;
}
if(evt.target.name == "Tent")
{
    Tent.visible = false;
    message.text = "A tent can be a home for the night and a home for life.";
    score = score + 1;
    scoredisplay.text = "score:" + score;
}
 if(score >= 11)
{

   gotoAndStop(1, "Victory Screen");
}
}
function removeAllEvents()
{
       removeEventListener(MouseEvent.CLICK, onMouseClick);      
       timer.removeEventListener(TimerEvent.TIMER, updateTime);
       timer.stop();
     }

还有我的胜利画面

stop();
import flash.events.MouseEvent;

addEventListener(MouseEvent.CLICK, onMouseClick2);
play();
function onMouseClick2(evt:MouseEvent)
{

   if(evt.target.name == "restartButton")
   {
          gotoAndStop(1, "Main Game");
          removeAllEvents2();
   }
}
 function removeAllEvents2()
{
   removeEventListener(MouseEvent.CLICK, onMouseClick2);      
}

还有我松散的屏幕

stop();
import flash.events.MouseEvent;
play();
addEventListener(MouseEvent.CLICK, onMouseClick2);

function onMouseClick3(evt:MouseEvent)
{

   if(evt.target.name == "restartButton")
   {
          gotoAndStop(1, "Main Game");
          removeAllEvents3();
}

}
function removeAllEvents3()
{
   removeEventListener(MouseEvent.CLICK, onMouseClick3);      
} 

那么,为什么我的游戏玩完一局后,计时器会无缘无故地加快速度。玩一局后,每 1 秒播放 2 秒,依此类推。

每次启动时您都在创建一个新计时器,因此您很可能在新游戏开始后将旧计时器 运行 放在后台。你需要调用 timer.stop() 来停止计时器,无论你想使用什么结束游戏的方法。您似乎只是在 removeAllEvents() 方法上这样做,但实际上您从未调用过该方法。