Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 3 of 3

Thread: Count-Down Timer in AS3.0

  1. #1

    Count-Down Timer in AS3.0

    HI Friends,
    I am making a CountDown timer....

    Code:
    var endDate:Date;
    var timerEvent:Timer;
    
    function countDownTimer (year:Number, month:Number, day:Number, hour:Number = 12, second:Number= 0) {
        endDate = new Date(year, (month-1), day, hour, second);
        trace (endDate );
        timerEvent = new Timer(1000);
        trace ("timerEvent " + timerEvent );
        timerEvent.addEventListener (TimerEvent.TIMER, updateTimer);
    }
    
    function updateTimer (e:TimerEvent) {
        trace ("si");
        var ourDate:Date = new Date();
        var diffirence:Number = endDate.getTime() - ourDate.getTime();
    
        var seconds:Number = Math.floor(diffirence/1000);
        var minute:Number = Math.floor(seconds/60);
        var hours:Number = Math.floor(minute/60);
        var days:Number = Math.floor(hours/24);
    
        seconds %= 60;
        minute %= 60;
        hours %= 24;
    
        var sec:String = String(seconds);
        var min:String = String(minute);
        var hrs:String = String(hours);
        var day:String = String(days);
    
        dayText.text = days + ":" + hours + ":" + minute + ":" + seconds;
    }
    But its not working..
    Please help me....

    // I am also sending the file.
    Attached Files Attached Files

  2. #2
    Code:
    // after this line:
    timerEvent.addEventListener (TimerEvent.TIMER, updateTimer);
    // add this - you need to start the timer, it doesn't automatically play
    timerEvent.start();

  3. #3

    Countdown Timer

    Hi Friends,

    I have made a countdown timer and its working fine...

    But problem is when we jump to next frame or other frame the timer should be restart but its not happening...

    I did this with

    secTimer.stop (); // in first frame
    secTimer.start (); // in second frame

    but its not working..
    How can i do this.

    here is my code
    Code:
    stop()
    
    var totSec:int = 5;
    var totTime:Number = 1000 * totSec;
    
    var secTimer:Timer = new Timer(1000,totSec-1);
    secTimer.start ();
    secTimer.addEventListener (TimerEvent.TIMER, updateClock);
    
    function updateClock (t:TimerEvent) {
        var timePassed:int = totTime - getTimer();
        var second:int = Math.floor(timePassed/1000);
        var minute:int = Math.floor(second/60);
        //trace ("second : " + second);
        second %= 60;
        var sec:String = "";
        sec = String(second);
    
        if (second < 10)
        {
            sec = "0" + second;
        }
        var showTime:String =  "Time : " + minute + ":" + sec;
        timeDisplay.text = String(showTime)
        trace (showTime);
    
    
        if (minute == 0 && second == 0 )
        {
            addEventListener (Event.ENTER_FRAME, stopTime);
            trace ("Times up");
           secTimer.start ();
           
        }
        
        
    
    }
    
    function stopTime (e:Event) {
        nextFrame()
    }
    and this is on second frame..
    Code:
    totSec = 20;
    totTime = 1000 * totSec;
    secTimer.start ();

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012