Link to home
Start Free TrialLog in
Avatar of cdr21
cdr21

asked on

Increment a counter variable based every x seconds


What is the best way in actionscript to handle incrementing a counter variable, say by 1 unit, every 20 seconds....

This will be used in a little project to simulate the number of visitors entering an amusement park....

-cdr
ASKER CERTIFIED SOLUTION
Avatar of Jakob_E
Jakob_E
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Billystyx
Billystyx

another less easy to use way (just for information)
is the getTimer()
set the variable in frame1:
time=getTimer();
counter=0;
frame2:
if(time+20000<getTimer()){
counter ++;
time=getTimer();
}
frame3:
gotoAndPlay(2);


Billystyx
but Jakob's method is the newer and (better) one.
Avatar of cdr21

ASKER


...I can be pretty dumb when it comes to this actionscripting stuff....

Below is the code I'm using on a variable called 'visits'...I 'm needing to initilize it to around 37000...so far I do have it showing up properly at 37000 in a dyanamic text box...but it is not incrementing....

any ideas why not?

-cdr


onClipEvent (enterFrame) {

var visits = 37000

function increaseCountV() { visits ++ }

// SetInterval makes a call to your function increaseCount every 20000 millisecond (20 secsonds)

counterInterval = setInterval(increaseCountV, 10000)


}
the 2 pieces of code jakob provided go on the root timeline, on a single frae - not on an mc.

Billystyx