Skip to main content
Eslam_Yosef
Participating Frequently
October 31, 2014
Answered

how to make energy bar increase by 1 each minute and set a timer for it?

  • October 31, 2014
  • 1 reply
  • 467 views

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?

This topic has been closed for replies.
Correct answer Ned Murphy

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

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
October 31, 2014

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

Eslam_Yosef
Participating Frequently
October 31, 2014

and i shall use energytimer.stop() to stop it when it full, well thank you Ned, was very helpful

Ned Murphy
Legend
October 31, 2014

You can stop it or you can put a condition in the function that inhibits adding more when the maximum is reached.