Copy link to clipboard
Copied
Hi,
how i can set a time for an energy bar like what you can see in facebook games?
and make it increase the energy bar value by 1 for each minute?
You can use the Timer class to have a Timer object repeatedly execute a function every minute. You define the Timer....
var energyTimer:Timer = new Timer(60000); // one minute delay - repeats indefinitely
energyTimer.addEventListener(TimerEvent.TIMER, addEnergy);
function addEnergy(evt:TimerEvent):void {
// adjust the energy value and the displays of it here
}
energyTimer.start(); // use when you want the Timer to begin
Copy link to clipboard
Copied
You can use the Timer class to have a Timer object repeatedly execute a function every minute. You define the Timer....
var energyTimer:Timer = new Timer(60000); // one minute delay - repeats indefinitely
energyTimer.addEventListener(TimerEvent.TIMER, addEnergy);
function addEnergy(evt:TimerEvent):void {
// adjust the energy value and the displays of it here
}
energyTimer.start(); // use when you want the Timer to begin
Copy link to clipboard
Copied
and i shall use energytimer.stop() to stop it when it full, well thank you Ned, was very helpful
Copy link to clipboard
Copied
You can stop it or you can put a condition in the function that inhibits adding more when the maximum is reached.
Copy link to clipboard
Copied
i don't know if that will work with my case, because there's no maximum, the player can have more than the full value by some ways, but the timer shall stop at the full value and full value+, i'm not sure about stopping the timer when the real value become more than the full value, i will give it a try if failed i think i will set anther q.
Copy link to clipboard
Copied
If you would havr some condition that would stoip the timer then that same condition can be used to prohibit the event handler function from processing anything while the timer continues running.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now