<?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, Flex and ActionScript tutorials - flashadvanced &#187; game</title>
	<atom:link href="http://flashadvanced.com/tag/game/feed/" rel="self" type="application/rss+xml" />
	<link>http://flashadvanced.com</link>
	<description>Become an advanced actionscript developer</description>
	<lastBuildDate>Sun, 30 Jan 2011 21:10:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Creating a small shooting game in AS3</title>
		<link>http://flashadvanced.com/creating-small-shooting-game-as3/</link>
		<comments>http://flashadvanced.com/creating-small-shooting-game-as3/#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 [...]]]></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/creating-small-shooting-game-as3/feed/</wfw:commentRss>
		<slash:comments>80</slash:comments>
		</item>
	</channel>
</rss>

