Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 02-06-2009, 06:15 PM   #1
mr-elephant
Registered User
 
Join Date: Feb 2009
Posts: 2
Default help with a countdown timer problem

I've successfully managed to create a countdown timer with the help of a tutorial (I know nothing about actionscript), and everything is working as intended.

However, I need additional functions, and I don't know how to achieve this.

I need to have the timer start counting down to a NEW date when it reaches zero. Is this possible, and if so; how?

Please explain as if I'm 10 years old.

Here's the code:
Code:
//Create your Date() object
var endDate:Date = new Date(2009,1,13);
//Create your Timer object
//The time being set with milliseconds(1000 milliseconds = 1 second)
var countdownTimer:Timer = new Timer(1000);
//Adding an event listener to the timer object
countdownTimer.addEventListener(TimerEvent.TIMER, updateTime);
//Initializing timer object
countdownTimer.start();
//Calculate the time remaining as it is being updated
function updateTime(e:TimerEvent):void
{
	//Current time
	var now:Date = new Date();
	var timeLeft:Number = endDate.getTime() - now.getTime();
	//Converting the remaining time into seconds, minutes, hours, and days
	var seconds:Number = Math.floor(timeLeft / 1000);
	var minutes:Number = Math.floor(seconds / 60);
	var hours:Number = Math.floor(minutes / 60);
	var days:Number = Math.floor(hours / 24);
	
	//Storing the remainder of this division problem
	seconds %= 60;
	minutes %= 60;
	hours %= 24;
	
	//Converting numerical values into strings so that 
	//we string all of these numbers together for the display
	var sec:String = seconds.toString();
	var min:String = minutes.toString();
	var hrs:String = hours.toString();
	var d:String = days.toString();
	
	//Setting up a few restrictions for when the current time reaches a single digit
	if (sec.length < 2) {
		sec = "0" + sec;
	}
	
	if (min.length < 2) {
		min = "0" + min;
	}
	
	if (hrs.length < 2) {
		hrs = "0" + hrs;
	}
	
	if (d.length < 2) {
		d = "0" + d;
	}
	
	//Stringing all of the numbers together for the display
	var time:String = d + ":" + hrs + ":" + min + ":" + sec;
	//Setting the string to the display
	time_txt.text = time;
	
	if((d <= "00")&&(hrs <= "23")&&(min <= "59")&&(sec <= "59")){
    	countdownTimer.stop();
    	var newTime:String = "tomorr:ow";
    	time_txt.text = newTime;
	}
	
	else {
		time = d + ":" + hrs + ":" + min + ":" + sec;
		time_txt.text = time;	
	}
}
mr-elephant is offline   Reply With Quote
Old 02-09-2009, 06:21 PM   #2
mr-elephant
Registered User
 
Join Date: Feb 2009
Posts: 2
Default

Anyone?
mr-elephant is offline   Reply With Quote
Old 10-07-2009, 12:37 AM   #3
ronny.depp
[Interactive Developer]
 
Join Date: Apr 2009
Location: Lahore, Pakistan
Posts: 9
Send a message via MSN to ronny.depp Send a message via Yahoo to ronny.depp Send a message via Skype™ to ronny.depp
Lightbulb Countdown Timer Help

Anyone seeking solutions to AS3 Countdown Timer must see my Posts on this Subject:

My Post#1: http://www.actionscript.org/forums/s....php3?t=198683

My Post #2: http://www.actionscript.org/forums/s....php3?p=929804

You will also find source files in my posts in .zip format there.

Download the Source files here: http://www.actionscript.org/forums/a...9&d=1254793145 - (zip file archive is here)

Also Subscribe to these Threads to get updates on this Topic (ActionScript 3 CountdownTimer) from me.

sincerely
--
Ronny Depp

Last edited by ronny.depp; 10-07-2009 at 12:40 AM.
ronny.depp 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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Countdown timer with input interface memykes ActionScript 2.0 5 10-16-2008 01:32 PM
Countdown timer is not working Flasher10 ActionScript 3.0 1 08-19-2008 06:12 PM
Newbie trying to create a Global Countdown timer! Stewade ActionScript 2.0 0 05-05-2008 03:20 PM
dynamic countdown timer chevron8653 ActionScript 2.0 4 05-27-2006 11:15 PM
Countdown Problem m02a ActionScript 2.0 5 05-13-2006 02:25 AM


All times are GMT. The time now is 09:04 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.