'How to do countdown timer for refilling?

I am currently working on Adobe AIR app game that requires passes for each level. I would like to do the function when the passes has reaches 0, the player needs to wait for 2hrs for their passes to be refilled. Once the countdown timer ends, the passes will be refilled to 3.

How would it be possible for AS3 to do it and keep the timer running even the app is closed?



Solution 1:[1]

Simplest way imo would be to store timer start date/time in SharedObjects and now even if you kill the app, you can get stored date/time and calculate how much time passed since then. If more than 2h you just refill passes. If less, you set the timer for the amount of time you have left.

But like @Vesper said, this approach is vulnerable and you can "cheat" by changing local time. If you need your app to prevent such a thing you should never trust the client and you should use server side. Flow can be something like:

  • On app start, sent Handshake request to the server (by using URLRequest for example)

  • Server respond with current time and you calculate time lapsed based on that value.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 3vilguy