The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


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