Skip navigation
Daniel12378992
Currently Being Moderated

How to execute a function every certain period of time?

Apr 26, 2013 8:33 AM

Tags: #help #pro #3.0 #swf #action_script_3 #actionscript #flash_professional #actions #cs6 #flash_cs6

Hi guys!I have a very simple question.I have a budget and income variables.I want to make the player to recieve income every minute.But it's quite uncofortable to create a loop for every particular minute like if (minutes==1){} if (minutes==2){} and so on.How can make this loop occur every 60 seconds?

Thanks

 

var fl_SecondsElapsed_3:Number = 1;

var minutes=2/fl_SecondsElapsed_3;

 

 

function fl_TimerHandler_3(event:TimerEvent):void

{

          trace("Прошло секунд: " + fl_SecondsElapsed_3);

          fl_SecondsElapsed_3++;

          if (fl_SecondsElapsed_3==60){

budget=budget+income;

}

}

 
Replies
  • Currently Being Moderated
    Apr 26, 2013 8:38 AM   in reply to Daniel12378992

    YOur function appears to be set up to work with a Timer class object, so all you seem to be mising is that Timer class object.  Create the Timer and set it to trigger every 60 seconds (60000 msecs)

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 30, 2013 6:40 PM   in reply to Daniel12378992

    Yes, then you can eliminate the portion of that function that counts the 60 seconds

     
    |
    Mark as:
  • Currently Being Moderated
    May 3, 2013 6:52 PM   in reply to Daniel12378992

    The first argument in the Timer creation is the delay time, so the code would be more like....

     

    var fl_TimerInstance_3:Timer = new Timer(60000);

     

    The second argument is the number of times to repeat the timing.  If you do not specify it a number of times (or set it to 0), it will repeat indefitnitely.  To have it only trigger once you specify 1.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points