Enter_Frame Based Timer Class made in AS3 .
Custom Timer Class’s Properties & Methods are similar to Flash’s Timer Class, that means it’s easy to switch from Flash’s Timer to Custom Timer.
Why Custom Timer Class:
- Custom Timer Class is more accurate than Flash’s Timer Class (view differences in preview, Flash’s Timer delays a little more every second…leave preview on for some minutes then look at differences).
- You can stop then restart from same millisecond, instead of Flash’s Timer Class where you stop then restart from last currentCount.
How to use:
- Place .as file in your project’s folder
- Import class: e.g. import com.utils.CustomTimer;
- Create the Timer using new operator:
new CustomTimer(delay, callback, repeatCount, startTimer); - If startTimer is false, use
.start()to start timer.
Public Properties & Methods:
CustomTimer(timerDelay:int, callback:Function, repeatCount:uint = 1, startTimer:Boolean = false):voidCreates a precise Timer
start():voidStarts Timer
reset():voidResets Timer
pause():voidPauses Timer, use start function to unpause
create():voidCreates Timer
destroy():voidDestroyes Timer, you can create it again using create function
getSeconds(toInt:Boolean):NumberGets Seconds elapsed from start in float number
get state():StringTimer’s state (On, Off, Paused, Finished), this property is read-only
set callback(val:Function):voidFunction to run after timer finished
get callback():FunctionFunction to run after timer finished
set running(val:Boolean):voidtrue if Timer is running, false if not
get running():Booleantrue if Timer is running, false if not
get elapsedTime():intElapsed time from start, this property is read-only
get lastingTime()intLasting time until finish, this property is read-only
set delay(val:int):voidTimer Delay in milliseconds
get delay():intTimer Delay in milliseconds
set currentCount(val:uint):voidTotal Times Timer has finished since it started
get currentCount():uintTotal Times Timer has finished since it started
set repeatCount(val:uint):voidTimes to repeat the Timer, if repeatCount is 0 it will repeat infinitely
get repeatCount():uintTimes to repeat the Timer, if repeatCount is 0 it will repeat infinitely
get currentCount():uintTotal Times Timer has finished since it started
set repeatCount(val:uint):voidTimes to repeat the Timer, if repeatCount is 0 it will repeat infinitely
get repeatCount():uintTimes to repeat the Timer, if repeatCount is 0 it will repeat infinitely

