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

  • SEARCH
  • Home
  • 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 7685323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:13:32+00:00 2026-05-31T19:13:32+00:00

I have a timer script: import flash.utils.Timer; import flash.events.TimerEvent; var secs:Number = 30;//second var

  • 0

I have a timer script:

import flash.utils.Timer;
import flash.events.TimerEvent;

var secs:Number = 30;//second
var mins:Number = 2;//minute
var sec_t:String;
var min_t:String;

var my_timer:Timer = new Timer(1000);
my_timer.addEventListener(TimerEvent.TIMER, timerHandler);
my_timer.start();
showTimer.text = "02:30";

function timerHandler(event:TimerEvent):void
{
    if (secs == 0)
    {
        if (mins == 0)
        {
            my_timer.stop();
            trace("Countdown is finished.");
            showTimer.text =String(min_t+sec_t)+" Times Up";
            return;
        }
        else
        {
            --mins;
            secs = 59;
        }
    }
    else
    {
        --secs;
    }
    sec_t = (secs < 10) ? "0" + String(secs):String(secs);
    min_t = (mins < 10) ? "0" + String(mins) + ":":String(mins) + ":";
    trace(min_t+sec_t);
    showTimer.text =String(min_t+sec_t);
}

wrongBtn.addEventListener(MouseEvent.CLICK, wrongClick);
function wrongClick(event:MouseEvent):void
{
    secs = secs - 10;
}

correctBtn.addEventListener(MouseEvent.CLICK, correctClick);
function correctClick(event:MouseEvent):void
{
    secs = secs + 10;
}

There are two buttons, wrongBtn and correctBtn.
wrongBtn will decrease time by 10 seconds, correctBtn will increase time by adding 10 seconds.
But when the timer second is around 2:05 and I press wrongBtn, the time is displayed incorrectly, like this: “2:0-5”. Likewise, when the time is around 2:55 and I press the correctBtn, the time will be displayed as “2:65″…

How can I get this working, so that the output is displayed correctly?

  • 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-31T19:13:33+00:00Added an answer on May 31, 2026 at 7:13 pm

    Keep one timer count instead of separate minutes and seconds. You can safely increase and decrease it, and always keep the correct time. To make it readable, just format the output:

    import flash.events.TimerEvent;
    import flash.utils.Timer;
    
    
    var timeRemaining:int = 150; // 150 seconds => 2:30 mins
    
    showTime.text = formatTimeRemaining();
    
    var timer : Timer = new Timer (1000);
    timer.addEventListener (TimerEvent.TIMER, onTimer);
    timer.start();
    
    
    function onTimer ( ev:TimerEvent ) : void {
        timeRemaining--;
        if (timeRemaining < 0) {
            timeRemaining = 0;
            loseGame();
        }
        else 
            showTime.text = formatTimeRemaining ();
    }
    
    function formatTimeRemaining () : String {
        var mins : int = int (timeRemaining / 60);
        var minstr : String = mins < 10 ? "0"+mins : ""+mins;
        var secs : int = timeRemaining % 60;
        var secstr : String = secs < 10 ? "0"+secs : ""+secs;
    
        return minstr+":"+secstr;
    }
    
    function loseGame () : void {
        timer.stop();
        trace("Countdown is finished.");
        showTime.text = formatTimeRemaining() + (" Time's Up!");
    }
    
    wrongBtn.addEventListener(MouseEvent.CLICK, wrongClick);
    function wrongClick(event:MouseEvent):void
    {
        timeRemaining -= 10;
    }
    
    correctBtn.addEventListener(MouseEvent.CLICK, correctClick);
    function correctClick(event:MouseEvent):void
    {
        timeRemaining += 10;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my GamePlay.as package com.work.scripts { import flash.display.Stage; import flash.events.Event; import flash.utils.Timer; import
I have the following script that changes my image on a timer: var da
I have the following script: Timer=0; function countdown(auctionid){ var auctions; var divs; Timer=Timer+1; if((Timer%10==0)||(Timer==1)){
I have created a php script to import rss feed into the database. The
I have this class: from threading import Thread import time class Timer(Thread): def __init__(self,
I have this script- import lxml from lxml.cssselect import CSSSelector from lxml.etree import fromstring
I have the following script defining a tzinfo object: import time from datetime import
I have a very basic python script that does HTTP connection. import socket def
I'm trying to have a jsfl script import a video into my .fla project
Hello! I have the following script: import os import stat curDir = os.getcwd() autorun_signature

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.