<?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; timer</title>
	<atom:link href="http://flashadvanced.com/tag/timer/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>XML random quotes rotator</title>
		<link>http://flashadvanced.com/advanced-actionscript-3/xml-random-quotes-rotator/</link>
		<comments>http://flashadvanced.com/advanced-actionscript-3/xml-random-quotes-rotator/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 10:37:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Advanced ActionScript 3]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[timer]]></category>
		<category><![CDATA[tween]]></category>
		<category><![CDATA[xml]]></category>

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


Today I will show you how to use XML and ActionScript 3 to create a small application that changes your favourite quotes after some time interval. We will be using also the AS3 Tween Class to animate the quotes&#8217; appearance.

At first this was just an experiment but i thought it might be useful for some [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://flashadvanced.com/?p=169"><br />
<img src="http://www.flashadvanced.com/wp-content/upload/quotes/quotes.jpg" alt="" /><br />
</a></p>
<p>Today I will show you how to use <strong>XML</strong> and ActionScript 3 to create a small application that changes your favourite quotes after some time interval. We will be using also the AS3 <strong>Tween Class</strong> to animate the quotes&#8217; appearance.</p>
<p><span id="more-169"></span></p>
<p>At first this was just an experiment but i thought it might be useful for some of you. What the rotator does is to choose a <strong>random</strong> quote from an XML file and then shows it for several seconds. Then it chooses another random quote and so on. You can use it for header of your blog or whatever you want. So, let&#8217;s get started.</p>
<p><span style="color: #ff0000;"><strong>1.</strong></span> Create a new Flash CS3 document with size 600 x 100 and background color #000000.<br />
<span style="color: #ff0000;"><strong>2.</strong></span> Create two dynamic text fields. The first one should be about 580px wide and the second one &#8211; about 200px. For the long text field choose #ffffff for color, size 14, bold. I have used &#8220;Verdana&#8221; for font. If you don&#8217;t like it choose another font. Align the text inside the text field to center. Give it an instance name &#8220;quoteTxt&#8221;. Embed the font like this:</p>
<p><img src="http://www.flashadvanced.com/wp-content/upload/quotes/embed.jpg" alt="" /></p>
<p>Now repeat this step for the other text field but only change the color to #00CCFF and give it an instance name &#8220;authorTxt&#8221;.<br />
<span style="color: #ff0000;"><strong>3.</strong></span> Convert the text fields to movie clips. Select the long text field and convert it to movie clip with instance name &#8220;quoteMC&#8221;. Repeat the same for the other text field and put &#8220;authorMC&#8221; for instance name.<br />
<span style="color: #ff0000;"><strong>4.</strong></span> Now let&#8217;s create the <strong>XML</strong> file we will be using. You can simply download it from <a href="http://www.flashadvanced.com/wp-content/upload/quotes/quotes.xml">here</a>. So after downloading put the file into directory named &#8220;data&#8221;.<br />
<span style="color: #ff0000;"><strong>5.</strong></span> Create a new layer called &#8220;actions&#8221;, open the actions panel and paste this code:</p>
<pre><code>
//importing tween classes
import fl.transitions.Tween;
import fl.transitions.easing.*;

//we create a variable to store the loaded XML
var xml:XML;
//the path to the xml file
var xmlPath:String = "http://www.flashadvanced.com/wp-content/upload/quotes/quotes.xml";
//we create a loader and when the loading is over we call the xmlComplete function
var loader:URLLoader = new URLLoader();
//a url request for our loader
var req:URLRequest = new URLRequest(xmlPath);
loader.addEventListener(Event.COMPLETE, xmlComplete);
loader.load(req);
//a variable for our tween
var myTween:Tween;
//we need to set a timer
var timer:Timer = new Timer(5000);
timer.addEventListener(TimerEvent.TIMER, changeQuotes);
timer.start();

function xmlComplete(e:Event):void{
	xml = new XML(e.target.data);
	addQuotes();
	randomQuoteTween();
}

//we create arrays to store the quotes and the authors
var quotesArray:Array = new Array();
var authorsArray:Array = new Array();
//we need a random quote number
var randomNumber:Number;

function addQuotes(){
	//we loop through the "quote" element of our XML
	for each(var item:XML in xml.quotes.quote){
		//we fill the arrays with quotes and authors
		quotesArray.push(item.content);
		authorsArray.push(item.author);
	}
}

function randomQuoteTween():void{
	//calculating the random number
	randomNumber = Math.round(Math.random() * (quotesArray.length - 1));
	//filling the text fields
	quoteMC.quoteTxt.text = quotesArray[randomNumber];
	authorMC.authorTxt.text = authorsArray[randomNumber];
	//creating tween effects
	myTween = new Tween(quoteMC, "alpha", Strong.easeOut, 0, 1, 3, true);
	myTween = new Tween(authorMC, "x", Strong.easeOut, 550, 500, 3, true);
}

function changeQuotes(e:TimerEvent){
	randomQuoteTween();
}
</code></pre>
<h4>Here is the final result:</h4>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="600" height="100" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://www.flashadvanced.com/wp-content/upload/quotes/Quotes.swf" /><embed type="application/x-shockwave-flash" width="600" height="100" src="http://www.flashadvanced.com/wp-content/upload/quotes/Quotes.swf"></embed></object></p>
<p style="text-align: left; margin: 40px 40px 40px 0;"><a href="http://www.flashadvanced.com/wp-content/upload/quotes/quotes.zip"><img src="http://flashadvanced.com/wp-content/upload/other/download.jpg" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://flashadvanced.com/advanced-actionscript-3/xml-random-quotes-rotator/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<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>
