Reputation: 8924
Per Adobe getTimer() is:
Used to compute relative time. For a Flash runtime processing ActionScript 3.0, this method returns the number of milliseconds that have elapsed since the Flash runtime virtual machine for ActionScript 3.0 (AVM2) started.
Since getTimer returns a int which:
The int class lets you work with the data type representing a 32-bit signed integer. The range of values represented by the int class is -2,147,483,648 (-2^31) to 2,147,483,647 (2^31-1)
What will getTimer() return after the 2,147,483,647 millisecond? That would roughly be 24.85 straight days of running I think. Not a usual situation but for digital signage and kiosk context that is entirely feasible.
Should getTimer() be avoided in these situations? Would a Date.UTC() object be safer since it returns a Number type?
Upvotes: 4
Views: 2176
Reputation: 8159
My guess is it will loop back on itself, just as int will.
var nt:int = int.MAX_VALUE + 10; //outputs -2147483639
var nt2:int = int.MIN_VALUE + 9; //outputs -2147483639
As you can see, MAX + 10
is the same as MIN + 9
(have to account for the min value itself, obviously). So when you hit that 24 day mark, it will possibly look like -24 days and start going back up.
There is also a chance that the function itself doesn't return the actual time, but something along these lines:
return timer % int.MAX_VALUE;
That will reset the time each time it hits the MAX_VALUE to 0, using simple modulus. I honestly would not be surprised if this is what they do (since you don't want a negative runtime, obviously)
Upvotes: 1