<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Flash and ActionScript tutorials - flashadvanced &#187; countdown</title>
	<atom:link href="http://flashadvanced.com/tag/countdown/feed/" rel="self" type="application/rss+xml" />
	<link>http://flashadvanced.com</link>
	<description>Become an advanced flash developer</description>
	<lastBuildDate>Mon, 11 Jan 2010 22:14:13 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Countdown timer with ActionScript 3.0</title>
		<link>http://flashadvanced.com/actionscript-3-basics/countdown-timer-with-actionscript-3-0/</link>
		<comments>http://flashadvanced.com/actionscript-3-basics/countdown-timer-with-actionscript-3-0/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 14:50:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ActionScript 3.0 Basics]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[countdown]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[timer]]></category>

		<guid isPermaLink="false">http://flashadvanced.com/?p=37</guid>
		<description><![CDATA[


In this tutorial I will show you how to use Timer and Date classes to create a nice countdown timer using Actionscript 3.

Well, each of us is waiting for something nice &#8211; birthday, vacation, weekend. As a soccer fan I am waiting for the FIFA World Cup 2010 which takes place in South Africa and [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://flashadvanced.com/?p=37"><br />
<img src="http://www.flashadvanced.com/wp-content/upload/countdown/countdown.jpg" alt="" /><br />
</a><br />
In this tutorial I will show you how to use <strong>Timer</strong> and <strong>Date</strong> classes to create a nice <strong>countdown</strong> timer using Actionscript 3.</p>
<p><span id="more-37"></span></p>
<p>Well, each of us is waiting for something nice &#8211; birthday, vacation, weekend. As a soccer fan I am waiting for the FIFA World Cup 2010 which takes place in South Africa and begins on 11th June 2010. I am counting down the days but I can say it&#8217;s not that easy. Because of this I made a <strong>Flash</strong> countdown timer and now it is much easier.</p>
<p>So let&#8217;s get started with our countdown timer.</p>
<p><span style="color: #ff0000;"><strong>1.</strong></span> Create a new Flash CS3 document and save it under the name &#8220;countdown.fla&#8221;.<br />
<span style="color: #ff0000;"><strong>2.</strong></span> Now create a new dynamic text field and name it &#8220;time_txt&#8221;. Here we&#8217;ll put the time that remains to the beginning of the world cup championship. For this tutorial I am using font downloaded from <a href="http://www.abstractfonts.com/font/12167">here</a>. To fully complete this tutorial you have to download this font and to install it on your system. Choose #009900 for font color and 24 for font size. Embed the font like this:</p>
<p><img src="http://www.flashadvanced.com/wp-content/upload/countdown/embed.jpg" alt="Character embedding" /></p>
<p><span style="color: #ff0000;"><strong>3.</strong></span> Now we have to move to actionscript. Create a new layer called &#8220;actions&#8221; and on its first keyframe press F9 to go to the &#8220;Actions&#8221; panel. Here is the code:</p>
<pre><code>//First we create a date object. Note that we count the months from "0"!
var endDate:Date = new Date(2010, 5, 11);
//next we create a timer that will update the time every second
var timer:Timer = new Timer(1000);
//we add an event listener to the timer and then we start it
timer.addEventListener(TimerEvent.TIMER, updateTime);
timer.start();
//Calculate the time remaining as it is being updated
function updateTime(e:TimerEvent):void{
	//we create a variable to hold the current date
	var currentDate:Date = new Date();
	//we calculate the time to FIFA World Cup 2010
	var timeLeft:Number = endDate.getTime() - currentDate.getTime();
	//we convert the remaining time into seconds, minutes, hours, and days
	var seconds:Number = Math.floor(timeLeft / 1000);
	var minutes:Number = Math.floor(seconds / 60);
	var hours:Number = Math.floor(minutes / 60);
	var days:Number = Math.floor(hours / 24);

	seconds %= 60;
	minutes %= 60;
	hours %= 24;

	//we convert the numbers to strings
	var sec:String = seconds.toString();
	var min:String = minutes.toString();
	var hrs:String = hours.toString();
	var d:String = days.toString();

	//if we have a single digit we add "0" in front of it
	if (sec.length &lt; 2) {
	    sec = "0" + sec;
	}

	if (min.length &lt; 2) {
	    min = "0" + min;
	}

	if (hrs.length &lt; 2) {
	    hrs = "0" + hrs;
	}

	//we create a variable to hold all elements and then we add it to our text field
	var time:String = d + ":" + hrs + ":" + min + ":" + sec;
	time_txt.text = time;
}</code></pre>
<h4>And here is the final result:</h4>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="500" height="430" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://flashadvanced.com/wp-content/upload/countdown/countdownto.swf" /><embed type="application/x-shockwave-flash" width="500" height="430" src="http://flashadvanced.com/wp-content/upload/countdown/countdownto.swf"></embed></object></p>
<p style="text-align: left; margin: 40px 40px 40px 0;"><a href="http://www.flashadvanced.com/wp-content/upload/countdown/countdown.zip"><img src="http://flashadvanced.com/wp-content/upload/other/download.jpg" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://flashadvanced.com/actionscript-3-basics/countdown-timer-with-actionscript-3-0/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>
