Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to create a count up timer...

Community Beginner ,
Feb 29, 2012 Feb 29, 2012

This is the code I have for a count down timer in days, hours, minutes, and seconds but I would just like a timer that counts up from 0 until what ever number I would like and I would like to be able to control the pace....any ideas?

var targetDate:Date = new Date(2012,3,5,13);

addEventListener(Event.ENTER_FRAME, loop);

function loop(e:Event):void

{

    var nowDate:Date = new Date();

    var ms:Number = targetDate.getTime() - nowDate.getTime();

    var sec:Number = Math.floor(ms/1000);

    var min:Number = Math.floor(sec/60);

    var hr:Number = Math.floor(min/60);

    var day:Number = Math.floor(hr/24);

   

    sec = sec % 60;

    min = min % 60;

    hr = hr % 24;

   

    daytxt.text = day.toString();

    hrtxt.text = (hr < 10) ? "0" + hr.toString() : hr.toString();

    mintxt.text = (min < 10) ? "0" + min.toString() : min.toString();

    sectxt.text = (sec < 10) ? "0" + sec.toString() : sec.toString();

TOPICS
ActionScript
6.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 29, 2012 Feb 29, 2012

Here's an extremely simple counter that will count up from 0 at a rate of one second. It just uses a Timer object.

import flash.utils.Timer;

import flash.events.TimerEvent;

var upCounter:int = 0;

var myTimer:Timer = new Timer(1000,0);

myTimer.addEventListener("timer", timerHandler);

myTimer.start();

function timerHandler(event:TimerEvent):void

{

          trace(upCounter);

          upCounter++;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 29, 2012 Feb 29, 2012

if I upload that to a website will it count up continuously?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 29, 2012 Feb 29, 2012

Yes. If you want to have it start based on some event, then put the line "myTimer.start();" in a function.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 16, 2012 Jul 16, 2012

Hi,

i'm trying to adapt this code for my count-up timer. i need a counter that ticks up every two seconds.

i pasted the code below into a keyframe in flash. i then put a text field with a zero in it on the stage. when i test the movie, i see a flickering zero.

what am i doing wrong?!

thanks in advance,

thomas

___________________________________________

import flash.utils.Timer;

import flash.events.TimerEvent;

var upCounter:int = 0;

var myTimer:Timer = new Timer(2000,7500);

myTimer.addEventListener("timer", timerHandler);

myTimer.start(1);

function timerHandler(event:TimerEvent):void

{

          trace(upCounter);

          upCounter++;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 16, 2012 Jul 16, 2012
LATEST

change

myTimer.start(1);

to

myTimer.start();

The start function takes no arguments.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines