<?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 User &#187; timer</title>
	<atom:link href="http://www.flashuser.net/tag/timer/feed" rel="self" type="application/rss+xml" />
	<link>http://www.flashuser.net</link>
	<description>FlashUser.net helps creative Flash developers and designers from all over the world to save time and money for their projects. By following our posts you will easily create more effective Flash designs or add value to your Flash software and applications</description>
	<lastBuildDate>Fri, 20 Aug 2010 11:27:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Tips &amp; Tricks 6: How to Create a Countdown Timer in Actionscript 3.0</title>
		<link>http://www.flashuser.net/flash-tricks/how-to-create-a-countdown-timer-in-actionscript-30.html</link>
		<comments>http://www.flashuser.net/flash-tricks/how-to-create-a-countdown-timer-in-actionscript-30.html#comments</comments>
		<pubDate>Thu, 09 Jul 2009 14:06:56 +0000</pubDate>
		<dc:creator>flashuser</dc:creator>
				<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[Flash Tips & Tricks]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[timer]]></category>

		<guid isPermaLink="false">http://www.flashuser.net/?p=376</guid>
		<description><![CDATA[<p>I will show you how to create a simple yet effective countdown timer in ActionScript 3.0. It counts from days to seconds and it&#8217;s useful when you schedule anniversaries, appointments, holidays.</p>
<p>1. Create a dynamic TextField and aligned to the right.<br />
<span id="more-376"></span><br />
2. Give it an instance name, I call it <em>countdown_txt</em>.</p>
<p>3. In the first frame of the scene open the Actions tab and paste this code:</p>
<pre class="brush: as3;">
this.addEventListener(&quot;enterFrame&quot;,startMovie);

function startMovie(e:Event) {

	var today:Date = new Date();
	var curTime = today.getTime();

	var myRetirement:Date = new Date(2050, 7, 9);// 2050 August 9 -- months are from 0 to 11

	var myRetirementTime = myRetirement.getTime();// get the time in miliseconds of myRetirement
	var timeLeft = myRetirementTime-curTime;

	var seconds = Math.floor(timeLeft/1000);
	var minutes = Math.floor(seconds/60);
	var hours = Math.floor(minutes/60);
	var days = Math.floor(hours/24);
	var years = Math.floor(days/365);

	seconds = String(seconds%60);

	if (seconds.length&lt;2) {
		seconds = &quot;0&quot;+seconds;
	}
	minutes = String(minutes%60);

	if (minutes.length&lt;2) {
		minutes = &quot;0&quot;+minutes;
	}
	hours = String(hours%24);

	if (hours.length&lt;2) {
		hours = &quot;0&quot;+hours;
	}
	days = String(days%365);

	if (days.length&lt;2) {
		days = &quot;0&quot;+days;
	}
	years = String(years);

	var count:String = years+&quot;:&quot;+days+&quot;:&quot;+hours+&quot;:&quot;+minutes+&quot;:&quot;+seconds;
	countdown_txt.text = count;
}
</pre>
<p><strong>Example:</strong></p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_retirement_as3_741488870"
			class="flashmovie"
			width="200"
			height="100">
	<param name="movie" value="http://www.flashuser.net/flash-files/flash_tips_tricks/6/retirement_as3.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.flashuser.net/flash-files/flash_tips_tricks/6/retirement_as3.swf"
			name="fm_retirement_as3_741488870"
			width="200"
			height="100">
	<!--<![endif]-->
		<br />
 <!-- Begin Alternate Content --></p>
<p>
 <a href="http://adobe.com/go/getflashplayer"><br />
<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /><br />
</a>
 </p>
<p><!-- End Alternate Content --></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
]]></description>
			<content:encoded><![CDATA[<p>I will show you how to create a simple yet effective countdown timer in ActionScript 3.0. It counts from days to seconds and it&#8217;s useful when you schedule anniversaries, appointments, holidays.</p>
<p>1. Create a dynamic TextField and aligned to the right.<br />
<span id="more-376"></span><br />
2. Give it an instance name, I call it <em>countdown_txt</em>.</p>
<p>3. In the first frame of the scene open the Actions tab and paste this code:</p>
<pre class="brush: as3;">
this.addEventListener(&quot;enterFrame&quot;,startMovie);

function startMovie(e:Event) {

	var today:Date = new Date();
	var curTime = today.getTime();

	var myRetirement:Date = new Date(2050, 7, 9);// 2050 August 9 -- months are from 0 to 11

	var myRetirementTime = myRetirement.getTime();// get the time in miliseconds of myRetirement
	var timeLeft = myRetirementTime-curTime;

	var seconds = Math.floor(timeLeft/1000);
	var minutes = Math.floor(seconds/60);
	var hours = Math.floor(minutes/60);
	var days = Math.floor(hours/24);
	var years = Math.floor(days/365);

	seconds = String(seconds%60);

	if (seconds.length&lt;2) {
		seconds = &quot;0&quot;+seconds;
	}
	minutes = String(minutes%60);

	if (minutes.length&lt;2) {
		minutes = &quot;0&quot;+minutes;
	}
	hours = String(hours%24);

	if (hours.length&lt;2) {
		hours = &quot;0&quot;+hours;
	}
	days = String(days%365);

	if (days.length&lt;2) {
		days = &quot;0&quot;+days;
	}
	years = String(years);

	var count:String = years+&quot;:&quot;+days+&quot;:&quot;+hours+&quot;:&quot;+minutes+&quot;:&quot;+seconds;
	countdown_txt.text = count;
}
</pre>
<p><strong>Example:</strong></p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_retirement_as3_895009162"
			class="flashmovie"
			width="200"
			height="100">
	<param name="movie" value="http://www.flashuser.net/flash-files/flash_tips_tricks/6/retirement_as3.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.flashuser.net/flash-files/flash_tips_tricks/6/retirement_as3.swf"
			name="fm_retirement_as3_895009162"
			width="200"
			height="100">
	<!--<![endif]-->
		<br />
 <!-- Begin Alternate Content --></p>
<p>
 <a href="http://adobe.com/go/getflashplayer"><br />
<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /><br />
</a>
 </p>
<p><!-- End Alternate Content --></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
]]></content:encoded>
			<wfw:commentRss>http://www.flashuser.net/flash-tricks/how-to-create-a-countdown-timer-in-actionscript-30.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
