Articles Tagged 'countdown'

A class countdown in Javascript

In the post with 3D CountDown FIVe3D (see also How I Did It: write a countdown to Flash ), was proposed to create a class object in Actionscript CountDown, here's a similar version in JavaScript:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/ **
* Class CountDown
*
* @ Author Giovambattista Fazioli
* @ @ Email g.fazioli undolog.com
* @ Web http://www.undolog.com
*
Dd * @ param (string) 'month day, year'
*
* /
dd ) { function countdown (dd) {
/ / Init target time
new Date ( dd ) ; var target = new Date (dd);
= target. getTime ( ) ; this. targetTime = target. getTime ();

/ **
* Refresh countdown
* /
= function ( ) { this. refresh = function () {
new Date ( ) ; var today = new Date ();
today. getTime ( ) ; var today = currentTime. getTime ();
/ / Time left
( this . targetTime - currentTime ) ; this. _leftMilliseconds = (this. targetTime - currentTime);
Math. floor ( this ._leftMilliseconds / 1000 ) ; this. _leftSeconds = Math. floor (this. _leftMilliseconds / 1000);
Math. floor ( this ._leftSeconds / 60 ) ; this. _leftMinutes = Math. floor (this. _leftSeconds / 60);
Math. floor ( this ._leftMinutes / 60 ) ; this. _leftHours = Math. floor (this. _leftMinutes / 60);
/ / No module
= Math. floor ( this ._leftHours / 24 ) ; this. leftDays = Math. floor (this. _leftHours / 24);
/ / For print
= this ._leftMilliseconds % 1000 ; this. leftMilliseconds = this. _leftMilliseconds% 1000;
= this ._leftSeconds % 60 ; this. leftSeconds = this. _leftSeconds 60%;
= this ._leftMinutes % 60 ; this. leftMinutes = this. _leftMinutes 60%;
= this ._leftHours % 24 ; this. leftHours = this. _leftHours 24%;
}
( ) ; this. refresh ();
}

Example

1
2
3
new countDown ( '1 1, 2009' ) ; var cd = new CountDown (1 '1, 2009 ');
/ / Show how many days, hours, minutes, seconds and milliseconds to January 1, 2009

Continued ...

3D Countdown with FIVe3D

I wrote a class CountDown for Actionscript 3.0. To test it I created an example using the text-rendering capabilities FIVe3D .

Click to open the Flash movie

Continued ...

How I Did It: Flash write a countdown

For the series "How I Did It" (or as I did) here is how to make a countdown to display Flash, starting with a date, what days, hours, minutes and seconds are missing an event! The Flash movie below, for example, see how many days the first year! They can be used pull-down menus to select a different date:

Loading Flash ...

We create three combo day_cmb, month_cmb year_cmb and initialize them:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/ / Init combo
controls . ComboBox ; import mx. controls. ComboBox;
/ /
var i = 1 ; i < 32 ; i ++ ) { for (var i = 1, i <32; i + +) {
i , i ) ; day_cmb. addItem (i, i);
}

var i = 0 ; i < 12 ; i ++ ) { for (var i = 0; i <12; i + +) {
sm [ i ] , i ) ; month_cmb. addItem (sm [i], i);
}
/ / Starting from today ... I
var i = 2007 ; i < 2020 ; i ++ ) { for (var i = 2007; i <2020; i + +) {
i , i ) ; year_cmb. addItem (i, i);
}
/ / Set the date to January 1, 2008
; // -1 day_cmb. selectedIndex = 0; / / -1
; // -1 month_cmb. selectedIndex = 0; / / -1
; year_cmb. selectedIndex = 1;

The heart of the system we place the onEnterFrame event:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
onEnterFrame = function ( ) { this. onEnterFrame = function () {
/ /
Date = new Date ( ) ; var today: Date = new Date ();
getFullYear ( ) ; var today = currenty. getFullYear ();
getTime ( ) ; var today = currentTime. getTime ();
/ /

getTime ( ) ; targetTime var = TARGETDIR. getTime ();
/ /
currentTime ; var = targetTime TimeLeft - currentTime;
/ /
. floor ( timeLeft / 1000 ) ; var s = Math . floor (TimeLeft / 1000);
= Math . floor ( sec / 60 ) ; var min = Math . floor (sec / 60);
. floor ( min / 60 ) ; var hrs = Math . floor (min / 60);
. floor ( hrs / 24 ) ; var days = Math . floor (hrs / 24);
/ /
sec % 60 ) ; sec = String (sec% 60);
length < 2 ) ? "0" + sec : sec ; sec = (sec. length <2)? "0" + sec: sec;
/ /
( min % 60 ) ; min = String (min% 60);
min . length < 2 ) ? "0" + min : min ; = min (min. length <2)? "0" + min: min;
/ /
hrs % 24 ) ; hrs = String (hrs% 24);
length < 2 ) ? "0" + hrs : hrs ; mins = (hrs. length <2)? "0" + hrs: mins;
/ /
days ) ; days = String (days);
length < 2 ) ? "0" + days : days ; = days (days. length <2)? "0" + days: days;
/ /
String = days + ":" + hrs + ":" + min + ":" + sec ; var counter: String = days + "" + hrs + ":" + min + ":" + sec;
/ /
= counter ; time_txt. text = counter;
};

Continued ...