A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [RESOLVED] AS3 Countdown to a specific hour?

  1. #1
    Member
    Join Date
    Oct 2010
    Posts
    55

    resolved [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!

  2. #2
    Senior Member
    Join Date
    Jun 2008
    Posts
    549
    Can you post up your code?

  3. #3
    Member
    Join Date
    Oct 2010
    Posts
    55
    Quote Originally Posted by ilike2 View Post
    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.TIMERrunTime);
    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.TIMERrunTime);
            
    timer.stop();
            
    gotoAndStop(2);
        }
        


  4. #4
    Senior Member
    Join Date
    Jun 2008
    Posts
    549
    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,dayhour); 
    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.

  5. #5
    Member
    Join Date
    Oct 2010
    Posts
    55
    Quote Originally Posted by ilike2 View Post
    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,dayhour); 
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center