-
[RESOLVED] AS3 Countdown to a specific hour?
Hey, everybody.
I'm trying to do a countdown application for Flash, but I'm having some trouble.
I made the countdown so it receives a day, month and year variable to count to. That means it will give me the remaining days to an specific date. So far so good.
But this works only if the event is at midnight. I need it to work to some specific hour (e.g. 8PM of tomorrow), but I can't manage to do it.
Any help will be great appreciated!
-
Can you post up your code?
-
Originally Posted by ilike2
Can you post up your code?
Sure.
PHP Code:
stop();
var year:Number = 2013;
var month:Number = 1;
var day:Number = 3;
var finalDate:Date = new Date(year,month-1,day);
var timer:Timer = new Timer(1000);
timer.addEventListener(TimerEvent.TIMER, runTime);
timer.start();
function runTime(e:TimerEvent):void{
var currentTime:Date = new Date();
var timeRemaining:Number = finalDate.getTime() - currentTime.getTime();
if (timeRemaining >=0) {
var seconds:Number = Math.floor(timeRemaining/1000);
var minutes:Number = Math.floor(seconds/60);
var hours:Number = Math.floor(minutes/60);
var days:Number = Math.floor(hours/24);
var secondsText:String = (seconds%60).toString();
var minutesText:String = (minutes%60).toString();
var hoursText:String = (hours%24).toString();
var daysText:String = days.toString();
if (secondsText.length < 2) {secondsText = "0" + secondsText;}
if (minutesText.length < 2) {minutesText = "0" + minutesText;}
if (hoursText.length < 2) {hoursText = "0" + hoursText;}
if (daysText.length < 2) {daysText = "0" + daysText;}
day_txt.text = daysText;
hour_txt.text = hoursText;
min_txt.text = minutesText;
sec_txt.text = secondsText;
}
else {
timer.removeEventListener(TimerEvent.TIMER, runTime);
timer.stop();
gotoAndStop(2);
}
}
-
You need to specify the hour in the Date class like this.
Eg.
PHP Code:
var year:Number = 2013;
var month:Number = 1;
var day:Number = 3;
var hour:Number = 8;
var finalDate:Date = new Date(year,month-1,day, hour);
I’ve written a post about the Date countdown using xml which might help you. Also, take a look at the AS3 Date class for more information.
-
Originally Posted by ilike2
You need to specify the hour in the Date class like this.
Eg.
PHP Code:
var year:Number = 2013; var month:Number = 1; var day:Number = 3; var hour:Number = 8;
var finalDate:Date = new Date(year,month-1,day, hour);
I’ve written a post about the Date countdown using xml which might help you. Also, take a look at the AS3 Date class for more information.
Wow, I didn't know the Date class could receive an hour parameter, stupid me.
Thanks again, I shall take a look at the post!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|