Go Back   kirupaForum > Flash > ActionScript 1.0/2.0

Reply
 
Thread Tools Display Modes
Old 11-22-2009, 09:51 PM   #1
spellbound55
Registered User
 
spellbound55's Avatar
2 minute countdown timer

Hi, I'm making a side scrolling flash game called Kit-Run using actionscript 2.0. I want to give each level a two minute time limit - ideally to have an enemy mc load that comes and kills you when it reaches 00:00.

I've found a lot of tutorials that count down time limits for dates, but none for a simple minute counter. I've started with a dynamic text field called "timeDisplay". What do I now??

thanks!
spellbound55 is offline   Reply With Quote

Sponsored Links (Guests Only) - Register | Need Help?
 

Old 11-23-2009, 01:35 AM   #2
NamikazeMinato
Registered User
 
NamikazeMinato's Avatar
Location Kochi,India

Posts 48
Code:
timerDisplay.text="00:02:00";
var dispSecs=60;
var dispMins=2;

var timerInterval=setInterval(countDown,1000);

function countDown()
{
   dispSecs--;
   if(dispSecs==59)
  {
     dispMins--;
  }
  if(dispSecs==0)
  {
    dispSecs=59;
  }
  if(dispMins==0)
  {
    clearInterval(timerInterval);//STOPS THE TIMER....
  }
  timeDisplay.text=prependZero(dispMins)+":"+prependZero(dispSecs);
 }
 
function prependZero(num)
{
  if(num<10)
  {
    num="0"+num;
  }
  return(num);
}
I think this will help you....

Cheers...
NamikazeMinato is offline   Reply With Quote
Old 11-23-2009, 02:05 AM   #3
spellbound55
Registered User
 
spellbound55's Avatar
that works beautifully! thank you
spellbound55 is offline   Reply With Quote
Old 11-23-2009, 02:59 AM   #4
spellbound55
Registered User
 
spellbound55's Avatar
Quote:
Originally Posted by spellbound55 View Post
that works beautifully! thank you

actually I take that back! it only ALMOST work perfectly.. once the dispSecs reaches zero, they start over again at 59 and the minutes never make it down to zero and the interval doesnt get cleared. It just loops for all eternity. I'm going to tweak it a little but if you see the problem before I do please let me know!
spellbound55 is offline   Reply With Quote
Old 11-23-2009, 03:41 AM   #5
spellbound55
Registered User
 
spellbound55's Avatar
okay figured it out:

changed

if(dispMins==0)
{
clearInterval(timerInterval);//STOPS THE TIMER....

to

if(dispMins==0 && dispSecs==0){
clearInterval(timerInterval);

now it works! Couldnt have done it on my own though, so thanks again.
spellbound55 is offline   Reply With Quote
Old 11-23-2009, 05:21 AM   #6
NamikazeMinato
Registered User
 
NamikazeMinato's Avatar
Location Kochi,India

Posts 48
Sorry spellbound...

My bad....

Cheers..
NamikazeMinato is offline   Reply With Quote
Reply

Tags
actionscript, countdown, minute, time limit, timer


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:44 PM.

SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple. flash components
Creative web apps. Make your own free flash banners and photo slideshows.
Check out the great, high-quality flash extensions. Buy or sell stock flash, video, audio and fonts for as little as 50 cents at FlashDen.

Flash Transition Effects

Flash Effect Tutorials

Digicrafts Components
Flash effects. Art without coding. Upload, publish, deliver. Secure hosting for your professional or academic video, presentations & more. Screencast.com
Streamsolutions Content Delivery Networks Flipping Book - page flip flash component.
Flash-Gallery.com - Get your flash photo gallery (flash component or swf gallery Learn how to advertise on kirupa.com
 

cdn
content delivery network (cdn)

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Copyright 2010 - kirupa.com Copyright 2010 - kirupa.com