CountDownTimer AS3 Class

Custom class dependencies: CountdownTimerEvent

Everyone always wants to make a count down to something. This is a class that attempts to enclose all the functionality that is usually needed to achieve this task. There a so many examples and tutorials out there for creating a count down, that I won’t bother explaining much here. I will go into a little about the details of THIS class though.

This class is simply an extended instance of the Timer class.
With one major addition to achieve the count down functionality. That is of course the date to count down to! The rest of the properties are fairly elementary when it comes to a count down. There are properties for the ‘milliSeconds’, ‘seconds’, ‘minutes’, ‘hours’, and ‘days’ that remain until the specified date provided by the ‘date’ property.

Here is an example of the CountDownTimer class in action. This example also uses my other class ClipTextField for the timer display. The timer is of course the one to note here:

[swfobj src=”https://jidd.jimisaacs.com/files/2008/08/example-CountdownTimer.swf” width=”450″ height=”300″ align=”center” required_player_version=”10.0.0″]

Also something important to note is that this class dispatches 2 custom event types:

  • CountDownTimerEvent.TIMER
  • CountDownTimerEvent.TIMER_COMPLETE

These events are pretty self-explanatory, but I suggest looking over the event class regardless.

Now here is the actual class that does all the count down work for you, enjoy 😉

Comment if you have any questions, or suggestions.


Posted

in

, ,

by

Comments

3 responses to “CountDownTimer AS3 Class”

  1. jr Avatar
    jr

    I extended your CountDownTimer class so I could pass on any start date aswell (server time or what ever).
    The only thing i needed to change in CountDownTimer was

    private var _dateMillisecs:Number;

    to

    protected var _dateMillisecs:Number;

    So my class could read that variable.

    My extended class

    package com.deviouswork..countdown {

    import com.jidd.utils.CountdownTimer;

    import flash.utils.getTimer;

    /**
    * CountDown
    */
    public class CountDown extends CountdownTimer {

    private var _start_date : Date;

    public function CountDown(start_date : Date, end_date:Date) {
    _start_date = start_date;
    getTimer();
    super(end_date);

    }

    override public function get milliSeconds():Number {

    var newMS_num : Number = _start_date.getTime() + getTimer();
    return (super._dateMillisecs - newMS_num);
    }
    }
    }

  2. jimisaacs Avatar

    jr that is a good call. Didn’t event think of a start date. Maybe I’ll integrate it when I get some time.
    Thanks for the info 🙂

  3. […] can find the original post here. No Comments, Comment or […]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.