Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 10-03-2006, 03:20 PM   #1
maximum rinse
Registarded User
 
Join Date: Sep 2006
Location: Brighton
Posts: 66
Red face Unable to reset clock timer

Dear all,


As a bit of an AS beginner, I'm hoping to get some help with my timer, which I believe is preventing me from restarting my game.
The timer starts when the game starts, and counts down from 30 seconds. When the time's up, some game results are displayed, and a restart button (restart_mc) pops up. When this is pressed, the game tries to restart for about 1 frame, but the game then returns directly to the analysis screen.
I recon this is probably the timer, as when I test my movie (Ctrl + enter) does not reset the timer either. I have to actually launch a new test window.


Code:
beginCount=30;
if(!done){     
time=Math.ceil(beginCount-getTimer()/(1000));   
time_txt.text = time
if(time<0){    
done=true;     
interface_mc.gotoAndPlay(end)                    
time_txt.text = 0;   
}         
}

restart_mc.onPress = function(){
replay();
}


function replay():Void{
beginCount = 30;
time = 30;
done = false;
interface_mc.gotoAndStop(game);
			
trace("RRRRRRREEEEEEEWIND");
			
init();
}

Do I need a new timer, or just fix the resetting of it? Any help would be appreciated!
Blessings and praises,
Tom
maximum rinse is offline   Reply With Quote
Old 10-03-2006, 04:03 PM   #2
Assertnfailure
as[org].addListener(this)
 
Assertnfailure's Avatar
 
Join Date: Dec 2005
Location: LA, California
Posts: 837
Default

getTimer returns a read-only value that represents the number of milliseconds that the swf has been running. You can't reset that.

I suggest checking out setInterval and setTimeout instead.
Assertnfailure is offline   Reply With Quote
Old 10-06-2006, 10:46 AM   #3
maximum rinse
Registarded User
 
Join Date: Sep 2006
Location: Brighton
Posts: 66
Default

thanks assert, I've had a look at setInterval, and nicked Kenzilla's code from this thread: http://www.actionscript.org/forums/s...ighlight=timer and then modified it slightly. I've now basically got this:

MC on stage with instance name of restart_mc, and a dynamic text box called my_txt.

Code:
restart_mc._visible = false
beginCount = 5;
function onEnterFrame():Void
{
    minutes = Math.floor(beginCount/60);
    seconds = beginCount%60;
    my_txt.text = seconds;
    if (seconds<=9) {
        my_txt.text=seconds;
    }
};
timeCounter = function () {
    beginCount--;
    if (minutes ==0 & seconds==1) {
        clearInterval(setIt);
		restart_mc._visible = true
        trace("stop");
		
    }
};
setIt = setInterval(this, "timeCounter", 1000);
//stop();


//////////////////////////REPLAY///////////////
restart_mc.onRelease = function(){
	
	beginCount = 5;
this._visible = false;
			
			
			trace("RRRRRRREEEEEEEWIND");
			
			onEnterFrame();
			}
Currently, when the reset button is clicked the timer does not run. It just sits there at the beginCount (-1).
So what else needs to be done to completely reset this timer?
maximum rinse is offline   Reply With Quote
Old 10-09-2006, 03:23 PM   #4
maximum rinse
Registarded User
 
Join Date: Sep 2006
Location: Brighton
Posts: 66
Default

OK a tough one..

I've attached a zip file with a fla & a swf for people to have a go with.

Can anyone point me in the right direction?

Cheers,
MR
Attached Files
File Type: zip timer.zip (6.8 KB, 96 views)
maximum rinse is offline   Reply With Quote
Old 10-09-2006, 04:33 PM   #5
darkzak
Registered User
 
Join Date: Apr 2003
Location: Salinas, California
Posts: 210
Default

You need to store the starting time and then subtract starting time from current time to get the time since you started counting down:

ActionScript Code:
restart_mc._visible = false; countTime = 5; startTime = getTimer(); this.onEnterFrame = countDown; function countDown():Void {     var curTime = (getTimer()-startTime)/1000;     var countDownTime = Math.round(countTime-curTime);     my_txt.text = countDownTime;     if (Math.round(countDownTime)<=0) {         countDownTime = 0;         restart_mc._visible = true;         this.onEnterFrame = undefined;     } } //////////////////////////REPLAY/////////////// restart_mc.onRelease = function() {     startTime = getTimer();     this._visible = false;     trace("RRRRRRREEEEEEEWIND");     this._parent.onEnterFrame = countDown;  };
darkzak is offline   Reply With Quote
Old 10-11-2006, 04:01 PM   #6
maximum rinse
Registarded User
 
Join Date: Sep 2006
Location: Brighton
Posts: 66
Default

Thanks for that Darkzak, I've managed to incorporate your suggestion into my timer, and have now come up with this. Thought I'd post it in case anybody else is looking for a simple timer with reset option..

Code looks something like this:
Code:
function init():Void {
done = false;
countTime = 30;
startTime = getTimer();
}

if (done == false) {
		var curTime = (getTimer()-startTime)/1000;
		var countDownTime = Math.ceil(countTime-curTime);
		time_txt.text = countDownTime;
		if (countDownTime<0) {
			done = true;
			interface_mc.time_txt.text = 0;
		}
	}

///////Reset button/////////
function restart():Void {
init();
}
maximum rinse is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
reset timer blaatorx ActionScript 1.0 (and below) 0 05-19-2005 08:56 AM
Reset Timer? mdharman ActionScript 1.0 (and below) 2 12-01-2004 12:37 AM
Running timer linked to computer clock symon ActionScript 1.0 (and below) 1 08-03-2004 10:06 AM
Flash5 clock to start @ 7:00:00pm regardless of real time -- how? Jessica lucidiastudios ActionScript 1.0 (and below) 35 10-30-2003 05:56 PM
reset timer larsKonrad Other Flash General Questions 4 04-11-2002 06:28 AM


All times are GMT. The time now is 06:22 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.