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 6925067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:44:33+00:00 2026-05-27T10:44:33+00:00

I tried this flex example from blog.flexexamples.com . This is a basic timer example.

  • 0

I tried this flex example from blog.flexexamples.com. This is a basic timer example.

But when timer crosses 30 min mark, it restarts automatically and starts showing negative time value(-1,-2 ..).

What is the problem ? Why it is showing negative value of timer, after it crosses 30 min mark ?

TimerDemo.mxml

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/08/14/creating-a-simple-timer-in-flex-with-the-flashutilstimer-class/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                layout="vertical"
                verticalAlign="middle"
                backgroundColor="white"
                creationComplete="init()">

    <mx:Script>
        <![CDATA[
            import flash.utils.Timer;
            import flash.events.TimerEvent;

            private const MIN_MASK:String = "00";
            private const SEC_MASK:String = "00";
            private const MS_MASK:String = "000";
            private const TIMER_INTERVAL:Number = 10;

            private var baseTimer:int;

            private var t:Timer;

            private function init():void {
                t = new Timer(TIMER_INTERVAL);
                t.addEventListener(TimerEvent.TIMER, updateTimer);
            }

            private function updateTimer(evt:TimerEvent):void {
                var d:Date = new Date(getTimer()-baseTimer);
                var min:String = (MIN_MASK + (d.minutes - 30.0)).toString();
                var sec:String = (SEC_MASK  + d.seconds).toString();
                var ms:String = (MS_MASK + d.milliseconds).toString();
                counter.text = String(min+":"+sec+"."+ms);
            }

            private function startTimer():void {
                baseTimer = getTimer();
                t.start();
            }

            private function stopTimer():void {
                t.stop();
            }
        ]]>
    </mx:Script>

    <mx:ApplicationControlBar dock="true">
        <mx:Button label="Start timer" click="startTimer()" />
        <mx:Button label="Stop timer" click="stopTimer()" />
    </mx:ApplicationControlBar>

    <mx:Label id="counter" fontSize="96" />

</mx:Application>
  • 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-27T10:44:33+00:00Added an answer on May 27, 2026 at 10:44 am

    I’m not really sure what you’re trying to do but I think I know what your problem is.
    By subtracting 30 of the min var, you only manipulate your output. So the actual timer is still counting the real minutes.

    If you want to subtract 30 minutes from your Timer you should do it when instantiating d:Date like so:

    const TIME_OFFSET:int = 1800000; //milliseconds in 30 minutes (1000*60*30)
    
    var d:Date = new Date(getTimer()-baseTimer-TIME_OFFSET);
    

    Remember to also remove the -30 for your var min:String

    I hope this is what you’re looking for.

    EDIT

    Given your comment about your getTimer() and baseTimer having a lot of difference, you should have a look at the getTimer() references. It states the following:

    Returns
    int — The number of milliseconds since the runtime was initialized (while processing ActionScript 2.0), or since the virtual machine
    started (while processing ActionScript 3.0). If the runtime starts
    playing one SWF file, and another SWF file is loaded later, the return
    value is relative to when the first SWF file was loaded.

    When I trace baseTimer and getTimer() within the startTimer() function they are always (more or less) the same. So it seems there is something off in your case.

    A workaround can be using new Date().time class instead of getTimer() like so:

    private function updateTimer(evt:TimerEvent):void {
    
        var d:Date = new Date(new Date().time - baseTimer);
        var min:String = (MIN_MASK + d.minutes).substr(-MIN_MASK.length);
        var sec:String = (SEC_MASK + d.seconds).substr(-SEC_MASK.length);
        var ms:String = (MS_MASK + d.milliseconds).substr(-MS_MASK.length);
        counter.text = String(min + ":" + sec + "." + ms);
    }
    
    private function startTimer():void {
    
        baseTimer = new Date().time;
    
        t.start();
    }
    

    More info on that can be found in the reference

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

Sidebar

Related Questions

Tried this: $('.link').click(function(e) { $.getScript('http://www.google.com/uds/api?file=uds.js&amp;v=1.0', function() { $('body').append('<p>GOOGLE API (UDS) is loaded</p>'); }); return
I tried this but it does not seem to be valid syntax. <xsl:element name=$myElementName></xsl:element>
I tried this example in Perl. Can someone explain why is it true? if
I tried this, but could not get through:- code behind protected HtmlTableRow trComment; protected
I tried this: def str1=good stuff 1) def str2 = str1.replaceAll('\)',' ') but i
I've tried the simple MVC example like this How to properly activate an MVC
I tried this XAML: <Slider Width=250 Height=25 Minimum=0 Maximum=1 MouseLeftButtonDown=slider_MouseLeftButtonDown MouseLeftButtonUp=slider_MouseLeftButtonUp /> And this
I tried this: ALTER TABLE My.Table DROP MyField and got this error: -MyField is
I tried this code to open a file in Python: f = open("/Desktop/temp/myfile.txt","file1") It
I tried this so far: <?php $error = ; $conn = pg_connect(host=localhost dbname=brittains_db user=brittains

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.