flash timer problemo!
- Started
- Last post
- 6 Responses
- armed_rob
Hey im doing this simple falsh game:
My problem is the timer, that is loaded into a mc called "loadmc"
If you just run ther game once (press "load spil") it works perfectly but if you play the game to the end or simply unload it (press "unload spil") the timer runs too fast (x 2?)
timer action:
i=0;
countID = setInterval(function (){
i++;
if(i==60){
_level2.gotoAndStop("endofgame...
clearInterval(countID);
}
},1000); // 1000ms=1sec
- Bozilla0
there's an anomaly with setInterval when you reuse the setInterval ID you created. You should delete that object after your clear the interval so if it starts again setInterval creates a new object alltogether.
so after clearInterval(countID) you say:
delete countID;
also avoid writing callback functions under setInterval like that....create a separate function and then just call it by name from setInterval:
in your case:
DoSomething=function(){
...
}
countID=setInterval(DoSomething, 1000);much easier to maintain and edit..
- armed_rob0
sorry but I dont get it!?
My script is now:
i=0;
countID = setInterval(function (){
i++;
if(i==60){
_level2.gotoAndStop("endofgame...
clearInterval(countID);
delete countID;
}
},1000); // 1000ms=1secRight? it dosent work...
- Bozilla0
How are you calling those frame actions the second time?
And can you explain more about what is it that you're trying to achieve with that i counter?
- armed_rob0
The thing is
I have the main scene that loads the "spillet.swf" on level 1('cause I got some outro actions) that loads the "hitthespot.swf" on level 2 (the game) and the "timer.swf" is loaded into a mc called "loadmc"
But if I click a new button thát unloads level2 and loads somthing new in level1, and the loads the game agian the problem is there!
Ahrm kinda hard to explain...
can I mail you a link to the test site?
- Bozilla0
do that..but I have to look at it tomorrow..it's 2:20am now and I gotta get some sleep..
- armed_rob0
Thanx but I need 2 get it done today (its morning in Denmark)