Subscribe

  • Subscribe  

Flash Timer Count Elapsed Time Since China’s Earthquake

Posted by Charles | May 19, 2008 .

To support the relief effort for China’s earthquake, the china-earthquake-relief.com needs a Flash timer to remind the time elapsed since the earthquake stroke at 14:28 May 12, 2008. So we made one.

flashtimer Flash Timer Count Elapsed Time Since Chinas Earthquake

It’s a Flash application developed right out of Adobe Flash CS3 Professional. It can be easily down with Flex but then the size of the swf could be much bigger than a pure Flash one.

There are not too much tricks once get the time calculation figured out, which is much harder than I thought. The main code is here:

stop();
countDownTxt.autoSize = true;

var year = 2008;
var month = 05;
var day = 11;
var hour = 23;
var minute = 28;
var date1 = new Date(year, month - 1, day, hour, minute);
trace(date1)

function countdown() {
    date2 = new Date();
    //trace(date2)
    difSec = Math.floor((date2 - date1)/1000);
    sec = difSec % 60;
    difMin = Math.floor(difSec/60);
    min = difMin % 60;
    difHours = Math.floor(difMin/60);
    hours = difHours % 24;
    days = Math.floor(difHours/24);
    if (sec < 10) {
        sec = "0" + sec;
    }
    if (min < 10) {
        min = "0" + min;
    }
    if (hours < 10) {
        hours = "0" + hours;
    }
    
    if(days < 0) {
        //trace("the countdown is over");
        gotoAndStop(2);
    }
    
    
    if(days < 10) {
        days = "00" + days;
    }
    if(days < 100 && days >= 10) {
        days = "0" + days;
    }
    
    countDownTxt.text = days + " Days " + hours + " Hr " + min + " Min" + " " + sec + " Sec";
    
}
var intervalID = setInterval(countdown, 100);

countdown();

Something to be noted:

  • You can switch the date2 and date1 in difSec = Math.floor((date2 – date1)/1000); to make the app to be either countdown or countup (time elapsed, in my case)
  • The initial variables are the time you want to start counting at. In the China Earthquake case, I factored in that based on PTS (GMT -8) time zone. Obviously, if you are in a different time zone, the elapsed time will be wrong.
  • So, it’ll be nicer to take in the initial variables from flashvars. Go knock yourself off on that. That’s why you can get all the source here.

So, go download the flashtimer.zip from here. It contains the swf and fla files. If you made improvements, drop me a copy please.

Leave a Comment

If you would like to make a comment, please fill out the form below.


Name

Email

Website

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Comments

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word


Related Posts

1 Comment so far
  1. Watch With Countdown Timer  November 23, 2015 12:16 pm

    Countdown Timer Designs make ever been an galvanic Watch With Countdown Timer conception of any circumstance.
    Investigation backwards to see how overmuch term is sect before an circumstance increases the anxiousness of the life.
    It would be great if you had the opportunity to create your really own Software Countdown Timer.
    A obovate to use usage you would savour having.

    By simply adding a widget you could savour the Downloadable Countdown Timer on your
    strainer.

<

Error. Page cannot be displayed. Please contact your service provider for more details. (25)


Direct TV Offers - usdirect has the best directtv deals