Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

creating a (proper) time counter in AS3

How do you create a time counter in as3? Some simple search on google will point you to the AS3 class Timer that actually is a counter of events and not a proper time counting utility.

I have seen this http://blogs.adobe.com/pdehaan/2006/07/using_the_timer_class_in_actio.html and I am a little worried by the fact that it is official documentation that should work.

Q: Where exactly is the problem?

A: The Timer class executes operations in a stack of events and if you have a pretty heavy application I can bet the timer will distort your time if you use it to count seconds, milliseconds or whatever.

like image 784
Mike Avatar asked Sep 19 '12 08:09

Mike


1 Answers

If you're looking to accurately measure short intervals of time you just use the getTimer() function (flash.utils.getTimer), which returns the number of milliseconds elapsed since Flash player started. The prototypical simple StopWatch class is:

public class StopWatch {
    private var _mark:int;
    private var _started:Boolean = false;

    public function start():void { _
        mark = getTimer(); 
        _started = true;
    }

    public function get elapsed():int { 
        return _started ? getTimer() - _mark : 0; 
    }
}

More Info:

like image 178
Joshua Honig Avatar answered Nov 15 '22 05:11

Joshua Honig