Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6890653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:18:35+00:00 2026-05-27T06:18:35+00:00

Hey guys so I’ve got a working Timer, which will stop() when I call

  • 0

Hey guys so I’ve got a working Timer, which will stop() when I call it to and start, but I can’t get it to reset(). It just starts from where it left off.

Code for the timer

package 
{

    import flash.display.MovieClip;
    import flash.display.Stage;
    import flash.text.TextField;
    import flash.events.Event;
    import flash.utils.Timer;
    import flash.events.TimerEvent;


    public class Score extends MovieClip
    {
        public var second:Number = 0;
        public var timer:Timer = new Timer(100);
        private var stageRef:Stage;
        private var endScore:displayFinalScore;

        public function Score(stageRef:Stage)
        {
            x = 560.95;
            y = 31.35;
            this.stageRef = stageRef;
            this.endScore = endScore;

            timer.addEventListener(TimerEvent.TIMER, scoreTimer);
            timer.reset();
            timer.start();
            updateDisplay();


        }

        public function scoreTimer(evt:TimerEvent):void
        {

            second += 1;
            updateDisplay();
        }

        public function get10Points(points:Number) : void
        {
            second += points;
            updateDisplay();
        }

        public function finalScore() : void {

            timer.stop();
        }

        public function resetTimer(): void {

            timer.reset();
            timer.start();
            updateDisplay();
        }

        public function updateDisplay(): void
        {

            scoreDisplay.text = String("Score: " +second);

        }
    }
}

Code for where I call it to do things:

private function sendGameOver(e:Event) : void
{
    //Stop the stage and remove everything
    stop();
    stage.removeChild(ourBoat);
    stage.removeChild(score);
    removeEventListener(Event.ENTER_FRAME, loop);

    //Add the end score     
    addChild(endScore);
    //Add the game over  
    addChild(endGame);
    addChild(playAgain);

    //Add the play again options
    playAgain.addEventListener(MouseEvent.CLICK, newGame);
    score.finalScore();


}

public function newGame (e:MouseEvent) :void 
{
    score.resetTimer();
    gotoAndPlay(1);
    removeChild(endGame);
    removeChild(endScore);
    removeChild(playAgain);
    stage.addChild(ourBoat);
    stage.addChild(score);

    //Keep the boat within the desired boundaries
    ourBoat.x = stage.stageWidth / 2;
    ourBoat.y = stage.stageHeight - 100;

    addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:18:36+00:00Added an answer on May 27, 2026 at 6:18 am

    In your resetTimer() function you’re resetting your Timer (this works just fine). But the thing is you’re not using the Timer itself to calculate your seconds variable. So when you start the Timer again the seconds will continue where they left off.

    What you need to do is reset the seconds variable.

    public function resetTimer(): void 
    {
        seconds = 0;
        timer.reset();
        timer.start();
        updateDisplay();
    }
    

    Keep in mind that, in this case, your Timer is just a tool you use to display your own interpretation of the seconds stored in your seconds variable. So manipulating the Timer won’t change the seconds nor the display.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys i wrote a quick test. I want delete to call deleteMe which
Hey guys i want to execute my SQL statement but im having synatx trouble,
Hey Guys, here is my code for this, the only help i get from
Hey guys, I've got a neat dropdown menu and also a flashfile in my
Hey guys. I'm not much of a programmer, but still need to do some
Hey guys, I have a little button functionality that is not erring, but also
Hey guys, first time using stackoverflow. can you guys help me debug? Heres the
Hey guys. I am trying to get the selected option in an each loop.
hey guys, how can I just achieve this simple layout? I'm hoping the answer
Hey guys, I want to parse some xml but I don't know how I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.