<?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; random</title>
	<atom:link href="http://flashadvanced.com/tag/random/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>Creating a small shooting game</title>
		<link>http://flashadvanced.com/advanced-actionscript-3/creating-small-shooting-game/</link>
		<comments>http://flashadvanced.com/advanced-actionscript-3/creating-small-shooting-game/#comments</comments>
		<pubDate>Sun, 26 Jul 2009 13:04:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Advanced ActionScript 3]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[random]]></category>

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


In this tutorial you will learn how to create a small &#8220;shooting stars&#8221; game using Flash and ActionScript 3. Let&#8217;s get started!

1. Open a new Flash document and save it under &#8220;ShootingGame.fla&#8221;. Set its size to 500 x 300 pixels.
2. First of all we need to draw the sight of our weapon. So rename the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://flashadvanced.com/?p=371"><br />
<img src="http://flashadvanced.com/wp-content/upload/shooting/shooting.jpg" /><br />
</a></p>
<p>In this tutorial you will learn how to create a small <strong>&#8220;shooting stars&#8221;</strong> game using Flash and ActionScript 3. Let&#8217;s get started!</p>
<p><span id="more-371"></span></p>
<p><span style="color: #ff0000;">1.</span> Open a new Flash document and save it under &#8220;ShootingGame.fla&#8221;. Set its size to 500 x 300 pixels.</p>
<p><span style="color: #ff0000;">2.</span> First of all we need to draw the sight of our weapon. So rename the first layer to &#8220;sight&#8221;. Take the <strong>Oval Tool</strong> and from the properties panel set its properties to Solid, Disabled Fill, Stroke height should be set to 3.<br />
Then take the Selection tool, select a part of the circle and cut it like this:</p>
<p><img src="http://flashadvanced.com/wp-content/upload/shooting/steps.jpg" /></p>
<p>The final step is to take the Line tool and to draw a cross. Just change the Stroke height value to 1.5. Select the whole sight and convert it to Movie Clip with instance name &#8220;sight&#8221; and <strong>registration point center</strong>.</p>
<p><span style="color: #ff0000;">3.</span> Now our sight is ready and we need to draw a star. Take the <strong>PolyStar Tool</strong> and set it properties like this:</p>
<p><img src="http://flashadvanced.com/wp-content/upload/shooting/properties.jpg" /></p>
<p>If your star is ready, select it and convert it to Movie Clip with <strong>registration point center</strong>. <strong>Linkage</strong> the star to class Star by going to the Library panel (Ctrl + L), right-clicking the Star movie clip and then setting the class name. Remove the star from the stage.</p>
<p><img src="http://flashadvanced.com/wp-content/upload/shooting/linkage.jpg" /></p>
<p><span style="color: #ff0000;">4.</span> Take the text tool and first create a Static text field and type &#8220;Score:&#8221;. Then create a <strong>dynamic</strong> text field with instance name &#8220;points_txt&#8221; and position it next to the static text field. Embed the Numeral values for the font and for color choose #FF0000. Align the text fields to the bottom right part of the stage.</p>
<p><span style="color: #ff0000;">5.</span> Create a new layer called &#8220;actions&#8221;, open Actions Panel and type this:</p>
<pre><code>
//importing tween classes
import fl.transitions.easing.*;
import fl.transitions.Tween;

//hiding the cursor
Mouse.hide();

//creating a new Star instance
var star:Star = new Star();
//creating the timer
var timer:Timer = new Timer(1000);
//we create variables for random X and Y positions
var randomX:Number;
var randomY:Number;
//variable for the alpha tween effect
var tween:Tween;
//we check if a star instance is already added to the stage
var starAdded:Boolean = false;
//we count the points
var points:int = 0;

//adding event handler on mouse move
stage.addEventListener(MouseEvent.MOUSE_MOVE, cursorMoveHandler);
//adding event handler to the timer
timer.addEventListener(TimerEvent.TIMER, timerHandler);
//starting the timer
timer.start();

function cursorMoveHandler(e:Event):void{
	//sight position matches the mouse position
	sight.x = mouseX;
	sight.y = mouseY;
}

function timerHandler(e:TimerEvent):void{
	//first we need to remove the star from the stage if already added
	if(starAdded){
		removeChild(star);
	}

	//positioning the star on a random position
	randomX = Math.random()*500;
	randomY = Math.random()*300;
	star.x = randomX;
	star.y = randomY;
	//adding the star to the stage
	addChild(star);
	//changing our boolean value to true
	starAdded = true;
	//adding a mouse click handler to the star
	star.addEventListener(MouseEvent.CLICK, clickHandler);
	//animating the star's appearance
	tween = new Tween(star, "alpha", Strong.easeOut, 0, 1, 3, true);
}

function clickHandler(e:Event):void{
	//when we click/shoot a star we increment the points
	points ++;
	//showing the result in the text field
	points_txt.text = points.toString();
}
</code></pre>
<h4>Here is the final result:</h4>
<p><object width="500" height="300"><param name="movie" value="http://flashadvanced.com/wp-content/upload/shooting/ShootingGame.swf"><embed src="http://flashadvanced.com/wp-content/upload/shooting/ShootingGame.swf" width="500" height="300"></embed></object></p>
<p style="text-align: left; margin: 40px 40px 40px 0;"><a href="http://www.flashadvanced.com/wp-content/upload/shooting/shooting.zip"><img src="http://flashadvanced.com/wp-content/upload/other/download.jpg" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://flashadvanced.com/advanced-actionscript-3/creating-small-shooting-game/feed/</wfw:commentRss>
		<slash:comments>62</slash:comments>
		</item>
		<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>
	</channel>
</rss>
