<?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 Game Development Tutorials - As Gamer</title>
	<atom:link href="http://asgamer.com/feed" rel="self" type="application/rss+xml" />
	<link>http://asgamer.com</link>
	<description>Learn to Make Flash Games, Applications, and Websites</description>
	<lastBuildDate>Fri, 13 Jan 2012 00:13:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Changing Colors Dynamically with ColorTransform in AS3</title>
		<link>http://asgamer.com/2011/changing-colors-with-colortransform-in-as3-code</link>
		<comments>http://asgamer.com/2011/changing-colors-with-colortransform-in-as3-code#comments</comments>
		<pubDate>Mon, 31 Jan 2011 20:13:12 +0000</pubDate>
		<dc:creator>Par</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[colortransform]]></category>
		<category><![CDATA[featured]]></category>

		<guid isPermaLink="false">http://asgamer.com/?p=532</guid>
		<description><![CDATA[Alright so what's this tutorial about? Well let's say your game has enemies that on death splat blood all over the place... sounds wonderful. So maybe these enemies are aliens with green blood, but a couple of them need to have blue blood, and well, maybe,  another one should have yellow. What do you do? Copy the same movieclip over and over each time changing the color of the blood? No... there's a much easier solution for handling color changes in ActionScript. (If you don't like the blood reference, imagine a cutesy dress up game where you want to change the colors of the outfits)]]></description>
			<content:encoded><![CDATA[<p>				<!-- Social Sharing Toolkit v2.0.4 | http://www.marijnrongen.com/wordpress-plugins/social_sharing_toolkit/ --></p>
<div class="mr_social_sharing_wrapper"><span class="mr_social_sharing"><a href="http://twitter.com/share?url=http%3A%2F%2Fasgamer.com%2F2011%2Fchanging-colors-with-colortransform-in-as3-code&amp;text=Changing+Colors+Dynamically+with+ColorTransform+in+AS3&amp;via=jon_par" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/twitter.png" alt="Share on Twitter" title="Share on Twitter"/></a></span><span class="mr_social_sharing"><g:plusone size="medium" count="false" href="http://asgamer.com/2011/changing-colors-with-colortransform-in-as3-code"></g:plusone></span><span class="mr_social_sharing"><a href="http://www.tumblr.com/share/link?url=http%3A%2F%2Fasgamer.com%2F2011%2Fchanging-colors-with-colortransform-in-as3-code&amp;name=Changing+Colors+Dynamically+with+ColorTransform+in+AS3" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/tumblr.png" alt="Share on Tumblr" title="Share on Tumblr"/></a></span><span class="mr_social_sharing"><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fasgamer.com%2F2011%2Fchanging-colors-with-colortransform-in-as3-code&amp;title=Changing+Colors+Dynamically+with+ColorTransform+in+AS3" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/stumbleupon.png" alt="Submit to StumbleUpon" title="Submit to StumbleUpon"/></a></span><span class="mr_social_sharing"><a href="http://del.icio.us/post?url=http%3A%2F%2Fasgamer.com%2F2011%2Fchanging-colors-with-colortransform-in-as3-code&amp;title=Changing+Colors+Dynamically+with+ColorTransform+in+AS3" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/delicious.png" alt="Save on Delicious" title="Save on Delicious"/></a></span><span class="mr_social_sharing"><a href="http://digg.com/submit?url=http%3A%2F%2Fasgamer.com%2F2011%2Fchanging-colors-with-colortransform-in-as3-code&amp;title=Changing+Colors+Dynamically+with+ColorTransform+in+AS3" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/digg.png" alt="Digg This" title="Digg This"/></a></span><span class="mr_social_sharing"><a href="http://www.reddit.com/submit?url=http%3A%2F%2Fasgamer.com%2F2011%2Fchanging-colors-with-colortransform-in-as3-code" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/reddit.png" alt="Submit to reddit" title="Submit to reddit"/></a></span><span class="mr_social_sharing"><iframe src="https://www.facebook.com/plugins/like.php?locale=en_US&amp;href=http%3A%2F%2Fasgamer.com%2F2011%2Fchanging-colors-with-colortransform-in-as3-code&amp;layout=standard&amp;show_faces=false&amp;width=51px&amp;height=24px" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:51px; height:24px;" allowTransparency="true"></iframe></span></div>
<p>Well, this is the first tutorial in a long time. Mostly because I&#8217;m still using CS3 and all CS4 and CS5 users are having a hard time understanding my tutorials. That&#8217;s okay, we&#8217;ll keep mostly in the code and everyone will be able to understand it (I hope).</p>
<p>Alright so what&#8217;s this tutorial about? Well let&#8217;s say your game has enemies that on death splat blood all over the place&#8230; sounds wonderful. So maybe these enemies are aliens with green blood, but a couple of them need to have blue blood, and well, maybe,  another one should have yellow. What do you do? Copy the same movieclip over and over each time changing the color of the blood? No&#8230; there&#8217;s a much easier solution for handling color changes in ActionScript. (If you don&#8217;t like the blood reference, imagine a cutesy dress up game where you want to change the colors of the outfits)</p>
<p>The beautiful thing about code based colour (for our &#8216;u&#8217; loving friends) changing is it is incredibly simple in as3. As long as you understand the basics, you&#8217;ll have no problem colour changing with your eyes closed.</p>
<h1>Step 1: Get the starting FLA and get Ready to Code</h1>
<p>Alright, so to get started with this tutorial I ask that you <a title="Download AS3 Source Code ColorTransform" href="http://asgamer.com/wp-content/uploads/2011/01/colorme-start.zip">download this zip file</a>. There is a colorme.fla, colorme.swf, and a folder containing a ColorExample.as file in the archive.  You will not need to make any changes to colorme.fla during this tutorial. But feel free to look over the fla as the setup of the file is important to how we write our code. You&#8217;ll notice in the library that there are two objects.  There names don&#8217;t matter and neither have an linkage attached to them. I have simply placed the sphere movieclip on the middle of the stage. I gave it the instance name of &#8220;button&#8221;.  Inside of button you&#8217;ll notice a few layers that make up the artwork. I locked all the layers but one. This one layer has our movieclip that we wish to color in it. I gave that button the instance name of &#8220;colorMe&#8221;.</p>
<p>Very simple, so all we will have to do to access our colorMe clip from our code is call button.colorMe in our Document Class. (BTW, if any of this sounds confusing, please go read <a title="AS3 Flash Games for Beginners" href="http://asgamer.com/2009/flash-game-design-basics-adding-library-objects-to-stage-with-as3">AS3 Flash Games for Beginners</a> as it should make sense of most everything) Which brings me to the point that I&#8217;ve already set the Document Class to be colorMe.ColorExample (our file in the colorMe folder).</p>
<h1>Step 2: Understanding some Hexadecimal</h1>
<p>Hopefully you understand hexadecimal. But if not let me make it really simple. Instead of counting 0-9, you&#8217;re counting 0-F (16 different characters instead of 10). Normally we&#8217;d count 1,2,3,4,5,6,7,8,9,10. In hex we&#8217;d count 1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,10. Hex 10 is equal to a 16 in decimal. Anyway, we don&#8217;t have to fully understand it, we just need to know how to use it.  If you can understand that 0 is low and F is high, then you are good to go.</p>
<p>Second, colors in hex form are six characters long, two for each color. And it&#8217;s always in the order Red, Green, and Blue.  So an example hex value would look like this #<span style="color: #ff0000;">43</span><span style="color: #00ff00;">A7</span><span style="color: #0000ff;">2F</span>. So is this color (#43F72A) mostly red, green, or blue? Green, of course. Why? Because <span style="color: #00ff00;">A7</span> is greater than <span style="color: #ff0000;">43</span> and <span style="color: #0000ff;">2F</span> both. For some clarity the numbers A7, 43, and 2F in hexadecimal are equal to 167, 67, and 47. The larger the number the more of that color is in the combination. Also, #000000 is black and #ffffff is white and equally important ff is equal to 255.</p>
<p>If you are looking for a specific color, the eye dropper in most all graphics software will tell you the hex value, so really there is no need to worry about it.</p>
<h1>Step 3: What is this ColorTransform Awesomeness?</h1>
<p>Okay so your code (in ColorExample.as) looks like this:</p>
<div class="wp_syntax">
<div class="code">
<pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> colorme
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">DisplayObject</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #3f5fbf;">/**
	 * ...
	 * @author AsGamer.com
	 */</span>
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> ColorExample <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Sprite</span>
	<span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> ColorExample<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre>
</div>
</div>
<p>Alright, First thing I want to do is write our function to change the colors. You are going to need to import an additional class, flash.geom.ColorTransform, so go to your imports at the top and import it now. Great! let&#8217;s write a function.</p>
<p>Now let&#8217;s write a function that takes two parameters, our movieclip that needs a color change and the color we want to change it to be. I&#8217;ll name it colorClip and it will look as follows.</p>
<div class="wp_syntax">
<div class="code">
<pre class="actionscript3" style="font-family:monospace;">		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> colorClip<span style="color: #000000;">&#40;</span>mc<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">DisplayObject</span><span style="color: #000066; font-weight: bold;">,</span> val<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #000000;">&#125;</span></pre>
</div>
</div>
<p>Of course, this isn&#8217;t the finished code, we need to write the insides that make this thing function. But to break it down, we are accepting a DisplayObject and a number. DisplayObject is pretty much the base class of all things visible in Flash. I&#8217;m not absolutely sure that&#8217;s true but I know Sprites and MovieClips are definitely extended from our <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObject.html?filter_coldfusion=9&amp;filter_flex=3&amp;filter_flashplayer=10&amp;filter_air=1.5" target="_blank">DisplayObject</a> friend. This means we can pass anything thats extended from a DisplayObject through to this function. Then we accept a number which will be our hex color value. Now let&#8217;s write all the code for our function&#8230; don&#8217;t worry it&#8217;s only three lines.</p>
<div class="wp_syntax">
<div class="code">
<pre class="actionscript3" style="font-family:monospace;">		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> colorClip<span style="color: #000000;">&#40;</span>mc<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">DisplayObject</span><span style="color: #000066; font-weight: bold;">,</span> val<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">colorTransform</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">ColorTransform</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">ColorTransform</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #004993;">colorTransform</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">color</span> = val<span style="color: #000066; font-weight: bold;">;</span>
				mc<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">transform</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">colorTransform</span> = <span style="color: #004993;">colorTransform</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span></pre>
</div>
</div>
<p>Alright Breakdown:</p>
<ul>
<li><strong>var colorTransform:ColorTransform = new ColorTransform(); </strong>Let&#8217;s see, create a variable and an instance of the ColorTransform class. Simple.</li>
<li><strong>colorTransform.color = val; </strong>So we take our hex number and pass it into the color property of our colorTransform variable.  Just to let you know val will equal a number like this 0x0000FF, 0x00FF00, 0xFF9944, or 0x1A4BB6. (Instead of using # as before we use 0x to establish the number is hex)</li>
<li><strong>mc.transform.colorTransform = colorTransform; </strong>Transform that DisplayObject. All done.</li>
</ul>
<h1>Step 4: Let&#8217;s Make Color Changes.</h1>
<p>Okay, we could end this now with one line of code. Go in the constructor and simply add:</p>
<div class="wp_syntax">
<div class="code">
<pre class="actionscript3" style="font-family:monospace;">colorClip<span style="color: #000000;">&#40;</span>button<span style="color: #000066; font-weight: bold;">.</span>colorMe<span style="color: #000066; font-weight: bold;">,</span> 0xFF0000<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre>
</div>
</div>
<p>Guess what? We just made our button red. Example below.</p>
<div id="swfobj_0"></div>
<h1>Step 5: More Color Transformation Fun</h1>
<p>Okay, you can quit with the above example and be happy with your life. You made a red button, the Nobel peace prize is definitely right around the corner.  But if you&#8217;re one of those learning types, we&#8217;ll try something else <img src='http://asgamer.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>I simply want to make the color change each time I click the Stage. So erase everything in your constructor and add this:</p>
<div class="wp_syntax">
<div class="code">
<pre class="actionscript3" style="font-family:monospace;"><span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_UP</span><span style="color: #000066; font-weight: bold;">,</span> changeColor<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre>
</div>
</div>
<p>This is an event listener. We ask the stage to watch out for someone releasing a click on the stage so when they do we can call the changeColor function. changeColor function doesn&#8217;t exist? Let&#8217;s write one.</p>
<div class="wp_syntax">
<div class="code">
<pre class="actionscript3" style="font-family:monospace;">		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> changeColor<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> red<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #004993;">int</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">255</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> green<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #004993;">int</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">255</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> blue<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #004993;">int</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">255</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #6699cc; font-weight: bold;">var</span> hex<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">Number</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;0x&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> red<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">16</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> green<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">16</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> blue<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">16</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			colorClip<span style="color: #000000;">&#40;</span>button<span style="color: #000066; font-weight: bold;">.</span>colorMe<span style="color: #000066; font-weight: bold;">,</span> hex<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span></pre>
</div>
</div>
<p>Confused? Don&#8217;t be. Remember a few steps and paragraphs up when I said FF = 255. Well, I hope that makes sense of what is happening when we define the red, green, and blue variables. If not, let me explain. Math.random() is selecting a random number between 0 and 1. We then times that number by 255. Which means the number is now something between 0 and 255. Then we make it an integer, which will just get rid of any decimals. Excellent, so our red, green, and blue variables should all have a whole number between 0 and 255 stored in them.</p>
<p>I almost LOL at the next line because it&#8217;s kinda funny. We&#8217;re taking three number&#8230; making them strings&#8230; concatenating them together&#8230; then making them all a number again. Why? Well flash has a nice function we can run on our integers to convert them to hex.  Simply use .toString(<em>value</em>) where value is the base. Since hex is base 16, we used the number sixteen.  Last we need to throw the 0x in front of our string and convert it back into a number. Once done, we are ready to send it off to our color clip function which will do all the magic.</p>
<p>Oh yeah, did I mention we are done? Test it out below. Here&#8217;s <a href="http://asgamer.com/wp-content/uploads/2011/01/colorme-end.zip">the final source code</a>.</p>
<div id="swfobj_1"></div>
<div class="wp_syntax">
<div class="code">
<pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> colorme
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MovieClip</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">DisplayObject</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.geom</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ColorTransform</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #3f5fbf;">/**
	 * ...
	 * @author AsGamer.com
	 */</span>
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> ColorExample <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">MovieClip</span>
	<span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> ColorExample<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #009900; font-style: italic;">//colorClip(button.colorMe, 0xFF0000);</span>
			<span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_UP</span><span style="color: #000066; font-weight: bold;">,</span> changeColor<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> changeColor<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> red<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #004993;">int</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">255</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> green<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #004993;">int</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">255</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> blue<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #004993;">int</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">255</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #6699cc; font-weight: bold;">var</span> hex<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">Number</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;0x&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> red<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">16</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> green<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">16</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> blue<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">16</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			colorClip<span style="color: #000000;">&#40;</span>button<span style="color: #000066; font-weight: bold;">.</span>colorMe<span style="color: #000066; font-weight: bold;">,</span> hex<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> colorClip<span style="color: #000000;">&#40;</span>mc<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">DisplayObject</span><span style="color: #000066; font-weight: bold;">,</span> val<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">colorTransform</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">ColorTransform</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">ColorTransform</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #004993;">colorTransform</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">color</span> = val<span style="color: #000066; font-weight: bold;">;</span>
				mc<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">transform</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">colorTransform</span> = <span style="color: #004993;">colorTransform</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre>
</div>
</div>
<p>				<!-- Social Sharing Toolkit v2.0.4 | http://www.marijnrongen.com/wordpress-plugins/social_sharing_toolkit/ --></p>
<div class="mr_social_sharing_wrapper"><span class="mr_social_sharing"><a href="http://twitter.com/share?url=http%3A%2F%2Fasgamer.com%2F2011%2Fchanging-colors-with-colortransform-in-as3-code&amp;text=Changing+Colors+Dynamically+with+ColorTransform+in+AS3&amp;via=jon_par" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/twitter.png" alt="Share on Twitter" title="Share on Twitter"/></a></span><span class="mr_social_sharing"><g:plusone size="medium" count="false" href="http://asgamer.com/2011/changing-colors-with-colortransform-in-as3-code"></g:plusone></span><span class="mr_social_sharing"><a href="http://www.tumblr.com/share/link?url=http%3A%2F%2Fasgamer.com%2F2011%2Fchanging-colors-with-colortransform-in-as3-code&amp;name=Changing+Colors+Dynamically+with+ColorTransform+in+AS3" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/tumblr.png" alt="Share on Tumblr" title="Share on Tumblr"/></a></span><span class="mr_social_sharing"><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fasgamer.com%2F2011%2Fchanging-colors-with-colortransform-in-as3-code&amp;title=Changing+Colors+Dynamically+with+ColorTransform+in+AS3" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/stumbleupon.png" alt="Submit to StumbleUpon" title="Submit to StumbleUpon"/></a></span><span class="mr_social_sharing"><a href="http://del.icio.us/post?url=http%3A%2F%2Fasgamer.com%2F2011%2Fchanging-colors-with-colortransform-in-as3-code&amp;title=Changing+Colors+Dynamically+with+ColorTransform+in+AS3" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/delicious.png" alt="Save on Delicious" title="Save on Delicious"/></a></span><span class="mr_social_sharing"><a href="http://digg.com/submit?url=http%3A%2F%2Fasgamer.com%2F2011%2Fchanging-colors-with-colortransform-in-as3-code&amp;title=Changing+Colors+Dynamically+with+ColorTransform+in+AS3" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/digg.png" alt="Digg This" title="Digg This"/></a></span><span class="mr_social_sharing"><a href="http://www.reddit.com/submit?url=http%3A%2F%2Fasgamer.com%2F2011%2Fchanging-colors-with-colortransform-in-as3-code" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/reddit.png" alt="Submit to reddit" title="Submit to reddit"/></a></span><span class="mr_social_sharing"><iframe src="https://www.facebook.com/plugins/like.php?locale=en_US&amp;href=http%3A%2F%2Fasgamer.com%2F2011%2Fchanging-colors-with-colortransform-in-as3-code&amp;layout=standard&amp;show_faces=false&amp;width=51px&amp;height=24px" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:51px; height:24px;" allowTransparency="true"></iframe></span></div>
]]></content:encoded>
			<wfw:commentRss>http://asgamer.com/2011/changing-colors-with-colortransform-in-as3-code/feed</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>A Review: SWF &amp; FLV Toolbox 4</title>
		<link>http://asgamer.com/2010/a-review-swf-flv-toolbox-4</link>
		<comments>http://asgamer.com/2010/a-review-swf-flv-toolbox-4#comments</comments>
		<pubDate>Thu, 11 Mar 2010 18:41:16 +0000</pubDate>
		<dc:creator>Par</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[Game Development]]></category>
		<category><![CDATA[gamedev]]></category>
		<category><![CDATA[user interface]]></category>

		<guid isPermaLink="false">http://asgamer.com/?p=519</guid>
		<description><![CDATA[Today, the fine folks at Eltima Software have provided me with their cool new version of their product SWF &#038; FLV Toolbox 4. At first when they came to me asking me to review it, I kindly turned them down. I mean, what's this product going to do for a game developer. I couldn't see it. How in the world am I going to use this? They quickly responded telling me some of the features in more detail. And at that point I was sold.]]></description>
			<content:encoded><![CDATA[<p>				<!-- Social Sharing Toolkit v2.0.4 | http://www.marijnrongen.com/wordpress-plugins/social_sharing_toolkit/ --></p>
<div class="mr_social_sharing_wrapper"><span class="mr_social_sharing"><a href="http://twitter.com/share?url=http%3A%2F%2Fasgamer.com%2F2010%2Fa-review-swf-flv-toolbox-4&amp;text=A+Review%3A+SWF+%26+FLV+Toolbox+4&amp;via=jon_par" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/twitter.png" alt="Share on Twitter" title="Share on Twitter"/></a></span><span class="mr_social_sharing"><g:plusone size="medium" count="false" href="http://asgamer.com/2010/a-review-swf-flv-toolbox-4"></g:plusone></span><span class="mr_social_sharing"><a href="http://www.tumblr.com/share/link?url=http%3A%2F%2Fasgamer.com%2F2010%2Fa-review-swf-flv-toolbox-4&amp;name=A+Review%3A+SWF+%26+FLV+Toolbox+4" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/tumblr.png" alt="Share on Tumblr" title="Share on Tumblr"/></a></span><span class="mr_social_sharing"><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fasgamer.com%2F2010%2Fa-review-swf-flv-toolbox-4&amp;title=A+Review%3A+SWF+%26+FLV+Toolbox+4" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/stumbleupon.png" alt="Submit to StumbleUpon" title="Submit to StumbleUpon"/></a></span><span class="mr_social_sharing"><a href="http://del.icio.us/post?url=http%3A%2F%2Fasgamer.com%2F2010%2Fa-review-swf-flv-toolbox-4&amp;title=A+Review%3A+SWF+%26+FLV+Toolbox+4" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/delicious.png" alt="Save on Delicious" title="Save on Delicious"/></a></span><span class="mr_social_sharing"><a href="http://digg.com/submit?url=http%3A%2F%2Fasgamer.com%2F2010%2Fa-review-swf-flv-toolbox-4&amp;title=A+Review%3A+SWF+%26+FLV+Toolbox+4" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/digg.png" alt="Digg This" title="Digg This"/></a></span><span class="mr_social_sharing"><a href="http://www.reddit.com/submit?url=http%3A%2F%2Fasgamer.com%2F2010%2Fa-review-swf-flv-toolbox-4" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/reddit.png" alt="Submit to reddit" title="Submit to reddit"/></a></span><span class="mr_social_sharing"><iframe src="https://www.facebook.com/plugins/like.php?locale=en_US&amp;href=http%3A%2F%2Fasgamer.com%2F2010%2Fa-review-swf-flv-toolbox-4&amp;layout=standard&amp;show_faces=false&amp;width=51px&amp;height=24px" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:51px; height:24px;" allowTransparency="true"></iframe></span></div>
<p>Okay okay, this isn&#8217;t a review site it&#8217;s a tutorial site right? Well actually it&#8217;s a flash game development website and there&#8217;s a lot about this software that is good for a flash game developer. Let me clear some things up before we begin. Whatever I write is my honest opinion, that you can trust I&#8217;m not paid to do anything on this site. This is simply a good bit of advice for flash developers wanting to know exactly how good or bad a product is.</p>
<p>Today, the fine folks at <a href="http://www.eltima.com/products/swf-tools/">Eltima Software</a> have provided me with their cool new version of their product <a href="http://www.eltima.com/products/swf-tools/">SWF &amp; FLV Toolbox 4</a>. At first when they came to me asking me to review it, I kindly turned them down. I mean, what&#8217;s this product going to do for a game developer. I couldn&#8217;t see it. How in the world am I going to use this? They quickly responded telling me some of the features in more detail. And at that point I was sold.</p>
<p>You see I have a flash game coming out soon and I&#8217;d really like to make a video of it so sponsors at FGL can see how it works long before they play the game.  And according to Eltima, I can actually load up my flash game&#8217;s swf, press the convert interactively button and play my game while it records it. Awesome!</p>
<div id="attachment_520" class="wp-caption alignnone" style="width: 569px"><a href="http://asgamer.com/wp-content/uploads/2010/03/toolbox-1.png"><img class="size-full wp-image-520" title="toolbox-1" src="http://asgamer.com/wp-content/uploads/2010/03/toolbox-1.png" alt="Screenshot of the SWF &amp; FLV Toolbox in action" width="559" height="689" /></a>
<p class="wp-caption-text">Screenshot of the SWF &amp; FLV Toolbox in action</p>
</div>
<p>So needless to say I&#8217;m excited to put this thing to the test. The first thing that impressed me is that this product actually installs like normal software. I know, that&#8217;s not impressive. But a lot of software like this just seems to extract and run, Kindisoft&#8217;s secureSWF for example. I like having my software appear in the Start Menu on my Window operated machine.</p>
<p>Okay, so I have the software installed and it&#8217;s test time.  I look at my options: convert to video, images, scr, exe, swf. Well, I don&#8217;t need to convert to swf, it&#8217;s already a swf that I am using. Images? lol, definitely not. Screen saver, nah don&#8217;t really want that either.  So there are two options that I actually care about, converting to video and converting to exe.</p>
<p>The EXE conversion didn&#8217;t excite me either at first. I told Eltima this, and that the Flash IDE does a very nice job of doing that by itself.  However, I was told it converts to an advanced Projector EXE. By advanced, they meant that I can have more control over a variety of things associated with the exe file.  I can select a custom cursor, setup a splash screen as the game loads, change menu items, and even control the number of times the application can be ran.  In a sense this could be very useful for sending out beta versions of your game for reviewing before releasing it. If you think this would work well for you then this product is definitely worth a buy at the current price tag ($39.95).</p>
<div id="attachment_521" class="wp-caption alignnone" style="width: 569px"><img class="size-full wp-image-521" title="toolbox-2" src="http://asgamer.com/wp-content/uploads/2010/03/toolbox-2.png" alt="shots of the multiple tabs for converting a swf to exe" width="559" height="1058" />
<p class="wp-caption-text">shots of the multiple tabs for converting a swf to exe</p>
</div>
<p>Now, the part that I really was looking forward to writing about when I first heard about the software, interactively converting my game&#8217;s game play into a video. So I loaded up my game and like the screenshot above I clicked convert interactively and immediately clicked CONVERT.</p>
<p>I was greeted by a new screen with my game loaded and convert options to choose from. See below:</p>
<p><img class="alignnone size-full wp-image-522" title="toolbox-3" src="http://asgamer.com/wp-content/uploads/2010/03/toolbox-3.png" alt="toolbox-3" width="560" height="689" /></p>
<p>So far so good&#8230; I press record&#8230; I select a level&#8230; it lags. It lags quite badly <img src='http://asgamer.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>I couldn&#8217;t believe it lagged! At first I thought it had to be my game&#8217;s fault. So I tried another one of my games and it lagged equally as bad.  But let&#8217;s be fair, both of the game&#8217;s I tested are pretty intensive on the flash player.  So I opened up the last tutorial from asgamer and tested it. To my surprise, it ran pretty smoothly. Which is awesome, this convert interactively thing isn&#8217;t all bad after all.  I&#8217;m going to upload two videos so you can get a feel for how well it converts. They&#8217;re below:</p>
<p><strong>My upcoming game Fly Away Rabbit:</strong></p>
<p><object width="500" height="405" data="http://www.youtube.com/v/fMZbDFA-l7A&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999&amp;border=1" type="application/x-shockwave-flash"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/fMZbDFA-l7A&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999&amp;border=1" /><param name="allowfullscreen" value="true" /></object></p>
<p><strong>The last tutorial:</strong></p>
<p><object width="500" height="405" data="http://www.youtube.com/v/pmzus00hzM0&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999&amp;border=1" type="application/x-shockwave-flash"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/pmzus00hzM0&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999&amp;border=1" /><param name="allowfullscreen" value="true" /></object></p>
<p>I do not recommend the interactive conversion to video for anything other than a basic flash game.  However, if you have a point and click adventure or something relatively simple on the ActionScript, I think it will work fine.  I contacted Eltima Software about the issue and they kindly said:</p>
<blockquote><p>&#8220;Difficult Flash files can be slow due to lack of hardware resources. <span><span style="background-color: #ffffff;" title="мы будем оптимизировать этот процесс в  будущем конвертация будет происходить лучше и быстрее">We will optimize this process in the future conversion will be better and faster. </span></span>We will continue to test and improve our product.&#8221;</p></blockquote>
<p>I like that response, they didn&#8217;t deny it, they just promised to work on it.  That doesn&#8217;t make me want to buy their product for swf to video conversion of my games but it does give me some faith and trust in the company. So if you are a flash game developer, it&#8217;s definitely worth weighing some of the things I&#8217;ve talked about when promoting your game.  <a href="http://www.eltima.com/products/swf-tools/">SWF &amp; FLV Toolbox 4</a> may be the perfect product for you or it may not, at this point I&#8217;ll let you decide.<br />
				<!-- Social Sharing Toolkit v2.0.4 | http://www.marijnrongen.com/wordpress-plugins/social_sharing_toolkit/ --></p>
<div class="mr_social_sharing_wrapper"><span class="mr_social_sharing"><a href="http://twitter.com/share?url=http%3A%2F%2Fasgamer.com%2F2010%2Fa-review-swf-flv-toolbox-4&amp;text=A+Review%3A+SWF+%26+FLV+Toolbox+4&amp;via=jon_par" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/twitter.png" alt="Share on Twitter" title="Share on Twitter"/></a></span><span class="mr_social_sharing"><g:plusone size="medium" count="false" href="http://asgamer.com/2010/a-review-swf-flv-toolbox-4"></g:plusone></span><span class="mr_social_sharing"><a href="http://www.tumblr.com/share/link?url=http%3A%2F%2Fasgamer.com%2F2010%2Fa-review-swf-flv-toolbox-4&amp;name=A+Review%3A+SWF+%26+FLV+Toolbox+4" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/tumblr.png" alt="Share on Tumblr" title="Share on Tumblr"/></a></span><span class="mr_social_sharing"><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fasgamer.com%2F2010%2Fa-review-swf-flv-toolbox-4&amp;title=A+Review%3A+SWF+%26+FLV+Toolbox+4" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/stumbleupon.png" alt="Submit to StumbleUpon" title="Submit to StumbleUpon"/></a></span><span class="mr_social_sharing"><a href="http://del.icio.us/post?url=http%3A%2F%2Fasgamer.com%2F2010%2Fa-review-swf-flv-toolbox-4&amp;title=A+Review%3A+SWF+%26+FLV+Toolbox+4" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/delicious.png" alt="Save on Delicious" title="Save on Delicious"/></a></span><span class="mr_social_sharing"><a href="http://digg.com/submit?url=http%3A%2F%2Fasgamer.com%2F2010%2Fa-review-swf-flv-toolbox-4&amp;title=A+Review%3A+SWF+%26+FLV+Toolbox+4" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/digg.png" alt="Digg This" title="Digg This"/></a></span><span class="mr_social_sharing"><a href="http://www.reddit.com/submit?url=http%3A%2F%2Fasgamer.com%2F2010%2Fa-review-swf-flv-toolbox-4" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/reddit.png" alt="Submit to reddit" title="Submit to reddit"/></a></span><span class="mr_social_sharing"><iframe src="https://www.facebook.com/plugins/like.php?locale=en_US&amp;href=http%3A%2F%2Fasgamer.com%2F2010%2Fa-review-swf-flv-toolbox-4&amp;layout=standard&amp;show_faces=false&amp;width=51px&amp;height=24px" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:51px; height:24px;" allowTransparency="true"></iframe></span></div>
]]></content:encoded>
			<wfw:commentRss>http://asgamer.com/2010/a-review-swf-flv-toolbox-4/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Asteroids Style Movement&#8230; Now with Firing Lasers</title>
		<link>http://asgamer.com/2009/asteroids-style-movement-firing-lasers</link>
		<comments>http://asgamer.com/2009/asteroids-style-movement-firing-lasers#comments</comments>
		<pubDate>Tue, 17 Nov 2009 16:42:15 +0000</pubDate>
		<dc:creator>Par</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[featured]]></category>

		<guid isPermaLink="false">http://asgamer.com/?p=494</guid>
		<description><![CDATA[A few months ago I wrote a series on character movement. As a part of that series we discussed developing the movement for a spaceship shooter like Asteroids. Since then I've had multiple requests for how to make the ship fire bullets. No problem! This one is simple, super simple, you may smack yourself to the head repetitively with an iron stick for not thinking of it.  But if you don't have an iron stick, no problem, we'll get this all squared away and you'll be on your way to solving this sort of issue with ease from now on.]]></description>
			<content:encoded><![CDATA[<p>				<!-- Social Sharing Toolkit v2.0.4 | http://www.marijnrongen.com/wordpress-plugins/social_sharing_toolkit/ --></p>
<div class="mr_social_sharing_wrapper"><span class="mr_social_sharing"><a href="http://twitter.com/share?url=http%3A%2F%2Fasgamer.com%2F2009%2Fasteroids-style-movement-firing-lasers&amp;text=Asteroids+Style+Movement%E2%80%A6+Now+with+Firing+Lasers&amp;via=jon_par" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/twitter.png" alt="Share on Twitter" title="Share on Twitter"/></a></span><span class="mr_social_sharing"><g:plusone size="medium" count="false" href="http://asgamer.com/2009/asteroids-style-movement-firing-lasers"></g:plusone></span><span class="mr_social_sharing"><a href="http://www.tumblr.com/share/link?url=http%3A%2F%2Fasgamer.com%2F2009%2Fasteroids-style-movement-firing-lasers&amp;name=Asteroids+Style+Movement%E2%80%A6+Now+with+Firing+Lasers" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/tumblr.png" alt="Share on Tumblr" title="Share on Tumblr"/></a></span><span class="mr_social_sharing"><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fasteroids-style-movement-firing-lasers&amp;title=Asteroids+Style+Movement%E2%80%A6+Now+with+Firing+Lasers" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/stumbleupon.png" alt="Submit to StumbleUpon" title="Submit to StumbleUpon"/></a></span><span class="mr_social_sharing"><a href="http://del.icio.us/post?url=http%3A%2F%2Fasgamer.com%2F2009%2Fasteroids-style-movement-firing-lasers&amp;title=Asteroids+Style+Movement%E2%80%A6+Now+with+Firing+Lasers" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/delicious.png" alt="Save on Delicious" title="Save on Delicious"/></a></span><span class="mr_social_sharing"><a href="http://digg.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fasteroids-style-movement-firing-lasers&amp;title=Asteroids+Style+Movement%E2%80%A6+Now+with+Firing+Lasers" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/digg.png" alt="Digg This" title="Digg This"/></a></span><span class="mr_social_sharing"><a href="http://www.reddit.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fasteroids-style-movement-firing-lasers" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/reddit.png" alt="Submit to reddit" title="Submit to reddit"/></a></span><span class="mr_social_sharing"><iframe src="https://www.facebook.com/plugins/like.php?locale=en_US&amp;href=http%3A%2F%2Fasgamer.com%2F2009%2Fasteroids-style-movement-firing-lasers&amp;layout=standard&amp;show_faces=false&amp;width=51px&amp;height=24px" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:51px; height:24px;" allowTransparency="true"></iframe></span></div>
<p>A few months ago I wrote a series on character movement. As a part of that series we discussed developing the movement for a spaceship shooter like Asteroids. Since then I&#8217;ve had multiple requests for how to make the ship fire bullets. No problem! This one is simple, super simple, you may smack yourself to the head repetitively with an iron stick for not thinking of it.  But if you don&#8217;t have an iron stick, no problem, we&#8217;ll get this all squared away and you&#8217;ll be on your way to solving this sort of issue with ease from now on.</p>
<p>Okay so why is this super simple? Well,  in the last tutorial we made our ship move in the direction it&#8217;s pointing. So wouldn&#8217;t that mean making a bullet move in the direction the ship is pointing would be pretty much the same thing? Guess what&#8230; it is.  The awesome thing is that it&#8217;s a lot easier than making the ship move because we just create the bullet and let it go.</p>
<p>Since this is a pretty simple project, here&#8217;s the final source with the FLA and the new Laser.as class.<br />
<a title="The Asteroids with 360 degree movement and laser firing game source" href="http://asgamer.com/wp-content/uploads/2009/11/directionalmovement3.zip">Asteroids Style Movement&#8230; Now with Firing Lasers source code</a></p>
<h2>1. What&#8217;s in the Source Archive? Lasers? Guns? Nuclear Bombs?</h2>
<p>Sorry guys, we&#8217;ll save nuclear bombs for next time. The FLA is pretty much the same as the end of the previous tutorial. I simply added the laser graphic from a <a title="Creating bullet lasers" href="http://asgamer.com/2009/creating-bullet-lasers-with-photoshop">previous tutorial</a>. Otherwise there is a minor adjustment to the ship.as class and a new laser.as class. Alright, quickest step in AsGamer history is complete.</p>
<h2>2. Altering the Ship.as file to fire our laser</h2>
<p>This may be the second quickest step in history. In order to fire lasers we only need to do one thing. Check when a key is pressed and create our laser. So our alterations to the ship class is literally only two lines <img src='http://asgamer.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Here&#8217;s the two lines.</p>
<div class="wp_syntax">
<div class="code">
<pre class="actionscript3" style="font-family:monospace;">			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>key<span style="color: #000066; font-weight: bold;">.</span>isDown<span style="color: #000000;">&#40;</span><span style="color: #004993;">Keyboard</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">SPACE</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
				<span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> Laser<span style="color: #000000;">&#40;</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">rotation</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre>
</div>
</div>
<p>The breakdown:</p>
<ul>
<li><strong>if (key.isDown(Keyboard.SPACE))</strong>. This almost reads like english. &#8220;If the keyboard&#8217;s space key is down&#8221;. See what I mean? Pretty simple.</li>
<li><strong>stage.addChild(new Laser(x, y, rotation));</strong> Here we add our new laser to the stage&#8230; we pass through the ships x, y, and rotation so we can apply all that to our laser.</li>
</ul>
<p>So our new completed Ship.as looks as follows:</p>
<div class="wp_syntax">
<div class="code">
<pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>asgamer<span style="color: #000066; font-weight: bold;">.</span>directionalmovement
<span style="color: #000000;">&#123;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MovieClip</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Stage</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>senocular<span style="color: #000066; font-weight: bold;">.</span>utils<span style="color: #000066; font-weight: bold;">.</span>KeyObject<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.ui</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Keyboard</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Ship <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">MovieClip</span>
	<span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> key<span style="color: #000066; font-weight: bold;">:</span>KeyObject<span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> speed<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0.3</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> rotateSpeed<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">5</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> vx<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> vy<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> friction<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0.95</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Ship <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			key = <span style="color: #0033ff; font-weight: bold;">new</span> KeyObject<span style="color: #000000;">&#40;</span><span style="color: #004993;">stage</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">loop</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">loop</span><span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>key<span style="color: #000066; font-weight: bold;">.</span>isDown<span style="color: #000000;">&#40;</span><span style="color: #004993;">Keyboard</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">UP</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				vy <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sin</span><span style="color: #000000;">&#40;</span>degreesToRadians<span style="color: #000000;">&#40;</span><span style="color: #004993;">rotation</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> speed<span style="color: #000066; font-weight: bold;">;</span>
				vx <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">cos</span><span style="color: #000000;">&#40;</span>degreesToRadians<span style="color: #000000;">&#40;</span><span style="color: #004993;">rotation</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> speed<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
				vy <span style="color: #000066; font-weight: bold;">*</span>= friction<span style="color: #000066; font-weight: bold;">;</span>
				vx <span style="color: #000066; font-weight: bold;">*</span>= friction<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>key<span style="color: #000066; font-weight: bold;">.</span>isDown<span style="color: #000000;">&#40;</span><span style="color: #004993;">Keyboard</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">RIGHT</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
				<span style="color: #004993;">rotation</span> <span style="color: #000066; font-weight: bold;">+</span>= rotateSpeed<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>key<span style="color: #000066; font-weight: bold;">.</span>isDown<span style="color: #000000;">&#40;</span><span style="color: #004993;">Keyboard</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">LEFT</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
				<span style="color: #004993;">rotation</span> <span style="color: #000066; font-weight: bold;">-</span>= rotateSpeed<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>key<span style="color: #000066; font-weight: bold;">.</span>isDown<span style="color: #000000;">&#40;</span><span style="color: #004993;">Keyboard</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">SPACE</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
				<span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> Laser<span style="color: #000000;">&#40;</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">rotation</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">+</span>= vy<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">+</span>= vx<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">&gt;</span> <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageWidth</span><span style="color: #000000;">&#41;</span>
				<span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>
				<span style="color: #004993;">x</span> = <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageWidth</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">&gt;</span> <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageHeight</span><span style="color: #000000;">&#41;</span>
				<span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>
				<span style="color: #004993;">y</span> = <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageHeight</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> degreesToRadians<span style="color: #000000;">&#40;</span>degrees<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Number</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> degrees <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span> <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">180</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre>
</div>
</div>
<p>And now for step 3.</p>
<h2>3. Writing our Laser Class so we can fire Blue Awesomeness</h2>
<p>Okay, in order to make Blue Awesomeness(our laser) we gotta fire out what class variables we may need. As you can see from the ship class we are passing in the x, y, and the rotation of our ship  Since our laser is established at creation and doesn&#8217;t alter it&#8217;s direction or speed after creation we don&#8217;t need to save these details. The only thing our ship needs to know at every frame is where it is going. So we need to store it&#8217;s velocity in x and y. So technically we need two class variables vx and vy. While it&#8217;s not needed I&#8217;m going to add a speed variable as well so I can change it easily later if needed.</p>
<p>So the start of our laser class looks something like this:</p>
<div class="wp_syntax">
<div class="code">
<pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>asgamer<span style="color: #000066; font-weight: bold;">.</span>directionalmovement
<span style="color: #000000;">&#123;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MovieClip</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Stage</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Laser <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">MovieClip</span>
	<span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> vx<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> vy<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> speed<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">12</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Laser <span style="color: #000000;">&#40;</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span> shipRotation<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre>
</div>
</div>
<p>Not much of a breakdown here&#8230; we just created the class variables and gave them a starting value and added the code for our constructor.  Let&#8217;s start filling in our constructor now.</p>
<p>So what do we need to do? What needs to be set to start off our laser? Well, let&#8217;s see. We need to place it at the correct x and y coordinates, set it&#8217;s rotation, find it&#8217;s velocity, and setup a listener so we can update the laser on every frame.</p>
<p>Let&#8217;s look at some more code&#8230; our now filled in constructor. (Plus our degreesToRadians function from the ship class)</p>
<div class="wp_syntax">
<div class="code">
<pre class="actionscript3" style="font-family:monospace;">		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Laser <span style="color: #000000;">&#40;</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span> shipRotation<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">rotation</span> = shipRotation<span style="color: #000066; font-weight: bold;">;</span>
			vy <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sin</span><span style="color: #000000;">&#40;</span>degreesToRadians<span style="color: #000000;">&#40;</span>shipRotation<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> speed<span style="color: #000066; font-weight: bold;">;</span>
			vx <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">cos</span><span style="color: #000000;">&#40;</span>degreesToRadians<span style="color: #000000;">&#40;</span>shipRotation<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> speed<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">+</span> vx<span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">+</span> vy<span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">loop</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> degreesToRadians<span style="color: #000000;">&#40;</span>degrees<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Number</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> degrees <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span> <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">180</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span></pre>
</div>
</div>
<p>Alright source code breakdown time.</p>
<ul>
<li><strong>this.rotation = shipRotation;</strong> point our laser in the same direction as our ship</li>
<li><strong>vy += Math.sin(degreesToRadians(shipRotation)) * speed; vx += Math.cos(degreesToRadians(shipRotation)) * speed;</strong> Remember this? You should. It&#8217;s the same thing we did to the ship to make it more in the direction it was pointing. I&#8217;d explain it with more intelligence and detail but I&#8217;m not a mathematician. Let&#8217;s just say we are taking the speed of our laser and applying it to the x and y based on the laser&#8217;s rotation.</li>
<li><strong>this.x = x + vx*2; this.y = y + vy*2;</strong> Why +vx*2 you ask? Why not just x? Well, our ship&#8217;s x is at our ship&#8217;s center. If we add the laser at the same place it will appear in the center of the ship. Not attractive in my opinion. So we know if our laser is shooting in the right direction and continues moving in the right direction when we add vx and vy on each frame then we can just add a little extra vx and vy to the creation and move the laser on away from our ship&#8217;s center when it is created. Awesome huh? Simple yet works.</li>
<li><strong>addEventListener(Event.ENTER_FRAME, loop, false, 0, true);</strong> You know what this is&#8230; seriously. Calls loop every on every enter frame.  So what&#8217;s that tell you? Next we&#8217;re writing a loop function.</li>
<li><strong>public function degreesToRadians(degrees:Number) : Number {&#8230;}</strong> This is the exact same function from the Ship.as class. Simply converts degrees to radians. Now to be honest with you, adding degreesToRadians to every class that needs it is probably a very bad way of programming. I mean, save yourself some time and create a static class and add your common functions to it so you can use them when necessary. Hmm&#8230;. static classes, I may have to discuss that in the next tutorial. For now, know that adding degreesToRadians to every class you&#8217;ve ever wrote won&#8217;t destroy your game or project, it&#8217;s just tedious and there is an easier way. But don&#8217;t worry about that, we&#8217;ll get to it another time.</li>
</ul>
<p>So what are we doing with each loop? Not much. Just adding our velocity to x and y. Then, of course, making sure our laser is still on screen because if not, we need to remove it. So here&#8217;s the last two functions in our laser class.</p>
<div class="wp_syntax">
<div class="code">
<pre class="actionscript3" style="font-family:monospace;">		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">loop</span><span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">+</span>= vy<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">+</span>= vx<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight:bold;">520</span> <span style="color: #000066; font-weight: bold;">||</span> <span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight:bold;">420</span> <span style="color: #000066; font-weight: bold;">||</span> <span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">&lt;</span> <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">20</span> <span style="color: #000066; font-weight: bold;">||</span> <span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">&lt;</span> <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">20</span><span style="color: #000000;">&#41;</span>
				destroy<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> destroy<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">parent</span><span style="color: #000000;">&#41;</span>
				<span style="color: #004993;">parent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeChild</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">loop</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span></pre>
</div>
</div>
<p>Simple huh?</p>
<ul>
<li> <strong>y += vy; x += vx;</strong> Pretty self explanatory. Add our velocity to x and y and move our ship! Awesome, I love Flash and its simplicity.</li>
<li><strong>if (x &gt; 520 || y &gt; 420 || x &lt; -20 || y &lt; -20) destroy();</strong> If our laser runs off the game screen&#8230; kill it. Well call our destroy function and it will kill it.</li>
<li><strong>if (parent) parent.removeChild(this);</strong> If the laser has a parent then remove the laser from the parent. Woah! what is a parent? Well when a MovieClip (or in general any DisplayObject) is inside another MovieClip then that Movieclip is the child and the other is the parent, respectively. So when in our Ship.as we did <em>stage.addChild(new Laser(&#8230;));</em> the parent of our laser became the stage. So all we are doing is saying if the parent isn&#8217;t null then it has a parent and we need to remove it from the parent. This way garbage collection can grab it.</li>
<li><strong>removeEventListener(Event.ENTER_FRAME, loop);</strong> This stops the laser from calling loop every time we enter the frame. Once removed we have no way to access our laser anymore so garbage collection upon it&#8217;s next run will grab our laser and get rid of it from memory.</li>
</ul>
<p>Last here&#8217;s the full source code for our laser class.</p>
<div class="wp_syntax">
<div class="code">
<pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>asgamer<span style="color: #000066; font-weight: bold;">.</span>directionalmovement
<span style="color: #000000;">&#123;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MovieClip</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Stage</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Laser <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">MovieClip</span>
	<span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> vx<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> vy<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> speed<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">12</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Laser <span style="color: #000000;">&#40;</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span> shipRotation<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">rotation</span> = shipRotation<span style="color: #000066; font-weight: bold;">;</span>
			vy <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sin</span><span style="color: #000000;">&#40;</span>degreesToRadians<span style="color: #000000;">&#40;</span>shipRotation<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> speed<span style="color: #000066; font-weight: bold;">;</span>
			vx <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">cos</span><span style="color: #000000;">&#40;</span>degreesToRadians<span style="color: #000000;">&#40;</span>shipRotation<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> speed<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">+</span> vx<span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">+</span> vy<span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">loop</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">loop</span><span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">+</span>= vy<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">+</span>= vx<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight:bold;">520</span> <span style="color: #000066; font-weight: bold;">||</span> <span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight:bold;">420</span> <span style="color: #000066; font-weight: bold;">||</span> <span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">&lt;</span> <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">20</span> <span style="color: #000066; font-weight: bold;">||</span> <span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">&lt;</span> <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">20</span><span style="color: #000000;">&#41;</span>
				destroy<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> destroy<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">parent</span><span style="color: #000000;">&#41;</span>
				<span style="color: #004993;">parent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeChild</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">loop</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> degreesToRadians<span style="color: #000000;">&#40;</span>degrees<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Number</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> degrees <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span> <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">180</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #000000;">&#125;</span></pre>
</div>
</div>
<p>Alright guys and gals, we&#8217;re finished!!! You should have something that looks like the below. <img src='http://asgamer.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<div id="swfobj_2"></div>
<p>				<!-- Social Sharing Toolkit v2.0.4 | http://www.marijnrongen.com/wordpress-plugins/social_sharing_toolkit/ --></p>
<div class="mr_social_sharing_wrapper"><span class="mr_social_sharing"><a href="http://twitter.com/share?url=http%3A%2F%2Fasgamer.com%2F2009%2Fasteroids-style-movement-firing-lasers&amp;text=Asteroids+Style+Movement%E2%80%A6+Now+with+Firing+Lasers&amp;via=jon_par" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/twitter.png" alt="Share on Twitter" title="Share on Twitter"/></a></span><span class="mr_social_sharing"><g:plusone size="medium" count="false" href="http://asgamer.com/2009/asteroids-style-movement-firing-lasers"></g:plusone></span><span class="mr_social_sharing"><a href="http://www.tumblr.com/share/link?url=http%3A%2F%2Fasgamer.com%2F2009%2Fasteroids-style-movement-firing-lasers&amp;name=Asteroids+Style+Movement%E2%80%A6+Now+with+Firing+Lasers" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/tumblr.png" alt="Share on Tumblr" title="Share on Tumblr"/></a></span><span class="mr_social_sharing"><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fasteroids-style-movement-firing-lasers&amp;title=Asteroids+Style+Movement%E2%80%A6+Now+with+Firing+Lasers" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/stumbleupon.png" alt="Submit to StumbleUpon" title="Submit to StumbleUpon"/></a></span><span class="mr_social_sharing"><a href="http://del.icio.us/post?url=http%3A%2F%2Fasgamer.com%2F2009%2Fasteroids-style-movement-firing-lasers&amp;title=Asteroids+Style+Movement%E2%80%A6+Now+with+Firing+Lasers" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/delicious.png" alt="Save on Delicious" title="Save on Delicious"/></a></span><span class="mr_social_sharing"><a href="http://digg.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fasteroids-style-movement-firing-lasers&amp;title=Asteroids+Style+Movement%E2%80%A6+Now+with+Firing+Lasers" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/digg.png" alt="Digg This" title="Digg This"/></a></span><span class="mr_social_sharing"><a href="http://www.reddit.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fasteroids-style-movement-firing-lasers" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/reddit.png" alt="Submit to reddit" title="Submit to reddit"/></a></span><span class="mr_social_sharing"><iframe src="https://www.facebook.com/plugins/like.php?locale=en_US&amp;href=http%3A%2F%2Fasgamer.com%2F2009%2Fasteroids-style-movement-firing-lasers&amp;layout=standard&amp;show_faces=false&amp;width=51px&amp;height=24px" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:51px; height:24px;" allowTransparency="true"></iframe></span></div>
]]></content:encoded>
			<wfw:commentRss>http://asgamer.com/2009/asteroids-style-movement-firing-lasers/feed</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Graphic Design &#8211; Making Smoke in Flash</title>
		<link>http://asgamer.com/2009/game-graphic-design-smoke-flash</link>
		<comments>http://asgamer.com/2009/game-graphic-design-smoke-flash#comments</comments>
		<pubDate>Wed, 01 Jul 2009 19:20:29 +0000</pubDate>
		<dc:creator>Par</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Art]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[explosion]]></category>
		<category><![CDATA[featured]]></category>
		<category><![CDATA[Game Development]]></category>
		<category><![CDATA[gamedev]]></category>
		<category><![CDATA[Graphic]]></category>
		<category><![CDATA[Photoshop]]></category>

		<guid isPermaLink="false">http://asgamer.com/?p=474</guid>
		<description><![CDATA[What good is smoke? Let&#8217;s think for a second. What produces smoke? Failing mechanical equipment, grenades, guns, volcanoes, factories, fires, vehicles, and probably a million other things. So does your Flash game need smoke, well, that&#8217;s for your to decide. But the fact of the matter is we can produce some rather convincing smoke with [...]]]></description>
			<content:encoded><![CDATA[<p>				<!-- Social Sharing Toolkit v2.0.4 | http://www.marijnrongen.com/wordpress-plugins/social_sharing_toolkit/ --></p>
<div class="mr_social_sharing_wrapper"><span class="mr_social_sharing"><a href="http://twitter.com/share?url=http%3A%2F%2Fasgamer.com%2F2009%2Fgame-graphic-design-smoke-flash&amp;text=Graphic+Design+%E2%80%93+Making+Smoke+in+Flash&amp;via=jon_par" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/twitter.png" alt="Share on Twitter" title="Share on Twitter"/></a></span><span class="mr_social_sharing"><g:plusone size="medium" count="false" href="http://asgamer.com/2009/game-graphic-design-smoke-flash"></g:plusone></span><span class="mr_social_sharing"><a href="http://www.tumblr.com/share/link?url=http%3A%2F%2Fasgamer.com%2F2009%2Fgame-graphic-design-smoke-flash&amp;name=Graphic+Design+%E2%80%93+Making+Smoke+in+Flash" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/tumblr.png" alt="Share on Tumblr" title="Share on Tumblr"/></a></span><span class="mr_social_sharing"><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fgame-graphic-design-smoke-flash&amp;title=Graphic+Design+%E2%80%93+Making+Smoke+in+Flash" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/stumbleupon.png" alt="Submit to StumbleUpon" title="Submit to StumbleUpon"/></a></span><span class="mr_social_sharing"><a href="http://del.icio.us/post?url=http%3A%2F%2Fasgamer.com%2F2009%2Fgame-graphic-design-smoke-flash&amp;title=Graphic+Design+%E2%80%93+Making+Smoke+in+Flash" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/delicious.png" alt="Save on Delicious" title="Save on Delicious"/></a></span><span class="mr_social_sharing"><a href="http://digg.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fgame-graphic-design-smoke-flash&amp;title=Graphic+Design+%E2%80%93+Making+Smoke+in+Flash" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/digg.png" alt="Digg This" title="Digg This"/></a></span><span class="mr_social_sharing"><a href="http://www.reddit.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fgame-graphic-design-smoke-flash" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/reddit.png" alt="Submit to reddit" title="Submit to reddit"/></a></span><span class="mr_social_sharing"><iframe src="https://www.facebook.com/plugins/like.php?locale=en_US&amp;href=http%3A%2F%2Fasgamer.com%2F2009%2Fgame-graphic-design-smoke-flash&amp;layout=standard&amp;show_faces=false&amp;width=51px&amp;height=24px" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:51px; height:24px;" allowTransparency="true"></iframe></span></div>
<p>What good is smoke? Let&#8217;s think for a second. What produces smoke? Failing mechanical equipment, grenades, guns, volcanoes, factories, fires, vehicles, and probably a million other things. So does your Flash game need smoke, well, that&#8217;s for your to decide. But the fact of the matter is we can produce some rather convincing smoke with a very simple bit of code and a little Adobe Photoshop. So let&#8217;s make some smoke.</p>
<h2>Creating Our Smoke Graphic Texture in Photoshop</h2>
<p>Open up Photoshop and create a new document 40&#215;40. Now go to your brushes window <strong><span style="color: #ff6600;">(F5)</span></strong> and select the brush in the image below.</p>
<p><img class="alignnone size-full wp-image-475" title="thepuff-0" src="http://asgamer.com/wp-content/uploads/2009/07/thepuff-0.jpg" alt="thepuff-0" width="263" height="310" /></p>
<p>and change a few of the settings on this brush as in the image below.</p>
<p><a href="http://asgamer.com/wp-content/uploads/2009/07/thepuff-01.jpg"><img class="alignnone size-full wp-image-476" title="thepuff-01" src="http://asgamer.com/wp-content/uploads/2009/07/thepuff-01.jpg" alt="thepuff-01" width="379" height="463" /></a></p>
<p>Now simply go in the middle of your canvas and make a smoke puff. Set the opacity down a little maybe 20% and start drawing. Make a little texture to it.</p>
<p><img class="alignnone size-full wp-image-477" title="thepuff-1" src="http://asgamer.com/wp-content/uploads/2009/07/smokepuff.png" alt="thepuff-1" /></p>
<p>It should look a little something like the above. Take your puff and save it as a png. If you don&#8217;t like how your puff looks then you can feel free to copy mine above. Just save it, it&#8217;s a png and will work well.</p>
<h2>Setting Our Smoke Puff up in Flash</h2>
<p>Okay. Very simple, Import from the Library your smoke puff. <strong><span style="color: #ff6600;">File &gt; Import &gt; Import to Library&#8230;</span></strong></p>
<p>Now just drop the image of your smoke puff dead center in the middle of a new MovieClip, name is SmokePuff.  Your stage should look like the image below:</p>
<p><img class="alignnone size-full wp-image-478" title="thepuff-2" src="http://asgamer.com/wp-content/uploads/2009/07/thepuff-2.jpg" alt="thepuff-2" width="111" height="105" /></p>
<p>Okay so one more thing left to do and you are set. Right click your SmokePuff MovieClip from the Library<strong><span style="color: #ff6600;">(CTRL+L) </span></strong>and select Linkage&#8230; Now just copy what you see below and click okay.</p>
<p><img class="alignnone size-full wp-image-479" title="thepuff-3" src="http://asgamer.com/wp-content/uploads/2009/07/thepuff-3.jpg" alt="thepuff-3" width="460" height="242" /></p>
<p>One last thing&#8230; set your document class to Main. Nice. Flash is ready, let&#8217;s start writing some code.</p>
<h2>Writing the Actionscript to make some Smoke</h2>
<p>Okay guys, this has been a super quick tutorial so far. Lots of images and little to say. Let&#8217;s get into the code that will say everything we need to make our smoke fly beautifully. Honestly guys this code is so straight forward, let me just post the Smokepuff.as class at once and explain it later. Make sure you save it to com/asgamer/graphics</p>
<div class="wp_syntax">
<div class="code">
<pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>asgamer<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span>
<span style="color: #000000;">&#123;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">BlendMode</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MovieClip</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Smokepuff <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">MovieClip</span>
	<span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> vx<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> vy<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Smokepuff<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">alpha</span> = <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			vx = <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			vy = <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">3</span> <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">5</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">scaleX</span> = <span style="color: #004993;">scaleY</span> = <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">loop</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">loop</span><span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">alpha</span> <span style="color: #000066; font-weight: bold;">-</span>= <span style="color: #000000; font-weight:bold;">0.01</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">+</span>= vy<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">+</span>= vx<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">scaleX</span> = <span style="color: #004993;">scaleY</span> <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #000000; font-weight:bold;">0.02</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">alpha</span> <span style="color: #000066; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>
				removeSelf<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> removeSelf<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">loop</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">parent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeChild</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre>
</div>
</div>
<p>Let&#8217;s break it down:</p>
<ul>
<li>We have a vx(velocity x) and vy(velocity y) class variable. Both are numbers and will hold the velocity of our smoke puff.</li>
<li>In our constructor we set up some basic information we need to use through our smoke puff.</li>
<li><strong>alpha = Math.random();</strong> We need some diversity with our puffs, let&#8217;s make them all start at a random alpha.</li>
<li><strong>vx = Math.random() &#8211; Math.random();</strong> Set the vx to something randomly between -1 and 1</li>
<li><strong>vy = Math.random() * 3 &#8211; 5;</strong> We need a negative vy so our smoke will move upward. This line will give us a number between -5 and -2 and some diversity in the speed of our smoke.</li>
<li><strong>scaleX = scaleY = Math.random();</strong> Choose a random value to start our smoke&#8217;s size. Once again to add some diversity.</li>
<li><strong>addEventListener(Event.ENTER_FRAME, loop, false, 0, true);</strong> each time we enter a frame&#8230; call loop.</li>
<li><strong>alpha -= 0.01;</strong> Make the alpha go down with each frame.</li>
<li><strong>y += vy; x += vx;</strong> Apply our velocity to our smokepuff.</li>
<li><strong>scaleX = scaleY += 0.02;</strong> Make our smoke spread out as it travels.</li>
<li><strong>if (alpha &lt; 0)  removeSelf(); </strong>If our smoke is no longer visible&#8230; let&#8217;s get rid of it.</li>
<li><strong>removeSelf()</strong> no need to fully explain this. It simply removes our event listener and removes the smoke puff from the display stack.</li>
</ul>
<p>Alright, so that makes our smoke move.  Let&#8217;s write the code for the main class.</p>
<div class="wp_syntax">
<div class="code">
<pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span>
<span style="color: #000000;">&#123;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Stage</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MovieClip</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>asgamer<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span>Smokepuff<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Main <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Sprite</span>
	<span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">loop</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">loop</span><span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> smokepuff<span style="color: #000066; font-weight: bold;">:</span>Smokepuff = <span style="color: #0033ff; font-weight: bold;">new</span> Smokepuff<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			smokepuff<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">250</span><span style="color: #000066; font-weight: bold;">;</span>
			smokepuff<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">250</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>smokepuff<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre>
</div>
</div>
<p>Okay breaking this down is extremely simple. We&#8217;re just creating an event listener to call loop on every enter frame like we did in Smokepuff. In the loop class we simply are creating a Smokepuff and positioning it at (250, 250) and adding it to the stage. From here our Smokepuff code will do everything on it&#8217;s own with a little help from garbage collection in the end.</p>
<p>Ready to see what it looks like?</p>
<div id="swfobj_3"></div>
<p>Awesome we&#8217;re done. Here&#8217;s the final source:<br />
<a href="http://asgamer.com/wp-content/uploads/2009/07/smokepuff.zip">Making Smoke in Flash Source Code Zip Archive</a><br />
				<!-- Social Sharing Toolkit v2.0.4 | http://www.marijnrongen.com/wordpress-plugins/social_sharing_toolkit/ --></p>
<div class="mr_social_sharing_wrapper"><span class="mr_social_sharing"><a href="http://twitter.com/share?url=http%3A%2F%2Fasgamer.com%2F2009%2Fgame-graphic-design-smoke-flash&amp;text=Graphic+Design+%E2%80%93+Making+Smoke+in+Flash&amp;via=jon_par" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/twitter.png" alt="Share on Twitter" title="Share on Twitter"/></a></span><span class="mr_social_sharing"><g:plusone size="medium" count="false" href="http://asgamer.com/2009/game-graphic-design-smoke-flash"></g:plusone></span><span class="mr_social_sharing"><a href="http://www.tumblr.com/share/link?url=http%3A%2F%2Fasgamer.com%2F2009%2Fgame-graphic-design-smoke-flash&amp;name=Graphic+Design+%E2%80%93+Making+Smoke+in+Flash" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/tumblr.png" alt="Share on Tumblr" title="Share on Tumblr"/></a></span><span class="mr_social_sharing"><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fgame-graphic-design-smoke-flash&amp;title=Graphic+Design+%E2%80%93+Making+Smoke+in+Flash" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/stumbleupon.png" alt="Submit to StumbleUpon" title="Submit to StumbleUpon"/></a></span><span class="mr_social_sharing"><a href="http://del.icio.us/post?url=http%3A%2F%2Fasgamer.com%2F2009%2Fgame-graphic-design-smoke-flash&amp;title=Graphic+Design+%E2%80%93+Making+Smoke+in+Flash" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/delicious.png" alt="Save on Delicious" title="Save on Delicious"/></a></span><span class="mr_social_sharing"><a href="http://digg.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fgame-graphic-design-smoke-flash&amp;title=Graphic+Design+%E2%80%93+Making+Smoke+in+Flash" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/digg.png" alt="Digg This" title="Digg This"/></a></span><span class="mr_social_sharing"><a href="http://www.reddit.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fgame-graphic-design-smoke-flash" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/reddit.png" alt="Submit to reddit" title="Submit to reddit"/></a></span><span class="mr_social_sharing"><iframe src="https://www.facebook.com/plugins/like.php?locale=en_US&amp;href=http%3A%2F%2Fasgamer.com%2F2009%2Fgame-graphic-design-smoke-flash&amp;layout=standard&amp;show_faces=false&amp;width=51px&amp;height=24px" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:51px; height:24px;" allowTransparency="true"></iframe></span></div>
]]></content:encoded>
			<wfw:commentRss>http://asgamer.com/2009/game-graphic-design-smoke-flash/feed</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Why and How to Encrypt Your Flash SWF</title>
		<link>http://asgamer.com/2009/why-how-to-encrypt-your-flash-swf</link>
		<comments>http://asgamer.com/2009/why-how-to-encrypt-your-flash-swf#comments</comments>
		<pubDate>Tue, 23 Jun 2009 17:36:39 +0000</pubDate>
		<dc:creator>Par</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[Game Development]]></category>
		<category><![CDATA[gamedev]]></category>
		<category><![CDATA[gotoAndPlay]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://asgamer.com/?p=459</guid>
		<description><![CDATA[So you just finished your first flash game, it's excellent, at least you think so. I mean you put hours on top of hours into it. Your eyes have been bloodshot and you've pulled your hair out more than once. Needless to say, you've worked hard and you are incredibly proud of it (But your ego is in check, you're not arrogant or anything :D ).  So you send your game off to be spread virally around the internet and it's doing amazing!!! You're making all kinds of money on your advertising, then a week later some guy comes out with your game and new graphics... better graphics.  But it's the same game, seriously to the last detail it works almost the exact same way. You're the victim of someone decompiling your game and stealing your source code! You're game loses popularity and you just lost a lot of hard work and money!]]></description>
			<content:encoded><![CDATA[<p>				<!-- Social Sharing Toolkit v2.0.4 | http://www.marijnrongen.com/wordpress-plugins/social_sharing_toolkit/ --></p>
<div class="mr_social_sharing_wrapper"><span class="mr_social_sharing"><a href="http://twitter.com/share?url=http%3A%2F%2Fasgamer.com%2F2009%2Fwhy-how-to-encrypt-your-flash-swf&amp;text=Why+and+How+to+Encrypt+Your+Flash+SWF&amp;via=jon_par" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/twitter.png" alt="Share on Twitter" title="Share on Twitter"/></a></span><span class="mr_social_sharing"><g:plusone size="medium" count="false" href="http://asgamer.com/2009/why-how-to-encrypt-your-flash-swf"></g:plusone></span><span class="mr_social_sharing"><a href="http://www.tumblr.com/share/link?url=http%3A%2F%2Fasgamer.com%2F2009%2Fwhy-how-to-encrypt-your-flash-swf&amp;name=Why+and+How+to+Encrypt+Your+Flash+SWF" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/tumblr.png" alt="Share on Tumblr" title="Share on Tumblr"/></a></span><span class="mr_social_sharing"><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fwhy-how-to-encrypt-your-flash-swf&amp;title=Why+and+How+to+Encrypt+Your+Flash+SWF" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/stumbleupon.png" alt="Submit to StumbleUpon" title="Submit to StumbleUpon"/></a></span><span class="mr_social_sharing"><a href="http://del.icio.us/post?url=http%3A%2F%2Fasgamer.com%2F2009%2Fwhy-how-to-encrypt-your-flash-swf&amp;title=Why+and+How+to+Encrypt+Your+Flash+SWF" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/delicious.png" alt="Save on Delicious" title="Save on Delicious"/></a></span><span class="mr_social_sharing"><a href="http://digg.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fwhy-how-to-encrypt-your-flash-swf&amp;title=Why+and+How+to+Encrypt+Your+Flash+SWF" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/digg.png" alt="Digg This" title="Digg This"/></a></span><span class="mr_social_sharing"><a href="http://www.reddit.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fwhy-how-to-encrypt-your-flash-swf" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/reddit.png" alt="Submit to reddit" title="Submit to reddit"/></a></span><span class="mr_social_sharing"><iframe src="https://www.facebook.com/plugins/like.php?locale=en_US&amp;href=http%3A%2F%2Fasgamer.com%2F2009%2Fwhy-how-to-encrypt-your-flash-swf&amp;layout=standard&amp;show_faces=false&amp;width=51px&amp;height=24px" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:51px; height:24px;" allowTransparency="true"></iframe></span></div>
<p>So you just finished your first flash game, it&#8217;s excellent, at least you think so. I mean you put hours on top of hours into it. Your eyes have been bloodshot and you&#8217;ve pulled your hair out more than once. Needless to say, you&#8217;ve worked hard and you are incredibly proud of it (But your ego is in check, you&#8217;re not arrogant or anything <img src='http://asgamer.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  ).  So you send your game off to be spread virally around the internet and it&#8217;s doing amazing!!! You&#8217;re making all kinds of money on your advertising, then a week later some guy comes out with your game and new graphics&#8230; better graphics.  But it&#8217;s the same game, seriously to the last detail it works almost the exact same way. You&#8217;re the victim of someone decompiling your game and stealing your source code! You&#8217;re game loses popularity and you just lost a lot of hard work and money!</p>
<p>Okay, that&#8217;s a fictitious example but it happens and it&#8217;s easier than you may think. For $79.99 you can purchase <a href="http://www.sothink.com/product/flashdecompiler/index.htm">Sothink SWF Decompiler</a> and you will be on your way to decompiling any and every swf you can get your hands on. Does it work? Yes. And let&#8217;s be honest, if someone is shady enough to steal your flash game&#8217;s actionscript code, they probably illegally downloaded SWF Decompiler meaning anyone can decompile your swfs for free!</p>
<h2>What is Flash SWF Encryption?</h2>
<p>Encryption is what is going to save your game from falling into the wrong hands.  It allows you to scramble your source code to the point that it will be completely unreadable by the person trying to recover your source code. The good is most, if not all, encryption software works on a compiled swf file so you don&#8217;t have to worry about it messing up your actual as2/as3 source code. The one thing I need to clear up though is all SWF Encryption software that I know of is not really encryption. Encryption requires decryption in order to make the encrypted application work. Since that&#8217;s not very reasonable in a public distributed viral flash game, it&#8217;s not a good option. Flash Encryption software actually works via code obfuscation methods.</p>
<p>Obfuscation you say? Yes, if your wondering. Obfuscation simply is the scrambling and renaming of your code to make it difficult to manage and interpret. So from now on when we call in encryption software as it is popularly called, we really mean obfuscation software.</p>
<p>Okay okay how do I encrypt my game?</p>
<p>Simple! There&#8217;s quite a few encryption software products on the market.  A simple search for flash encryption software on google will return plenty of possibilities.  The two games I&#8217;ve released to the public were encrypted and I wouldn&#8217;t have considered releasing them without it.</p>
<h2>Encrypt my Game Now with Kindisoft secureSWF</h2>
<p>I&#8217;ll be honest, I&#8217;ve researched flash game encryption for quite a while and when I finally decided who to use, I chose Amayeta SWF Encrypt 5.0. This was over a year ago. However, after a lot of reading at the Flash Game License forum I&#8217;ve seen it to be a pretty heated battle between whether SWF Encrypt or Kindisoft secureSWF is the better encryption software. That said, I highly doubt most of the people in the discussion have used both products, as of now, I have.</p>
<p>A  few weeks ago I asked Kindisoft if I could have a copy of their software to review. Full knowing that I could give them a bad review they handed over license and linked me to their download page to test the software. If I had developed their software, I would have done the same thing. It is without a doubt the most superior flash encryption software I have seen to date, it&#8217;s something to be proud of developing.  You can&#8217;t go wrong with this product, it&#8217;s simply amazing. Compared to secureSWF, SWF Encrypt options pale in comparison. Don&#8217;t get me wrong, SWF Encrypt is a solid product and it works (most of the time) but secureSWF is a lot more effective.</p>
<p>Once I got secureSWF loaded on my machine, my first goal was to fix a problem I&#8217;ve had with encrypting all my games with SWF Encrypt. Every time I encrypt a game on Kongregate with the API added I get a weird API Bootstrap error that messes up my game. I tried everything with SWF Encrypt to make it work but it never did. I ended up uploading my games with no encryption. SCARY! I know. secureSWF&#8217;s endless options helped me take care of everything I needed, now my <a title="Play Blueberry Escape From Chaos Factory" href="http://2leet.com/2009/05/play-blueberry-escape-chaos-factory-flash-game/">Blueberry: Escape from Chaos Factory</a> game is up on Kongregate and encrypted. Needless to say I am very happy and Kindisoft&#8217;s secureSWF is the reason why.</p>
<h2>How to Use Kindisoft secureSWF to Encrypt your Game</h2>
<p>Now you may or may not want to use secureSWF, that&#8217;s fine. But if you do, and I think the next few lines will convince you, here&#8217;s a look at all the features that the software has to offer and how you can use it to encrypt your next flash game.</p>
<div id="attachment_462" class="wp-caption alignnone" style="width: 560px"><img class="size-full wp-image-462" title="secureswf-1" src="http://asgamer.com/wp-content/uploads/2009/06/secureswf-1.jpg" alt="The secureSWF main loadup screen. Here you can pick which swf files you want to encrypt and setup some basic information" width="550" height="428" />
<p class="wp-caption-text">The secureSWF main loadup screen. Here you can pick which swf files you want to encrypt and setup some basic information</p>
</div>
<p>Okay so first things first, the main screen when you load up the application.  All you do is click add and select your swf file that you want to encrypt. Once done it will pop up a little information about your swf in the bottom right corner. As you can see Blueberry is a pretty detailed game (220 classes).  Another cool thing here is your have a dropdown of &#8220;Protection Presets&#8221; these let you choose how you want your swf file to be encrypted. There&#8217;s a few options from Aggressive to Testing, which you choose depends on how you developed you game. Certain programming choices you make will determine what options you can use and where. I&#8217;ll give an example later. Anyway, I chose custom with Blueberry because I wanted full control of what was encrypted. An extremely valuable feature that I have only seen with secureSWF. let me know if you know of a product with as much customization. I don&#8217;t know of any.</p>
<div id="attachment_463" class="wp-caption alignnone" style="width: 560px"><img class="size-full wp-image-463" title="secureswf-2" src="http://asgamer.com/wp-content/uploads/2009/06/secureswf-2.jpg" alt="The Identifiers Renaming Tab. Here you pick what you want secureSWF to rename in order to make reading your source code more difficult." width="550" height="428" />
<p class="wp-caption-text">The Identifiers Renaming Tab. Here you pick what you want secureSWF to rename in order to make reading your source code more difficult.</p>
</div>
<p>This made me very happy. Every class I used in Blueberry appeared in the tree list on the left. I could go through all the classes and choose which I wanted to be renamed and which I didn&#8217;t. At the same time when I clicked on a class it&#8217;s functions and variables would appear on the right. I could also select which of them I wanted to be renamed. Like before, I have a drop down that allows me to choose how aggressive I want the renaming to be.  There&#8217;s also an advanced option at the bottom that allows me to quickly control what classes, functions, variables, and labels will be renamed.</p>
<p>Now if you are wondering why you need to be in control of what&#8217;s renamed, let me explain. There are times when renaming certain functions or classes can cause your application to not work. Remember <a title="Call functions from string variables" href="http://asgamer.com/2009/using-string-variables-to-call-functions-in-as3">the tutorial about using strings to call functions</a>? Well, imagine if our encryption software names our jumpUp function &#8220;id_loc_3&#8243; but our string still keeps the data &#8220;jumpUp&#8221;.  We&#8217;ve got a problem. So to fix this we can simply tell secureSWF to not rename our jumpUp function. This is awesome, the other software I have used required me to disable all renaming in order to fix the issue.</p>
<div id="attachment_464" class="wp-caption alignnone" style="width: 560px"><img class="size-full wp-image-464" title="secureswf-3" src="http://asgamer.com/wp-content/uploads/2009/06/secureswf-3.jpg" alt="The labels tab. Here you can choose which labels to rename." width="550" height="428" />
<p class="wp-caption-text">The labels tab. Here you can choose which labels to rename.</p>
</div>
<p>Like the class renaming list the above picture is the label renaming list.  Here you can select what labels you want to rename and which you would like to leave alone. This is valuable for the same reason as I mentioned above.</p>
<p>An example, if you use gotoAndPlay(<span style="color: #ff0000;">frame label</span>); in your code, you don&#8217;t want your frame label to be changing. In the above case I&#8217;m deselecting vats because I want to be able to use gotoAndStop(&#8220;vats&#8221;); in my game&#8217;s sourcecode.</p>
<div id="attachment_465" class="wp-caption alignnone" style="width: 560px"><img class="size-full wp-image-465" title="secureswf-4" src="http://asgamer.com/wp-content/uploads/2009/06/secureswf-4.jpg" alt="The protec tion options. Make a few changes here and there and set your flash file as encrypted as possible" width="550" height="428" />
<p class="wp-caption-text">The protection options. Make a few changes here and there and set your flash file as encrypted as possible.</p>
</div>
<p>Here you can do a lot of work to encrypt your game. Everything for the most part is controlled by sliders which you can move in order to find the highest level of encryption that will work well with your game.  I&#8217;ll be bluntly honest with you, I don&#8217;t fully understand the details but I know what it does works as you can see from how mangled the source code is after an encryption occurs.</p>
<p>There is also the option to encrypt strings.  This works really well; however, not really needed unless you are wanting to hide the text inside the string from a decompiler. Which could definitely be useful on occasion, and it&#8217;s great to be able to access this feature if needed.</p>
<p>One of the handiest features on this tab is the domain locking feature. With domain locking you can control what websites the game can be played on. This works great when you have a site-locked sponsorship of your game that you want to make sure only works on that website. All you have to do is enter the url of the website the game is playable on and you are all set <img src='http://asgamer.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>There&#8217;s also a few optimization features that will increase the speed and filesize of your game. Definitely an excellent feature to have around.</p>
<h2>Final Note and examples of secureSWF and SWF Encryption</h2>
<p>Currently my flash development arsenal consists of four very solid applications.</p>
<ul>
<li>Adobe Flash</li>
<li>Adobe Photoshop</li>
<li>Flash Develop</li>
<li><em>and now</em> Kindisoft secureSWF</li>
</ul>
<p>With the first three apps I can program and design a solid flash game. With the last application, I can make sure my flash game stays mine and out of the hands of would be thieves. It&#8217;s the perfect mix.</p>
<p>I&#8217;d love to show you a before and after of some of the code from Blueberry but secureSWF&#8217;s encryption worked so well I couldn&#8217;t get my decompiler to actually decompile the code without crashing. Here&#8217;s an example from secureSWF&#8217;s website of what their encryption does to actionscript source code:</p>
<p>Before secureSWF:</p>
<div class="wp_syntax">
<div class="code">
<pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> getNeighbours<span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">,</span> j<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span><span style="color: #000000;">&#123;</span>
  <span style="color: #6699cc; font-weight: bold;">var</span> a<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> k = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> k <span style="color: #000066; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight:bold;">8</span><span style="color: #000066; font-weight: bold;">;</span> k<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
    <span style="color: #6699cc; font-weight: bold;">var</span> ni = i <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #004993;">int</span><span style="color: #000000;">&#40;</span>neighbour_map<span style="color: #000000;">&#91;</span>k<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #6699cc; font-weight: bold;">var</span> nj = j <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #004993;">int</span><span style="color: #000000;">&#40;</span>neighbour_map<span style="color: #000000;">&#91;</span>k<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>ni <span style="color: #000066; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000066; font-weight: bold;">||</span> ni <span style="color: #000066; font-weight: bold;">&gt;</span>= xsize <span style="color: #000066; font-weight: bold;">||</span> nj <span style="color: #000066; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000066; font-weight: bold;">||</span> nj <span style="color: #000066; font-weight: bold;">&gt;</span>= ysize<span style="color: #000000;">&#41;</span>
      <span style="color: #0033ff; font-weight: bold;">continue</span><span style="color: #000066; font-weight: bold;">;</span>
    a<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>Cell<span style="color: #000000;">&#40;</span>cells<span style="color: #000000;">&#91;</span>ni<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>nj<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #000000;">&#125;</span>
  <span style="color: #0033ff; font-weight: bold;">return</span> a<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre>
</div>
</div>
<p>after secureSWF:</p>
<div class="wp_syntax">
<div class="code">
<pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> getNeighbours<span style="color: #000000;">&#40;</span>_arg1<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">,</span> _arg2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span><span style="color: #000000;">&#123;</span>
  <span style="color: #6699cc; font-weight: bold;">var</span> _local3<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">null</span> <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000066; font-weight: bold;">!</span>NULL<span style="color: #000066; font-weight: bold;">!</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">%</span> <span style="color: #000066; font-weight: bold;">~</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">undefined</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #6699cc; font-weight: bold;">var</span> _local4<span style="color: #000066; font-weight: bold;">:*;</span>
  <span style="color: #6699cc; font-weight: bold;">var</span> _local5<span style="color: #000066; font-weight: bold;">:*;</span>
  <span style="color: #6699cc; font-weight: bold;">var</span> _local6<span style="color: #000066; font-weight: bold;">:*;</span>
  _local3 = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
  _local4 = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">;</span><span style="color: #009900; font-style: italic;">//unresolved jump</span>
  <span style="color: #000066; font-weight: bold;">,</span> _arg2 <span style="color: #000066; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight:bold;">8</span><span style="color: #000066; font-weight: bold;">;</span>_local4<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    _local5 = <span style="color: #000000;">&#40;</span>_arg1 <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #004993;">int</span><span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span>NULL<span style="color: #000066; font-weight: bold;">!</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
    _local6 = <span style="color: #000000;">&#40;</span>_arg2 <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #004993;">int</span><span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span>NULL<span style="color: #000066; font-weight: bold;">!</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
      _arg1 = <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #009900; font-style: italic;">//unresolved nextvalue or nextname &lt;&lt; !NULL!) + !NULL!) </span>
<span style="color: #000066; font-weight: bold;">&lt;&lt;</span> <span style="color: #0033ff; font-weight: bold;">undefined</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
      _arg1 = <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span><span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span>NULL<span style="color: #000066; font-weight: bold;">!</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">^</span> <span style="color: #000066; font-weight: bold;">!</span>NULL<span style="color: #000066; font-weight: bold;">!</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span>NULL<span style="color: #000066; font-weight: bold;">!</span> <span style="color: #0033ff; font-weight: bold;">instanceof</span> <span style="color: #000066; font-weight: bold;">!</span>NULL<span style="color: #000066; font-weight: bold;">!</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #6699cc; font-weight: bold;">var</span> _local1 = <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span>NULL<span style="color: #000066; font-weight: bold;">!</span> <span style="color: #0033ff; font-weight: bold;">as</span> <span style="color: #000066; font-weight: bold;">!</span>NULL<span style="color: #000066; font-weight: bold;">!</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000066; font-weight: bold;">!</span>NULL<span style="color: #000066; font-weight: bold;">!</span><span style="color: #000000;">&#41;</span> == <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span><span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span>NULL<span style="color: #000066; font-weight: bold;">!</span> == <span style="color: #000066; font-weight: bold;">!</span>NULL<span style="color: #000066; font-weight: bold;">!</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">true</span> <span style="color: #000066; font-weight: bold;">&lt;&lt;</span> <span style="color: #000066; font-weight: bold;">!</span>NULL<span style="color: #000066; font-weight: bold;">!</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>Cell<span style="color: #000000;">&#40;</span>cells<span style="color: #000000;">&#91;</span>_local5<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>_local6<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
    <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
      <span style="color: #000000;">&#40;</span>_local6 <span style="color: #000066; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #000000;">&#40;</span>_local6 <span style="color: #000066; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #000000;">&#40;</span>_local5 <span style="color: #000066; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #000000;">&#125;</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #000000;">&#40;</span>_local3<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre>
</div>
</div>
<p>I hope this gets you excited about encrypting your flash games. If you want more information you can find secureSWF at <a href="http://www.kindisoft.com/secureSWF">http://www.kindisoft.com/secureSWF/</a>. Enjoy and if you want to test out some of their products you can from their website or FlashGameLicense. FGL has partnered with Kindisoft to offer encryption for all flash files hosted on their website. So make sure to check out FGL and use a basic version of Kindisoft&#8217;s encryption and site-locking. </p>
<p>				<!-- Social Sharing Toolkit v2.0.4 | http://www.marijnrongen.com/wordpress-plugins/social_sharing_toolkit/ --></p>
<div class="mr_social_sharing_wrapper"><span class="mr_social_sharing"><a href="http://twitter.com/share?url=http%3A%2F%2Fasgamer.com%2F2009%2Fwhy-how-to-encrypt-your-flash-swf&amp;text=Why+and+How+to+Encrypt+Your+Flash+SWF&amp;via=jon_par" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/twitter.png" alt="Share on Twitter" title="Share on Twitter"/></a></span><span class="mr_social_sharing"><g:plusone size="medium" count="false" href="http://asgamer.com/2009/why-how-to-encrypt-your-flash-swf"></g:plusone></span><span class="mr_social_sharing"><a href="http://www.tumblr.com/share/link?url=http%3A%2F%2Fasgamer.com%2F2009%2Fwhy-how-to-encrypt-your-flash-swf&amp;name=Why+and+How+to+Encrypt+Your+Flash+SWF" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/tumblr.png" alt="Share on Tumblr" title="Share on Tumblr"/></a></span><span class="mr_social_sharing"><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fwhy-how-to-encrypt-your-flash-swf&amp;title=Why+and+How+to+Encrypt+Your+Flash+SWF" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/stumbleupon.png" alt="Submit to StumbleUpon" title="Submit to StumbleUpon"/></a></span><span class="mr_social_sharing"><a href="http://del.icio.us/post?url=http%3A%2F%2Fasgamer.com%2F2009%2Fwhy-how-to-encrypt-your-flash-swf&amp;title=Why+and+How+to+Encrypt+Your+Flash+SWF" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/delicious.png" alt="Save on Delicious" title="Save on Delicious"/></a></span><span class="mr_social_sharing"><a href="http://digg.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fwhy-how-to-encrypt-your-flash-swf&amp;title=Why+and+How+to+Encrypt+Your+Flash+SWF" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/digg.png" alt="Digg This" title="Digg This"/></a></span><span class="mr_social_sharing"><a href="http://www.reddit.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fwhy-how-to-encrypt-your-flash-swf" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/reddit.png" alt="Submit to reddit" title="Submit to reddit"/></a></span><span class="mr_social_sharing"><iframe src="https://www.facebook.com/plugins/like.php?locale=en_US&amp;href=http%3A%2F%2Fasgamer.com%2F2009%2Fwhy-how-to-encrypt-your-flash-swf&amp;layout=standard&amp;show_faces=false&amp;width=51px&amp;height=24px" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:51px; height:24px;" allowTransparency="true"></iframe></span></div>
]]></content:encoded>
			<wfw:commentRss>http://asgamer.com/2009/why-how-to-encrypt-your-flash-swf/feed</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>How to make Death vs. Monstars style explosions</title>
		<link>http://asgamer.com/2009/how-to-make-death-vs-monstars-style-explosions</link>
		<comments>http://asgamer.com/2009/how-to-make-death-vs-monstars-style-explosions#comments</comments>
		<pubDate>Fri, 08 May 2009 15:40:58 +0000</pubDate>
		<dc:creator>Par</dc:creator>
				<category><![CDATA[Link]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Art]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[explosion]]></category>
		<category><![CDATA[Game Development]]></category>
		<category><![CDATA[gamedev]]></category>
		<category><![CDATA[Graphic]]></category>
		<category><![CDATA[Inspirational]]></category>
		<category><![CDATA[Photoshop]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://asgamer.com/?p=437</guid>
		<description><![CDATA[If there's one game that's came out lately that I have really liked... it's Death vs. Monstars.  It's an exciting simple little flash game with lots and LOTS of bullets. If you haven't played it, you definitely should. The graphics are simple yet beautiful, and the gameplay is just fun. In this tutorial you are going to learn to make explosions like those in the game.]]></description>
			<content:encoded><![CDATA[<p>				<!-- Social Sharing Toolkit v2.0.4 | http://www.marijnrongen.com/wordpress-plugins/social_sharing_toolkit/ --></p>
<div class="mr_social_sharing_wrapper"><span class="mr_social_sharing"><a href="http://twitter.com/share?url=http%3A%2F%2Fasgamer.com%2F2009%2Fhow-to-make-death-vs-monstars-style-explosions&amp;text=How+to+make+Death+vs.+Monstars+style+explosions&amp;via=jon_par" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/twitter.png" alt="Share on Twitter" title="Share on Twitter"/></a></span><span class="mr_social_sharing"><g:plusone size="medium" count="false" href="http://asgamer.com/2009/how-to-make-death-vs-monstars-style-explosions"></g:plusone></span><span class="mr_social_sharing"><a href="http://www.tumblr.com/share/link?url=http%3A%2F%2Fasgamer.com%2F2009%2Fhow-to-make-death-vs-monstars-style-explosions&amp;name=How+to+make+Death+vs.+Monstars+style+explosions" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/tumblr.png" alt="Share on Tumblr" title="Share on Tumblr"/></a></span><span class="mr_social_sharing"><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fhow-to-make-death-vs-monstars-style-explosions&amp;title=How+to+make+Death+vs.+Monstars+style+explosions" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/stumbleupon.png" alt="Submit to StumbleUpon" title="Submit to StumbleUpon"/></a></span><span class="mr_social_sharing"><a href="http://del.icio.us/post?url=http%3A%2F%2Fasgamer.com%2F2009%2Fhow-to-make-death-vs-monstars-style-explosions&amp;title=How+to+make+Death+vs.+Monstars+style+explosions" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/delicious.png" alt="Save on Delicious" title="Save on Delicious"/></a></span><span class="mr_social_sharing"><a href="http://digg.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fhow-to-make-death-vs-monstars-style-explosions&amp;title=How+to+make+Death+vs.+Monstars+style+explosions" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/digg.png" alt="Digg This" title="Digg This"/></a></span><span class="mr_social_sharing"><a href="http://www.reddit.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fhow-to-make-death-vs-monstars-style-explosions" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/reddit.png" alt="Submit to reddit" title="Submit to reddit"/></a></span><span class="mr_social_sharing"><iframe src="https://www.facebook.com/plugins/like.php?locale=en_US&amp;href=http%3A%2F%2Fasgamer.com%2F2009%2Fhow-to-make-death-vs-monstars-style-explosions&amp;layout=standard&amp;show_faces=false&amp;width=51px&amp;height=24px" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:51px; height:24px;" allowTransparency="true"></iframe></span></div>
<p>If there&#8217;s one game that&#8217;s came out lately that I have really liked&#8230; it&#8217;s Death vs. Monstars.  It&#8217;s an exciting simple little flash game with lots and LOTS of bullets. If you haven&#8217;t played it, you definitely should. The graphics are simple yet beautiful, and the gameplay is just fun.</p>
<p><a href="http://2leet.com/death-vs-monstars-flash-game/">Here&#8217;s the game if you want to play it. (after the jump)<br />
</a></p>
<p><a href="http://2leet.com/death-vs-monstars-flash-game/"><img class="alignnone size-full wp-image-438" title="gamescreen" src="http://asgamer.com/wp-content/uploads/2009/05/gamescreen.jpg" alt="gamescreen" width="550" height="471" /></a></p>
<p>Anyway, I didn&#8217;t write this tutorial but it&#8217;s a good graphics one.</p>
<p>Here&#8217;s the link to the tutorial by the game&#8217;s author:<br />
<a title="Game Reclaim" href="http://www.gamereclaim.com/2009/04/how-to-make-death-vs-monstars-style-explosions/">http://www.gamereclaim.com/2009/04/how-to-make-death-vs-monstars-style-explosions/</a></p>
<p>Enjoy!<br />
				<!-- Social Sharing Toolkit v2.0.4 | http://www.marijnrongen.com/wordpress-plugins/social_sharing_toolkit/ --></p>
<div class="mr_social_sharing_wrapper"><span class="mr_social_sharing"><a href="http://twitter.com/share?url=http%3A%2F%2Fasgamer.com%2F2009%2Fhow-to-make-death-vs-monstars-style-explosions&amp;text=How+to+make+Death+vs.+Monstars+style+explosions&amp;via=jon_par" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/twitter.png" alt="Share on Twitter" title="Share on Twitter"/></a></span><span class="mr_social_sharing"><g:plusone size="medium" count="false" href="http://asgamer.com/2009/how-to-make-death-vs-monstars-style-explosions"></g:plusone></span><span class="mr_social_sharing"><a href="http://www.tumblr.com/share/link?url=http%3A%2F%2Fasgamer.com%2F2009%2Fhow-to-make-death-vs-monstars-style-explosions&amp;name=How+to+make+Death+vs.+Monstars+style+explosions" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/tumblr.png" alt="Share on Tumblr" title="Share on Tumblr"/></a></span><span class="mr_social_sharing"><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fhow-to-make-death-vs-monstars-style-explosions&amp;title=How+to+make+Death+vs.+Monstars+style+explosions" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/stumbleupon.png" alt="Submit to StumbleUpon" title="Submit to StumbleUpon"/></a></span><span class="mr_social_sharing"><a href="http://del.icio.us/post?url=http%3A%2F%2Fasgamer.com%2F2009%2Fhow-to-make-death-vs-monstars-style-explosions&amp;title=How+to+make+Death+vs.+Monstars+style+explosions" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/delicious.png" alt="Save on Delicious" title="Save on Delicious"/></a></span><span class="mr_social_sharing"><a href="http://digg.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fhow-to-make-death-vs-monstars-style-explosions&amp;title=How+to+make+Death+vs.+Monstars+style+explosions" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/digg.png" alt="Digg This" title="Digg This"/></a></span><span class="mr_social_sharing"><a href="http://www.reddit.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fhow-to-make-death-vs-monstars-style-explosions" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/reddit.png" alt="Submit to reddit" title="Submit to reddit"/></a></span><span class="mr_social_sharing"><iframe src="https://www.facebook.com/plugins/like.php?locale=en_US&amp;href=http%3A%2F%2Fasgamer.com%2F2009%2Fhow-to-make-death-vs-monstars-style-explosions&amp;layout=standard&amp;show_faces=false&amp;width=51px&amp;height=24px" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:51px; height:24px;" allowTransparency="true"></iframe></span></div>
]]></content:encoded>
			<wfw:commentRss>http://asgamer.com/2009/how-to-make-death-vs-monstars-style-explosions/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Making a Complete Flash Game: Menus, UI, Screens, or Windows</title>
		<link>http://asgamer.com/2009/making-a-complete-flash-game-menus-ui-screens-or-windows</link>
		<comments>http://asgamer.com/2009/making-a-complete-flash-game-menus-ui-screens-or-windows#comments</comments>
		<pubDate>Mon, 27 Apr 2009 16:13:36 +0000</pubDate>
		<dc:creator>Par</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Art]]></category>
		<category><![CDATA[Game Development]]></category>
		<category><![CDATA[gamedev]]></category>
		<category><![CDATA[Graphic]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[user interface]]></category>

		<guid isPermaLink="false">http://asgamer.com/?p=429</guid>
		<description><![CDATA[Whatever you want to call it, a complete Flash game is going to need an user interface that kicks off the game. A place where the user can get more information about the game, see the credits, save the game, load the game, whatever needs to be done. The Menu the starts the game provides this functionality. So how are we going to do it? Well, you're probably thinking this is a simple task, and it is. We're going to make it a step simpler by creating a base menu class that we will extend in all our other menu classes. This base class will keep some of our core functionality so we don't have to write transitions for each class uniquely.]]></description>
			<content:encoded><![CDATA[<p>				<!-- Social Sharing Toolkit v2.0.4 | http://www.marijnrongen.com/wordpress-plugins/social_sharing_toolkit/ --></p>
<div class="mr_social_sharing_wrapper"><span class="mr_social_sharing"><a href="http://twitter.com/share?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-menus-ui-screens-or-windows&amp;text=Making+a+Complete+Flash+Game%3A+Menus%2C+UI%2C+Screens%2C+or+Windows&amp;via=jon_par" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/twitter.png" alt="Share on Twitter" title="Share on Twitter"/></a></span><span class="mr_social_sharing"><g:plusone size="medium" count="false" href="http://asgamer.com/2009/making-a-complete-flash-game-menus-ui-screens-or-windows"></g:plusone></span><span class="mr_social_sharing"><a href="http://www.tumblr.com/share/link?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-menus-ui-screens-or-windows&amp;name=Making+a+Complete+Flash+Game%3A+Menus%2C+UI%2C+Screens%2C+or+Windows" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/tumblr.png" alt="Share on Tumblr" title="Share on Tumblr"/></a></span><span class="mr_social_sharing"><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-menus-ui-screens-or-windows&amp;title=Making+a+Complete+Flash+Game%3A+Menus%2C+UI%2C+Screens%2C+or+Windows" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/stumbleupon.png" alt="Submit to StumbleUpon" title="Submit to StumbleUpon"/></a></span><span class="mr_social_sharing"><a href="http://del.icio.us/post?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-menus-ui-screens-or-windows&amp;title=Making+a+Complete+Flash+Game%3A+Menus%2C+UI%2C+Screens%2C+or+Windows" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/delicious.png" alt="Save on Delicious" title="Save on Delicious"/></a></span><span class="mr_social_sharing"><a href="http://digg.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-menus-ui-screens-or-windows&amp;title=Making+a+Complete+Flash+Game%3A+Menus%2C+UI%2C+Screens%2C+or+Windows" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/digg.png" alt="Digg This" title="Digg This"/></a></span><span class="mr_social_sharing"><a href="http://www.reddit.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-menus-ui-screens-or-windows" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/reddit.png" alt="Submit to reddit" title="Submit to reddit"/></a></span><span class="mr_social_sharing"><iframe src="https://www.facebook.com/plugins/like.php?locale=en_US&amp;href=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-menus-ui-screens-or-windows&amp;layout=standard&amp;show_faces=false&amp;width=51px&amp;height=24px" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:51px; height:24px;" allowTransparency="true"></iframe></span></div>
<p>Whatever you want to call it, a complete Flash game is going to need an user interface that kicks off the game. A place where the user can get more information about the game, see the credits, save the game, load the game, whatever needs to be done. The Menu the starts the game provides this functionality. So how are we going to do it? Well, you&#8217;re probably thinking this is a simple task, and it is. We&#8217;re going to make it a step simpler by creating a base menu class that we will extend in all our other menu classes. This base class will keep some of our core functionality so we don&#8217;t have to write transitions for each class uniquely.</p>
<div id="serial-posts-wrapper">
<h3 class="serial-posts-heading"><span class="serial-pre-text">You are reading</span>&nbsp;<span class="serial-name">Making a Complete Flash Game</span>&nbsp;<span class="serial-post-text">Read more from this series of articles.</span></h3>
<ul class="serial-posts">
<li class="serial-posts-list-item"><a href="http://asgamer.com/2009/making-a-complete-flash-game-creating-understanding-the-preloader" title="Making a Complete Flash Game: Creating &#038; Understanding the Preloader">Making a Complete Flash Game: Creating &#038; Understanding the Preloader</a></li>
<li class="serial-posts-list-item"><a href="http://asgamer.com/2009/making-a-complete-flash-game-prerolling-sponsor-ads-and-your-logo" title="Making a Complete Flash Game: Prerolling Sponsor Ads and Your Logo">Making a Complete Flash Game: Prerolling Sponsor Ads and Your Logo</a></li>
<li class="serial-posts-list-item current-inactive">Making a Complete Flash Game: Menus, UI, Screens, or Windows</li>
</ul>
</div>
<p>Now, you are going to need to download a<a href="http://asgamer.com/wp-content/uploads/2009/04/completegameseries-3begin-menus.zip"> new zip file</a> to start this project.  If you have been keeping up with the last two tutorials in this series, you will still need to download <a href="http://asgamer.com/wp-content/uploads/2009/04/completegameseries-3begin-menus.zip">this zip archive</a>.  The code in this zip is the same as we left it at the end of the last project. However, the fla contains a new folder called Menus with a few graphic files and MovieClips setup to be used in this tutorial. The reason I am doing this is because, I really don&#8217;t want to keep explaining the same things over and over, if you are having problems understanding then you need to go back and read <a title="AS3 Flash Game Development Tutorial" href="http://asgamer.com/2009/flash-game-design-basics-adding-library-objects-to-stage-with-as3">AS3 Flash Games for Beginners</a>.  Anyway make sure you grab the zip file from the links above so you can get started.</p>
<h3>Step 1: Explaining the new FLA File</h3>
<p>Okay here&#8217;s the deal. The FLA file you downloaded in the zip has a new folder called Menus in the Library. Under Menus we have Credits and MainMenu folders.  Each have some graphic files in them and buttons for our Menu pages. The main file in each is titled Credits and MainMenu. These two MovieClips have linkage set to com.asgamer.snipergame.CreditsMenu and com.asgamer.snipergame.MainMenu respectively. They are both set to Export on Frame 1 and are not in our AssetHolder MovieClip.  So you will need to turn export on frame 1 off and drop them in the AssetHolder MovieClip.  I could have done this for you but this is good practice because you&#8217;ll need to do it with any asset your create in your game. (At least with the preloader method we are using)</p>
<h3>Step 2: Our Menu Design Goals</h3>
<p>Okay, so you have already seen our menus. But what is my user interface goal? Well, in the few games I have made, I&#8217;ve learned a thing or two to be consistent. One of those things is that pretty much every user interface menu you design will need to appear and disappear as the user jumps between them. And of course we&#8217;d like our menu to transition gracefully so we need a way to animate it in and out.  Since this is always consistent in our UI, let&#8217;s make a base class for our menus that does the animate in and out.</p>
<p><strong>Whoa, base class you say?</strong></p>
<p>I may have talked about this before and maybe you know what it is but if not I&#8217;ll explain.  Let me explain it in a simple manner.  A Base Class is a class that when extended we can use all the public or internal functions and parameters of that class.  So we can write our animate in function once in our menu base class then have all our other classes extend it.  It&#8217;s like when I talked about MovieClips and DisplayObjects in <a href="http://asgamer.com/2009/flash-game-design-basics-adding-library-objects-to-stage-with-as3">AS3 Flash Games for Beginners</a></p>
<h3>Step 3: Let&#8217;s Make It (Our Base Class) Happen.</h3>
<p>Alright so here&#8217;s the deal. In our com/asgamer/snipergame directory let&#8217;s create our base class with a new AS file called BaseMenu.as. I want this base class to do two things:  Load (add to stage and animate in) and Unload (animate out and remove from stage).  Add while we are at it, let&#8217;s just have some fun with it. Let&#8217;s make it so that if we send it our next Menu to unload, it will go ahead and load it when our current Menu unloads. That&#8217;s a lot of load/unload talk. Let&#8217;s make it work.  So here&#8217;s our BaseMenu.as code.</p>
<div class="wp_syntax">
<div class="code">
<pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>asgamer<span style="color: #000066; font-weight: bold;">.</span>snipergame
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MovieClip</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> caurina<span style="color: #000066; font-weight: bold;">.</span>transitions<span style="color: #000066; font-weight: bold;">.</span>Tweener<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Stage</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> BaseMenu <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">MovieClip</span>
	<span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> stageRef<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Stage</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//the stage</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> loadNext<span style="color: #000066; font-weight: bold;">:</span>BaseMenu<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//instance of next Menu to load</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> BaseMenu<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">alpha</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">400</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">unload</span><span style="color: #000000;">&#40;</span>loadMe<span style="color: #000066; font-weight: bold;">:</span>BaseMenu = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>loadMe <span style="color: #000066; font-weight: bold;">!</span>= <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span>
				loadNext = loadMe<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			Tweener<span style="color: #000066; font-weight: bold;">.</span>addTween<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000;">&#123;</span> <span style="color: #004993;">alpha</span><span style="color: #000066; font-weight: bold;">:</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">:-</span><span style="color: #000000; font-weight:bold;">400</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">time</span><span style="color: #000066; font-weight: bold;">:</span> <span style="color: #000000; font-weight:bold;">0.7</span><span style="color: #000066; font-weight: bold;">,</span> onComplete<span style="color: #000066; font-weight: bold;">:</span>remove <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> remove<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Event</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;menuRemoved&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>stageRef<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">contains</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
				stageRef<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeChild</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>loadNext <span style="color: #000066; font-weight: bold;">!</span>= <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span>
				loadNext<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			stageRef<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			Tweener<span style="color: #000066; font-weight: bold;">.</span>addTween<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000;">&#123;</span> <span style="color: #004993;">alpha</span><span style="color: #000066; font-weight: bold;">:</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">time</span><span style="color: #000066; font-weight: bold;">:</span> <span style="color: #000000; font-weight:bold;">0.7</span><span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre>
</div>
</div>
<p>And the breakdown:</p>
<ul>
<li>First of all, imports and our BaseMenu extends MovieClip.  We have two class variables: stageRef (Stage Reference) and loadNext(an instance of the next Menu to load, if we have one)</li>
<li>In the constructor we set the alpha to 0 and the y to 400. This is so we can animate it fading in and moving up into position when we call load.</li>
<li><strong>public function unload(loadMe:BaseMenu = null) : void. </strong>Our unload function. It excepts a parameter called loadMe which is an instance of a BaseMenu (meaning it&#8217;s one of our menus we will create that extends BaseMenu).  The loadMe parameter is the new menu that we are going to load when we unload our current Menu.  Now if we don&#8217;t pass a new Menu into unload then loadMe will store as null.</li>
<li><strong>if (loadMe != null) loadNext = loadMe; </strong>So if loadMe gets something passed into it, then we will store it in loadNext (our class variable).</li>
<li><strong>Tweener.addTween(this, { alpha: 0, y:-400, time: 0.7, onComplete:remove } ); </strong>A simple animate out and move up tween using Tweener. If you need to know how to use Tweener or what it is then you should read <a title="How to use Tweener to animate objects" href="http://asgamer.com/2009/using-tweener-in-as3-to-move-objects">Using Tweener in AS3 to Move Objects</a>.</li>
<li><strong>public function remove() : void. </strong>When our tween completes this function is called. This function does three simple things. First it dispatches the event &#8220;menuRemoved&#8221; which we may need to use at sometime in the future, currently we have no need for it. Then if our menu is on the stage we remove it from the stage. And last if loadNext is not null then we go ahead and call load on the loadNext menu instance.</li>
<li><strong>public function load() : void. </strong>Simple function that adds our BaseMenu to the stage and Tweens it up into position while fading it in.</li>
</ul>
<p>Alright that covers the BaseMenu. Let&#8217;s make our MainMenu and our CreditsMenu pages.</p>
<h3>Step 4: Making the Main Menu and the Credits Menu Work</h3>
<p>Oh this is simple. We already have everything setup in our FLA so we just have to code it.  And coding these two is so simple I&#8217;m just going to drop off the code for both of them then explain it real quickly.</p>
<p>MainMenu.as</p>
<div class="wp_syntax">
<div class="code">
<pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>asgamer<span style="color: #000066; font-weight: bold;">.</span>snipergame
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MovieClip</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">SimpleButton</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Stage</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> MainMenu <span style="color: #0033ff; font-weight: bold;">extends</span> BaseMenu
	<span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> MainMenu<span style="color: #000000;">&#40;</span>stageRef<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Stage</span> = <span style="color: #0033ff; font-weight: bold;">null</span> <span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>stageRef = stageRef<span style="color: #000066; font-weight: bold;">;</span>
			btnPlay<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_DOWN</span><span style="color: #000066; font-weight: bold;">,</span> playGame<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			btnCredits<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_DOWN</span><span style="color: #000066; font-weight: bold;">,</span> credits<span style="color: #000066; font-weight: bold;">,</span>  <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> playGame<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> credits<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">unload</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> CreditsMenu<span style="color: #000000;">&#40;</span>stageRef<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre>
</div>
</div>
<p>CreditsMenu.as</p>
<div class="wp_syntax">
<div class="code">
<pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>asgamer<span style="color: #000066; font-weight: bold;">.</span>snipergame
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MovieClip</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">SimpleButton</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Stage</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> CreditsMenu <span style="color: #0033ff; font-weight: bold;">extends</span> BaseMenu
	<span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> CreditsMenu<span style="color: #000000;">&#40;</span>stageRef<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Stage</span> = <span style="color: #0033ff; font-weight: bold;">null</span> <span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>stageRef = stageRef<span style="color: #000066; font-weight: bold;">;</span>
			btnReturn<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_DOWN</span><span style="color: #000066; font-weight: bold;">,</span> returnMainMenu<span style="color: #000066; font-weight: bold;">,</span>  <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> returnMainMenu<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">unload</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> MainMenu<span style="color: #000000;">&#40;</span>stageRef<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre>
</div>
</div>
<p>Okay Breakdown Time:</p>
<ul>
<li>First thing you notice is that both have imports and extend BaseMenu. So they both have all the functionality of our BaseMenu class.</li>
<li>Both constructors except the stage reference. We add = null so during preloading when the menus try to load from inside our AssetHolder they won&#8217;t complain about not getting a parameter sent in to them.</li>
<li>Then also in the constructor we set event listeners on our buttons that our inside our Menu Movieclips.</li>
<li>the playGame function is currently empty. We will use it in the next tutorial.</li>
<li><strong>unload(new MainMenu(stageRef)); </strong>This unloads our menu(by calling unload from our BaseMenu class) and loads the instance of MainMenu that we are passing into it.</li>
</ul>
<p>See I told you it was simple! This tutorial is finished. Here&#8217;s the final SWF &amp; source:</p>
<div id="swfobj_4"></div>
<p><a href="http://asgamer.com/wp-content/uploads/2009/04/completegameseries-3end-menus.zip">Menus, UI, Screens, or Windows Complete Source Zip Archive</a><br />
				<!-- Social Sharing Toolkit v2.0.4 | http://www.marijnrongen.com/wordpress-plugins/social_sharing_toolkit/ --></p>
<div class="mr_social_sharing_wrapper"><span class="mr_social_sharing"><a href="http://twitter.com/share?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-menus-ui-screens-or-windows&amp;text=Making+a+Complete+Flash+Game%3A+Menus%2C+UI%2C+Screens%2C+or+Windows&amp;via=jon_par" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/twitter.png" alt="Share on Twitter" title="Share on Twitter"/></a></span><span class="mr_social_sharing"><g:plusone size="medium" count="false" href="http://asgamer.com/2009/making-a-complete-flash-game-menus-ui-screens-or-windows"></g:plusone></span><span class="mr_social_sharing"><a href="http://www.tumblr.com/share/link?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-menus-ui-screens-or-windows&amp;name=Making+a+Complete+Flash+Game%3A+Menus%2C+UI%2C+Screens%2C+or+Windows" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/tumblr.png" alt="Share on Tumblr" title="Share on Tumblr"/></a></span><span class="mr_social_sharing"><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-menus-ui-screens-or-windows&amp;title=Making+a+Complete+Flash+Game%3A+Menus%2C+UI%2C+Screens%2C+or+Windows" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/stumbleupon.png" alt="Submit to StumbleUpon" title="Submit to StumbleUpon"/></a></span><span class="mr_social_sharing"><a href="http://del.icio.us/post?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-menus-ui-screens-or-windows&amp;title=Making+a+Complete+Flash+Game%3A+Menus%2C+UI%2C+Screens%2C+or+Windows" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/delicious.png" alt="Save on Delicious" title="Save on Delicious"/></a></span><span class="mr_social_sharing"><a href="http://digg.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-menus-ui-screens-or-windows&amp;title=Making+a+Complete+Flash+Game%3A+Menus%2C+UI%2C+Screens%2C+or+Windows" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/digg.png" alt="Digg This" title="Digg This"/></a></span><span class="mr_social_sharing"><a href="http://www.reddit.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-menus-ui-screens-or-windows" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/reddit.png" alt="Submit to reddit" title="Submit to reddit"/></a></span><span class="mr_social_sharing"><iframe src="https://www.facebook.com/plugins/like.php?locale=en_US&amp;href=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-menus-ui-screens-or-windows&amp;layout=standard&amp;show_faces=false&amp;width=51px&amp;height=24px" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:51px; height:24px;" allowTransparency="true"></iframe></span></div>
]]></content:encoded>
			<wfw:commentRss>http://asgamer.com/2009/making-a-complete-flash-game-menus-ui-screens-or-windows/feed</wfw:commentRss>
		<slash:comments>44</slash:comments>
		</item>
		<item>
		<title>Easily Use Frameworks in Multiple Projects By Setting a Global Class Path</title>
		<link>http://asgamer.com/2009/easily-use-frameworks-in-multiple-projects-by-setting-a-global-class-path</link>
		<comments>http://asgamer.com/2009/easily-use-frameworks-in-multiple-projects-by-setting-a-global-class-path#comments</comments>
		<pubDate>Wed, 15 Apr 2009 12:37:08 +0000</pubDate>
		<dc:creator>Par</dc:creator>
				<category><![CDATA[Quick Tips]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[Game Development]]></category>
		<category><![CDATA[gamedev]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://asgamer.com/?p=422</guid>
		<description><![CDATA[This is a super valuable tip that has saved me a lot of time and headaches when starting a new project. Do you often find yourself copying frameworks like Tweener, Papervision, Box2D, as3CoreLib, and all the many others into the directory of your latest project? It get's annoying eh? Well there is a quick and very easy way to solve this problem so you don't have to always copy them everytime you start a new project.]]></description>
			<content:encoded><![CDATA[<p>				<!-- Social Sharing Toolkit v2.0.4 | http://www.marijnrongen.com/wordpress-plugins/social_sharing_toolkit/ --></p>
<div class="mr_social_sharing_wrapper"><span class="mr_social_sharing"><a href="http://twitter.com/share?url=http%3A%2F%2Fasgamer.com%2F2009%2Feasily-use-frameworks-in-multiple-projects-by-setting-a-global-class-path&amp;text=Easily+Use+Frameworks+in+Multiple+Projects+By+Setting+a+Global+Class+Path&amp;via=jon_par" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/twitter.png" alt="Share on Twitter" title="Share on Twitter"/></a></span><span class="mr_social_sharing"><g:plusone size="medium" count="false" href="http://asgamer.com/2009/easily-use-frameworks-in-multiple-projects-by-setting-a-global-class-path"></g:plusone></span><span class="mr_social_sharing"><a href="http://www.tumblr.com/share/link?url=http%3A%2F%2Fasgamer.com%2F2009%2Feasily-use-frameworks-in-multiple-projects-by-setting-a-global-class-path&amp;name=Easily+Use+Frameworks+in+Multiple+Projects+By+Setting+a+Global+Class+Path" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/tumblr.png" alt="Share on Tumblr" title="Share on Tumblr"/></a></span><span class="mr_social_sharing"><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Feasily-use-frameworks-in-multiple-projects-by-setting-a-global-class-path&amp;title=Easily+Use+Frameworks+in+Multiple+Projects+By+Setting+a+Global+Class+Path" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/stumbleupon.png" alt="Submit to StumbleUpon" title="Submit to StumbleUpon"/></a></span><span class="mr_social_sharing"><a href="http://del.icio.us/post?url=http%3A%2F%2Fasgamer.com%2F2009%2Feasily-use-frameworks-in-multiple-projects-by-setting-a-global-class-path&amp;title=Easily+Use+Frameworks+in+Multiple+Projects+By+Setting+a+Global+Class+Path" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/delicious.png" alt="Save on Delicious" title="Save on Delicious"/></a></span><span class="mr_social_sharing"><a href="http://digg.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Feasily-use-frameworks-in-multiple-projects-by-setting-a-global-class-path&amp;title=Easily+Use+Frameworks+in+Multiple+Projects+By+Setting+a+Global+Class+Path" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/digg.png" alt="Digg This" title="Digg This"/></a></span><span class="mr_social_sharing"><a href="http://www.reddit.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Feasily-use-frameworks-in-multiple-projects-by-setting-a-global-class-path" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/reddit.png" alt="Submit to reddit" title="Submit to reddit"/></a></span><span class="mr_social_sharing"><iframe src="https://www.facebook.com/plugins/like.php?locale=en_US&amp;href=http%3A%2F%2Fasgamer.com%2F2009%2Feasily-use-frameworks-in-multiple-projects-by-setting-a-global-class-path&amp;layout=standard&amp;show_faces=false&amp;width=51px&amp;height=24px" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:51px; height:24px;" allowTransparency="true"></iframe></span></div>
<p>This is a super valuable tip that has saved me a lot of time and headaches when starting a new project. Do you often find yourself copying frameworks like Tweener, Papervision, Box2D, as3CoreLib, and all the many others into the directory of your latest project? It get&#8217;s annoying eh? Well there is a quick and very easy way to solve this problem so you don&#8217;t have to always copy them every time you start a new project.</p>
<p>Okay so here&#8217;s the deal, you are going to want to create a folder somewhere on your hard drive that you will put all your most used frameworks. Once it&#8217;s created put the frameworks in there and you are ready to go.</p>
<p>All you have to do now is inside Flash go to Edit &gt; Preferences <strong><span style="color: #ff6600;">(CTRL+U)</span></strong> and click on ActionScript. You&#8217;ll get this little window:</p>
<p><img class="alignnone size-full wp-image-423" title="Actionscript Preferences Window" src="http://asgamer.com/wp-content/uploads/2009/04/classpath-1.jpg" alt="Actionscript Preferences Window" width="536" height="615" /></p>
<p>Now if you&#8217;re class is Actionscript 3.0 then under language select the ActionScript 3.0 Settings&#8230; button. If your class is ActionScript 2.0 then select that button instead.</p>
<p>Now you get this screen:</p>
<div id="attachment_424" class="wp-caption alignnone" style="width: 450px"><img class="size-full wp-image-424" title="classpath" src="http://asgamer.com/wp-content/uploads/2009/04/classpath-2.jpg" alt="List of Class Paths that can be accessed from any Flash Project." width="440" height="224" />
<p class="wp-caption-text">List of Class Paths that can be accessed from any Flash Project.</p>
</div>
<p>Alright. So you can see that I make use of this little feature extensively. I&#8217;ve added practically every AS3 Project that I use here.  Why? Because I hate copying  Tweener to every project that I write, this universal classpath idea is awesome.</p>
<p>So here&#8217;s how you use it, if you can&#8217;t tell already, press the little + sign and paste the url to your class here.  You can also click the crosshair symbol and use a GUI to get to the directory you want to add.  Notice that most of my directories end in an src file. This is because the majority of Projects that you will download will start the base directory of the current version with src&#8230; particularly if they use subversion.</p>
<p>If you use Flash Develop you can do the exact same thing with it under Project &gt; Properties &gt; Classpaths &gt; Edit Global Classpaths.</p>
<p>Anyway, you&#8217;re all set! Happy coding.<br />
				<!-- Social Sharing Toolkit v2.0.4 | http://www.marijnrongen.com/wordpress-plugins/social_sharing_toolkit/ --></p>
<div class="mr_social_sharing_wrapper"><span class="mr_social_sharing"><a href="http://twitter.com/share?url=http%3A%2F%2Fasgamer.com%2F2009%2Feasily-use-frameworks-in-multiple-projects-by-setting-a-global-class-path&amp;text=Easily+Use+Frameworks+in+Multiple+Projects+By+Setting+a+Global+Class+Path&amp;via=jon_par" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/twitter.png" alt="Share on Twitter" title="Share on Twitter"/></a></span><span class="mr_social_sharing"><g:plusone size="medium" count="false" href="http://asgamer.com/2009/easily-use-frameworks-in-multiple-projects-by-setting-a-global-class-path"></g:plusone></span><span class="mr_social_sharing"><a href="http://www.tumblr.com/share/link?url=http%3A%2F%2Fasgamer.com%2F2009%2Feasily-use-frameworks-in-multiple-projects-by-setting-a-global-class-path&amp;name=Easily+Use+Frameworks+in+Multiple+Projects+By+Setting+a+Global+Class+Path" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/tumblr.png" alt="Share on Tumblr" title="Share on Tumblr"/></a></span><span class="mr_social_sharing"><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Feasily-use-frameworks-in-multiple-projects-by-setting-a-global-class-path&amp;title=Easily+Use+Frameworks+in+Multiple+Projects+By+Setting+a+Global+Class+Path" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/stumbleupon.png" alt="Submit to StumbleUpon" title="Submit to StumbleUpon"/></a></span><span class="mr_social_sharing"><a href="http://del.icio.us/post?url=http%3A%2F%2Fasgamer.com%2F2009%2Feasily-use-frameworks-in-multiple-projects-by-setting-a-global-class-path&amp;title=Easily+Use+Frameworks+in+Multiple+Projects+By+Setting+a+Global+Class+Path" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/delicious.png" alt="Save on Delicious" title="Save on Delicious"/></a></span><span class="mr_social_sharing"><a href="http://digg.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Feasily-use-frameworks-in-multiple-projects-by-setting-a-global-class-path&amp;title=Easily+Use+Frameworks+in+Multiple+Projects+By+Setting+a+Global+Class+Path" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/digg.png" alt="Digg This" title="Digg This"/></a></span><span class="mr_social_sharing"><a href="http://www.reddit.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Feasily-use-frameworks-in-multiple-projects-by-setting-a-global-class-path" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/reddit.png" alt="Submit to reddit" title="Submit to reddit"/></a></span><span class="mr_social_sharing"><iframe src="https://www.facebook.com/plugins/like.php?locale=en_US&amp;href=http%3A%2F%2Fasgamer.com%2F2009%2Feasily-use-frameworks-in-multiple-projects-by-setting-a-global-class-path&amp;layout=standard&amp;show_faces=false&amp;width=51px&amp;height=24px" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:51px; height:24px;" allowTransparency="true"></iframe></span></div>
]]></content:encoded>
			<wfw:commentRss>http://asgamer.com/2009/easily-use-frameworks-in-multiple-projects-by-setting-a-global-class-path/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Making a Complete Flash Game: Prerolling Sponsor Ads and Your Logo</title>
		<link>http://asgamer.com/2009/making-a-complete-flash-game-prerolling-sponsor-ads-and-your-logo</link>
		<comments>http://asgamer.com/2009/making-a-complete-flash-game-prerolling-sponsor-ads-and-your-logo#comments</comments>
		<pubDate>Mon, 13 Apr 2009 16:54:30 +0000</pubDate>
		<dc:creator>Par</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Game Development]]></category>
		<category><![CDATA[gamedev]]></category>
		<category><![CDATA[preloader]]></category>
		<category><![CDATA[spotlight]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://asgamer.com/?p=411</guid>
		<description><![CDATA[One of the number one ways you can make money off your Flash game is to get a sponsor. One of the number one ways to get a sponsor is http://flashgamelicense.com.  That said, if you get a sponsor they are going to want their advertisement at the beginning of your Flash game.  Now honestly, this is probably one of the simplest things you can do with Flash. I mean all we are doing is showing their advertisement, which is likely a MovieClip, and then jumping on to our game.  But the thing is, you could sell your game to multiple sponsors. You are going to need a quick and easy way to show of the sponsors advertisement and your advertisement without having to change your whole game every time. So today we are going to write a quick simple class to go through and play all our sponsor and credit MovieClips before our game starts.]]></description>
			<content:encoded><![CDATA[<p>				<!-- Social Sharing Toolkit v2.0.4 | http://www.marijnrongen.com/wordpress-plugins/social_sharing_toolkit/ --></p>
<div class="mr_social_sharing_wrapper"><span class="mr_social_sharing"><a href="http://twitter.com/share?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-prerolling-sponsor-ads-and-your-logo&amp;text=Making+a+Complete+Flash+Game%3A+Prerolling+Sponsor+Ads+and+Your+Logo&amp;via=jon_par" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/twitter.png" alt="Share on Twitter" title="Share on Twitter"/></a></span><span class="mr_social_sharing"><g:plusone size="medium" count="false" href="http://asgamer.com/2009/making-a-complete-flash-game-prerolling-sponsor-ads-and-your-logo"></g:plusone></span><span class="mr_social_sharing"><a href="http://www.tumblr.com/share/link?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-prerolling-sponsor-ads-and-your-logo&amp;name=Making+a+Complete+Flash+Game%3A+Prerolling+Sponsor+Ads+and+Your+Logo" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/tumblr.png" alt="Share on Tumblr" title="Share on Tumblr"/></a></span><span class="mr_social_sharing"><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-prerolling-sponsor-ads-and-your-logo&amp;title=Making+a+Complete+Flash+Game%3A+Prerolling+Sponsor+Ads+and+Your+Logo" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/stumbleupon.png" alt="Submit to StumbleUpon" title="Submit to StumbleUpon"/></a></span><span class="mr_social_sharing"><a href="http://del.icio.us/post?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-prerolling-sponsor-ads-and-your-logo&amp;title=Making+a+Complete+Flash+Game%3A+Prerolling+Sponsor+Ads+and+Your+Logo" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/delicious.png" alt="Save on Delicious" title="Save on Delicious"/></a></span><span class="mr_social_sharing"><a href="http://digg.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-prerolling-sponsor-ads-and-your-logo&amp;title=Making+a+Complete+Flash+Game%3A+Prerolling+Sponsor+Ads+and+Your+Logo" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/digg.png" alt="Digg This" title="Digg This"/></a></span><span class="mr_social_sharing"><a href="http://www.reddit.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-prerolling-sponsor-ads-and-your-logo" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/reddit.png" alt="Submit to reddit" title="Submit to reddit"/></a></span><span class="mr_social_sharing"><iframe src="https://www.facebook.com/plugins/like.php?locale=en_US&amp;href=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-prerolling-sponsor-ads-and-your-logo&amp;layout=standard&amp;show_faces=false&amp;width=51px&amp;height=24px" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:51px; height:24px;" allowTransparency="true"></iframe></span></div>
<p>One of the number one ways you can make money off your Flash game is to get a sponsor. One of the number one ways to get a sponsor is <a href="http://flashgamelicense.com">http://flashgamelicense.com</a>.  That said, if you get a sponsor they are going to want their advertisement at the beginning of your Flash game.  Now honestly, this is probably one of the simplest things you can do with Flash. I mean all we are doing is showing their advertisement, which is likely a MovieClip, and then jumping on to our game.  But the thing is, you could sell your game to multiple sponsors. You are going to need a quick and easy way to show of the sponsors advertisement and your advertisement without having to change your whole game every time. So today we are going to write a quick simple class to go through and play all our sponsor and credit MovieClips before our game starts.</p>
<p>This tutorial is apart of a series on Flash game development and how to make a complete Flash game from the ground up.  Below is the Table of Contents for this series. If something in this article is confusing please return to the first article to progress from there. If you want to start this tutorial without reading the previous one, here is <a href="http://asgamer.com/wp-content/uploads/2009/04/completegameseries-1-preloader.zip">the source from the previous tutorial</a>.  This series is for intermediate Flash users. If you are a beginner and the information in this series is too advanced please read, <a title="AS3 Flash Games for Beginners" href="http://asgamer.com/2009/flash-game-design-basics-adding-library-objects-to-stage-with-as3">AS3 Flash Games for Beginners</a>.</p>
<div id="serial-posts-wrapper">
<h3 class="serial-posts-heading"><span class="serial-pre-text">You are reading</span>&nbsp;<span class="serial-name">Making a Complete Flash Game</span>&nbsp;<span class="serial-post-text">Read more from this series of articles.</span></h3>
<ul class="serial-posts">
<li class="serial-posts-list-item"><a href="http://asgamer.com/2009/making-a-complete-flash-game-creating-understanding-the-preloader" title="Making a Complete Flash Game: Creating &#038; Understanding the Preloader">Making a Complete Flash Game: Creating &#038; Understanding the Preloader</a></li>
<li class="serial-posts-list-item current-inactive">Making a Complete Flash Game: Prerolling Sponsor Ads and Your Logo</li>
<li class="serial-posts-list-item"><a href="http://asgamer.com/2009/making-a-complete-flash-game-menus-ui-screens-or-windows" title="Making a Complete Flash Game: Menus, UI, Screens, or Windows">Making a Complete Flash Game: Menus, UI, Screens, or Windows</a></li>
</ul>
</div>
<h3>Step 1: Why our Preloader has a PhaseOut Function that we need to use</h3>
<p>If you are following along from the previous tutorial you should remember that our ThePreloader class has a function called phaseOut that we run when our file is completely preloaded.  Also if you remember from the previous tutorial, we can&#8217;t use any of our game&#8217;s assets until our main timeline reaches frame 3.  Well if our phaseOut function immediately calls phaseComplete and jumps to loading our sponsors preroll then we are in trouble. Why? because our sponsors preroll hasn&#8217;t loaded yet since we are still on frame one. So just open your ThePreloader.as file and inside our phaseOut function add:</p>
<div class="wp_syntax">
<div class="code">
<pre class="actionscript3" style="font-family:monospace;">Tweener<span style="color: #000066; font-weight: bold;">.</span>addTween<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000;">&#123;</span> <span style="color: #004993;">time</span><span style="color: #000066; font-weight: bold;">:</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">alpha</span><span style="color: #000066; font-weight: bold;">:</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> onComplete<span style="color: #000066; font-weight: bold;">:</span>phaseComplete <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre>
</div>
</div>
<p>Alright, of course you will need to import Tweener and add it to your directory so flash can use it. But now it will take one second for our Preloader to fade out(plenty enough time for us to reach frame 3), then we can start loading our sponsors.</p>
<h3>Step 2: Organize your Preroll MovieClips</h3>
<p>Okay, First let me state the obvious, we are using Flash. Flash is great 2D animation software. Therefore most of your sponsors will probably do their animated logo as a MovieClip. So we are going to assume that all your sponsors will use MovieClips for their logo. Don&#8217;t worry, if they use a video file you can import it and tell Flash to embed it in a MovieClip. And if they just send you a JPG you can throw it in a MovieClip to solve that problem as well.</p>
<p>So here&#8217;s what you need to do. Download my FLA for this project. I have two MovieClips ready to be used. I&#8217;ll discuss how they are setup once you look at them.</p>
<p>Here&#8217;s the FLA: <a href="http://asgamer.com/wp-content/uploads/2009/04/completegame.fla">CompleteGame.fla</a></p>
<p>If you want to keep using your FLA from the previous project, just copy and paste Sponsors Preroll folder from my FLA file into your FLA file.</p>
<p>You&#8217;ll notice there are two MovieClips prefixed with Preroll under the Sponsors Preroll folder.  Doubleclick PrerollEchodrop, you&#8217;ll notice the timeline is 130 frames long.  In those frames we animate in a still rastor image of the Echodrop logo then we fade it back out. At the end, on the very last frame, we write in the actions:</p>
<div class="wp_syntax">
<div class="code">
<pre class="actionscript3" style="font-family:monospace;"><span style="color: #004993;">gotoAndStop</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Event</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;finished&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre>
</div>
</div>
<p>So when our Preroll is finished, we dispatch &#8220;finished&#8221;. All we have to do is listen for &#8220;finished&#8221; in our class and we will know the animation is over.</p>
<p>One more thing, right click on PrerollEchodrop in the Library and goto Linkage&#8230;  Your&#8217;ll notice the class is PrerollEchodrop and the Linkage&#8230; has &#8220;Export for ActionScript&#8221; but not &#8220;Export on First Frame&#8221;. So we need to make sure our PrerollEchodrop Symbol is in the AssetHolder MovieClip in order for it to export. (If you are using my FLA, it will already be in the AssetHolder MovieClip).  You&#8217;ll want to do the same with the PrerollGameSponsor and any other Preroll clips you use.</p>
<h3>Step 3: Let&#8217;s Code our Preroll Sponsors Manager Class</h3>
<p>Okay, this is actually a very simple class. Here&#8217;s what we need. A class that will create our preroll clip, animate through it, call the next clip, animate through it, and so on until all our prerolls are finished.  We&#8217;ll call our classPrerollSponsors. So make the as file and let&#8217;s write the code. It&#8217;s super simple, here it is.</p>
<div class="wp_syntax">
<div class="code">
<pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>asgamer<span style="color: #000066; font-weight: bold;">.</span>snipergame
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MovieClip</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Stage</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> PrerollSponsors <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Sprite</span>
	<span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> stageRef<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Stage</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> prerollList<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//keeps up with our Movieclip prerolls</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> currentPreroll<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//the current preroll we are on</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> PrerollSponsors<span style="color: #000000;">&#40;</span>stageRef<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Stage</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>stageRef = stageRef<span style="color: #000066; font-weight: bold;">;</span>
			prerollList = <span style="color: #000000;">&#91;</span><span style="color: #0033ff; font-weight: bold;">new</span> PrerollEchoDrop<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">new</span> PrerollGameSponsor<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> preroll<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>currentPreroll == prerollList<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000000;">&#41;</span>
				<span style="color: #0033ff; font-weight: bold;">return</span> prerollComplete<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #6699cc; font-weight: bold;">var</span> clip<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MovieClip</span> = prerollList<span style="color: #000000;">&#91;</span>currentPreroll<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
			clip<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #000000;">&#40;</span>stageRef<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageWidth</span> <span style="color: #000066; font-weight: bold;">-</span> clip<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span>
			clip<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000;">&#40;</span>stageRef<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageHeight</span> <span style="color: #000066; font-weight: bold;">-</span> clip<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span>
			clip<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">gotoAndPlay</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			clip<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;finished&quot;</span><span style="color: #000066; font-weight: bold;">,</span> nextPreroll<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			stageRef<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>clip<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> nextPreroll<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">currentTarget</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;finished&quot;</span><span style="color: #000066; font-weight: bold;">,</span> nextPreroll<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			stageRef<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeChild</span><span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">currentTarget</span> <span style="color: #0033ff; font-weight: bold;">as</span> <span style="color: #004993;">MovieClip</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			currentPreroll<span style="color: #000066; font-weight: bold;">++;</span>
			preroll<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> prerollComplete<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Event</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;prerollComplete&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre>
</div>
</div>
<p>Okay, let me break this down:</p>
<ul>
<li>imports, extends, stageRef. You should know what all this is (stageRef is just a stage reference holder). If not you should be reading <a title="AS3 Flash Games for Beginners" href="http://asgamer.com/2009/flash-game-design-basics-adding-library-objects-to-stage-with-as3">AS3 Flash Games for Beginners </a></li>
<li><strong>prerollList = [new PrerollEchoDrop(), new PrerollGameSponsor()]; </strong>Here we create instances of our two preroll classes and drop them in our prerollList array.</li>
<li><strong>public function preroll() : void. </strong>The function we call every time we want to start the next video in the list.</li>
<li><strong>if (currentPreroll == prerollList.length). </strong>So in the case of this example, currentPreroll should be 0 on the first run and prerollList.length should be 2. So if currentPreroll equals 2 then this will evaluate TRUE.</li>
<li><strong>return prerollComplete(); </strong>If the above evaluates true then we run this line.  Here we are telling flash to return the result of prerollComplete. If you look at prerollComplete quickly you&#8217;ll see it only returns void so we are actually returning nothing. But we will dispatch our event in prerollComplete which is all we want to do anyway. We could have wrote this in two lines: prerollComplete(); followed by return; But it&#8217;s just simpler this way.</li>
<li><strong>var clip:MovieClip = prerollList[currentPreroll]; </strong>Just grabbing the current preroll and dropping it in the variable clip. This way we don&#8217;t have to write prerollList[currentPreroll] every time we want to access it.</li>
<li><strong>clip.x = (stageRef.stageWidth &#8211; clip.width) / 2; clip.y = (stageRef.stageHeight &#8211; clip.height) / 2; </strong>This will center our MovieClip, no matter it&#8217;s size, in the middle of the stage. One thing is required for this to work. The movieClip&#8217;s registration point MUST BE in the top left corner of the movieClip.</li>
<li><strong>clip.gotoAndPlay(1); </strong>Simply reset and play our movieClip.</li>
<li><strong>clip.addEventListener(&#8220;finished&#8221;, nextPreroll); </strong>Remember we dispatch the event &#8220;finished&#8221; at the end of our preroll MovieClip. Well we catch it here and call nextPreroll when it occurs.</li>
<li><strong>stageRef.addChild(clip); </strong>uhm we add it to stage. Don&#8217;t even know why I am explaining this.</li>
<li><strong>e.currentTarget.removeEventListener(&#8220;finished&#8221;, nextPreroll); </strong>Alright nothing complicated. e.currentTarget will let us grab whatever dispatched the event. In our case, it was our preroll MovieClip. So we remove the event listener because we are finished with it.</li>
<li><strong>stageRef.removeChild(e.currentTarget as MovieClip); </strong>Remove the currentTarget.  as MovieClip let&#8217;s Flash know that the currentTarget is a MovieClip so it doesn&#8217;t give us a hideous error, <span style="color: #ff0000;">1118: Implicit coercion of a value with static type Object to a possibly unrelated type flash.display:DisplayObject.</span>, when we compile.</li>
<li><strong>currentPreroll++</strong> increment the currentPreroll by 1</li>
<li><strong>preroll();</strong> since currentPreroll is now 1 greater let&#8217;s run preroll again and show the next preroll advertisement or sponsor.</li>
<li><strong>dispatchEvent(new Event(&#8220;prerollComplete&#8221;)); </strong>We&#8217;re done! Dispatch &#8220;prerollComplete&#8221;. Now we just need to make something catch it.</li>
</ul>
<p>Alright, so what&#8217;s going to catch the prerollComplete? The same thing that is going to create an instance of our PrerollSponsor class, the Engine.</p>
<h3>Step 4: Using our PrerollSponsor Class</h3>
<p>Okay. Open your Engine class. Inside the showSponsors class change it to be this:</p>
<div class="wp_syntax">
<div class="code">
<pre class="actionscript3" style="font-family:monospace;">			<span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeChild</span><span style="color: #000000;">&#40;</span>preloader<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> ps<span style="color: #000066; font-weight: bold;">:</span>PrerollSponsors = <span style="color: #0033ff; font-weight: bold;">new</span> PrerollSponsors<span style="color: #000000;">&#40;</span><span style="color: #004993;">stage</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			ps<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;prerollComplete&quot;</span><span style="color: #000066; font-weight: bold;">,</span> showMenu<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			ps<span style="color: #000066; font-weight: bold;">.</span>preroll<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre>
</div>
</div>
<p>Nice, I really shouldn&#8217;t need to break this down but I will.</p>
<ul>
<li>first we remove the preloader. (Which was already in our class from last time)</li>
<li>we create a new instance of PrerollSponsors passing stage into it as a parameter</li>
<li>we add an Event Listener that waits for prerollComplete to be called, once called we goto the showMenu function.</li>
<li>Then we kick off the PrerollSponsors class by calling the function ps.preroll();</li>
</ul>
<p>Last you just need to create a private showMenu function that receives an event. It doesn&#8217;t need to do anything but needs to exist so flash doesn&#8217;t crash.  Anyway, here&#8217;s our new Engine class with these new updates.</p>
<div class="wp_syntax">
<div class="code">
<pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>asgamer<span style="color: #000066; font-weight: bold;">.</span>snipergame
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MovieClip</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Engine <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">MovieClip</span>
	<span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> preloader<span style="color: #000066; font-weight: bold;">:</span>ThePreloader<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Engine<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			preloader = <span style="color: #0033ff; font-weight: bold;">new</span> ThePreloader<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">474</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">loaderInfo</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>preloader<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			preloader<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;loadComplete&quot;</span><span style="color: #000066; font-weight: bold;">,</span> loadAssets<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			preloader<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;preloaderFinished&quot;</span><span style="color: #000066; font-weight: bold;">,</span> showSponsors<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> loadAssets<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">play</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> showSponsors<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeChild</span><span style="color: #000000;">&#40;</span>preloader<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> ps<span style="color: #000066; font-weight: bold;">:</span>PrerollSponsors = <span style="color: #0033ff; font-weight: bold;">new</span> PrerollSponsors<span style="color: #000000;">&#40;</span><span style="color: #004993;">stage</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			ps<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;prerollComplete&quot;</span><span style="color: #000066; font-weight: bold;">,</span> showMenu<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			ps<span style="color: #000066; font-weight: bold;">.</span>preroll<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> showMenu<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;showMenu&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre>
</div>
</div>
<p>Alright. We&#8217;ve completed the second part of Making a Complete Flash Game.</p>
<p>Here&#8217;s our finished source:<br />
<a href="http://asgamer.com/wp-content/uploads/2009/04/completegameseries-2-preroll.zip">Prerolling Sponsor Ads and Your Logo Source Code Zip Archive</a><br />
				<!-- Social Sharing Toolkit v2.0.4 | http://www.marijnrongen.com/wordpress-plugins/social_sharing_toolkit/ --></p>
<div class="mr_social_sharing_wrapper"><span class="mr_social_sharing"><a href="http://twitter.com/share?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-prerolling-sponsor-ads-and-your-logo&amp;text=Making+a+Complete+Flash+Game%3A+Prerolling+Sponsor+Ads+and+Your+Logo&amp;via=jon_par" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/twitter.png" alt="Share on Twitter" title="Share on Twitter"/></a></span><span class="mr_social_sharing"><g:plusone size="medium" count="false" href="http://asgamer.com/2009/making-a-complete-flash-game-prerolling-sponsor-ads-and-your-logo"></g:plusone></span><span class="mr_social_sharing"><a href="http://www.tumblr.com/share/link?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-prerolling-sponsor-ads-and-your-logo&amp;name=Making+a+Complete+Flash+Game%3A+Prerolling+Sponsor+Ads+and+Your+Logo" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/tumblr.png" alt="Share on Tumblr" title="Share on Tumblr"/></a></span><span class="mr_social_sharing"><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-prerolling-sponsor-ads-and-your-logo&amp;title=Making+a+Complete+Flash+Game%3A+Prerolling+Sponsor+Ads+and+Your+Logo" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/stumbleupon.png" alt="Submit to StumbleUpon" title="Submit to StumbleUpon"/></a></span><span class="mr_social_sharing"><a href="http://del.icio.us/post?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-prerolling-sponsor-ads-and-your-logo&amp;title=Making+a+Complete+Flash+Game%3A+Prerolling+Sponsor+Ads+and+Your+Logo" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/delicious.png" alt="Save on Delicious" title="Save on Delicious"/></a></span><span class="mr_social_sharing"><a href="http://digg.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-prerolling-sponsor-ads-and-your-logo&amp;title=Making+a+Complete+Flash+Game%3A+Prerolling+Sponsor+Ads+and+Your+Logo" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/digg.png" alt="Digg This" title="Digg This"/></a></span><span class="mr_social_sharing"><a href="http://www.reddit.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-prerolling-sponsor-ads-and-your-logo" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/reddit.png" alt="Submit to reddit" title="Submit to reddit"/></a></span><span class="mr_social_sharing"><iframe src="https://www.facebook.com/plugins/like.php?locale=en_US&amp;href=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-prerolling-sponsor-ads-and-your-logo&amp;layout=standard&amp;show_faces=false&amp;width=51px&amp;height=24px" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:51px; height:24px;" allowTransparency="true"></iframe></span></div>
]]></content:encoded>
			<wfw:commentRss>http://asgamer.com/2009/making-a-complete-flash-game-prerolling-sponsor-ads-and-your-logo/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Making a Complete Flash Game: Creating &amp; Understanding the Preloader</title>
		<link>http://asgamer.com/2009/making-a-complete-flash-game-creating-understanding-the-preloader</link>
		<comments>http://asgamer.com/2009/making-a-complete-flash-game-creating-understanding-the-preloader#comments</comments>
		<pubDate>Tue, 07 Apr 2009 14:41:35 +0000</pubDate>
		<dc:creator>Par</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[Game Development]]></category>
		<category><![CDATA[gamedev]]></category>
		<category><![CDATA[preloader]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://asgamer.com/?p=384</guid>
		<description><![CDATA[We're going to talk about the first thing you see in every good flash game you've played, the preloader.  Without the preloader your audience will likely leave your game after staring at a blank screen for too long. So the feedback given from a preloader that tells the user, "Hey, the game is loading. Be cool wait a second and we'll be ready to go" is vital. And since this is the largest single page tutorial on As Gamer to date, you'll definitely get the information you need.]]></description>
			<content:encoded><![CDATA[<p>				<!-- Social Sharing Toolkit v2.0.4 | http://www.marijnrongen.com/wordpress-plugins/social_sharing_toolkit/ --></p>
<div class="mr_social_sharing_wrapper"><span class="mr_social_sharing"><a href="http://twitter.com/share?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-creating-understanding-the-preloader&amp;text=Making+a+Complete+Flash+Game%3A+Creating+%26+Understanding+the+Preloader&amp;via=jon_par" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/twitter.png" alt="Share on Twitter" title="Share on Twitter"/></a></span><span class="mr_social_sharing"><g:plusone size="medium" count="false" href="http://asgamer.com/2009/making-a-complete-flash-game-creating-understanding-the-preloader"></g:plusone></span><span class="mr_social_sharing"><a href="http://www.tumblr.com/share/link?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-creating-understanding-the-preloader&amp;name=Making+a+Complete+Flash+Game%3A+Creating+%26+Understanding+the+Preloader" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/tumblr.png" alt="Share on Tumblr" title="Share on Tumblr"/></a></span><span class="mr_social_sharing"><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-creating-understanding-the-preloader&amp;title=Making+a+Complete+Flash+Game%3A+Creating+%26+Understanding+the+Preloader" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/stumbleupon.png" alt="Submit to StumbleUpon" title="Submit to StumbleUpon"/></a></span><span class="mr_social_sharing"><a href="http://del.icio.us/post?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-creating-understanding-the-preloader&amp;title=Making+a+Complete+Flash+Game%3A+Creating+%26+Understanding+the+Preloader" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/delicious.png" alt="Save on Delicious" title="Save on Delicious"/></a></span><span class="mr_social_sharing"><a href="http://digg.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-creating-understanding-the-preloader&amp;title=Making+a+Complete+Flash+Game%3A+Creating+%26+Understanding+the+Preloader" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/digg.png" alt="Digg This" title="Digg This"/></a></span><span class="mr_social_sharing"><a href="http://www.reddit.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-creating-understanding-the-preloader" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/reddit.png" alt="Submit to reddit" title="Submit to reddit"/></a></span><span class="mr_social_sharing"><iframe src="https://www.facebook.com/plugins/like.php?locale=en_US&amp;href=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-creating-understanding-the-preloader&amp;layout=standard&amp;show_faces=false&amp;width=51px&amp;height=24px" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:51px; height:24px;" allowTransparency="true"></iframe></span></div>
<p>Kicking off the series, we&#8217;re going to talk about the first thing you see in every good flash game you&#8217;ve played, the preloader.  Without the preloader your audience will likely leave your game after staring at a blank screen for too long. So the feedback given from a preloader that tells the player, &#8220;Hey, the game is loading. Be cool wait a second and we&#8217;ll be ready to go&#8221; is vital.  Now what type of preloader you make is your business&#8230; but make sure it gives the user feedback so they know the game is loading and not sitting in limbo.</p>
<p><span style="color: #0000ff;">As a note, this Preloader tutorial can be used for <strong>ANY FLASH APPLICATION </strong>so even if you&#8217;re not making a game this can be very useful.</span></p>
<div id="serial-posts-wrapper">
<h3 class="serial-posts-heading"><span class="serial-pre-text">You are reading</span>&nbsp;<span class="serial-name">Making a Complete Flash Game</span>&nbsp;<span class="serial-post-text">Read more from this series of articles.</span></h3>
<ul class="serial-posts">
<li class="serial-posts-list-item current-inactive">Making a Complete Flash Game: Creating &#038; Understanding the Preloader</li>
<li class="serial-posts-list-item"><a href="http://asgamer.com/2009/making-a-complete-flash-game-prerolling-sponsor-ads-and-your-logo" title="Making a Complete Flash Game: Prerolling Sponsor Ads and Your Logo">Making a Complete Flash Game: Prerolling Sponsor Ads and Your Logo</a></li>
<li class="serial-posts-list-item"><a href="http://asgamer.com/2009/making-a-complete-flash-game-menus-ui-screens-or-windows" title="Making a Complete Flash Game: Menus, UI, Screens, or Windows">Making a Complete Flash Game: Menus, UI, Screens, or Windows</a></li>
</ul>
</div>
<h3>Step 1: Understanding the Problem with Single File Preloaders</h3>
<p>Preloaders are not a difficult concept. Seriously, you need to keep up with how much data is loaded and how much data we have to load.  Seems like this whole idea of making a preloader should be cut and dry.  But&#8230; it&#8217;s not. We have things we need to manage in order to make our preloader work correctly.</p>
<p>Why? Well our goal with this game as mentioned in the last section is to make a game that is single file and that&#8217;s our problem.  If we had two files&#8230; a swf that does the loading and our game then we could just write the preloader code and be done with it. But all the flash portals that I know want you to submit a one file game and there lies our issue.</p>
<p>So, tired of hearing that a one file preloader is a problem and want to know why it&#8217;s a problem? Okay let me explain.</p>
<p>Our first issue deals with our classes linkage setup. Remember this screen?</p>
<p><img class="alignnone" title="Display of Linkage Setup" src="http://asgamer.com/wp-content/uploads/2009/02/basics1_step3-2.jpg" alt="" width="464" height="245" /></p>
<p><strong><span style="color: #ff0000;">DISCLAIMER:</span></strong><br />
<span style="color: #800000;">If you don&#8217;t know what this is&#8230; well the concept is going to be way over your head. You need to read <a title="AS3 Flash Games for Beginners" href="http://asgamer.com/2009/flash-game-design-basics-adding-library-objects-to-stage-with-as3" target="_blank">AS3 Flash Games for Beginners</a> to get familar with AS3.  This is not a series on familiarizing yourself with Flash, As Gamer has other tutorials to help you with that.</span></p>
<p>See the third checkbox, &#8220;Export in first frame&#8221;, that&#8217;s our problem. If that&#8217;s checked then this class will have to load before anything else in our Flash project will.  So if all our MovieClip&#8217;s are set to export in first frame then by the time our preloader starts working our game will already be mostly loaded. Your user will have saw that dreaded blank screen for the majority of your game&#8217;s loading time.  So the solution may seem simple right&#8230; uncheck &#8220;Export in first frame&#8221; and problem solved? Sadly, it&#8217;s not that easy.</p>
<p>Here&#8217;s the new problem. If we don&#8217;t export our class in the first frame then we don&#8217;t export our class. Which means our class never gets exported and we can never call it from the library and use it.  The conundrum is getting pretty obvious now huh? We either have a preloader that has to wait on everything else to load before it starts working (which defeats the purpose) or we stop everything from loading at the beginning and have to figure out another way to export them.</p>
<p>But there is a solution and this tutorial will explain it. That said, I don&#8217;t take credit for it. I first saw the solution for setting up a single file preloader at 8bitrocket.  These guys are geniuses and write some brillant tutorials on flash game development. Click <a title="8BitRocket" href="http://8bitrocket.com/newsdisplay.aspx?newspage=10807" target="_blank">here</a> to read the tutorial that I used to build a flash preloader in as3.</p>
<p>Now, if you wish to follow along on As Gamer to setup the preloader feel free to continue reading as I will discuss the same method I learned from 8bitrocket.  My style of explanation is quite a bit different from theirs so whichever helps you the most, use it <img src='http://asgamer.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  Plus I&#8217;m going to discuss a few more elements that they did not and it&#8217;s much easier to discuss the concept as a whole than in part.</p>
<h3>Step 2: Making Our Preloader</h3>
<p>This is the first game that I will have made the preloader at the beginning of the project. It seems odd because really&#8230; what are we loading? At the moment nothing.  But at least once we&#8217;ve completed this tutorial we&#8217;ll know what to watch out for when developing our game and that it will have a working preloader when it&#8217;s finished.</p>
<p>So AsGamer recently released a <a href="http://asgamer.com/2009/using-9-slice-scaling-to-retain-shape-while-resizing">tutorial on 9-Slice Scaling</a>, if you don&#8217;t know what it is then you are going to need to read the tutorial because we&#8217;re about to use it. It&#8217;s a simple tutorial but it&#8217;s important for our preloader that we are about to make.</p>
<p>Alright so open Flash, create a new AS3 Document, set the FPS to 30, and the Dimensions to 550&#215;400.  Good, now we need to build our Preloader screen. Let&#8217;s not do anything too complicated. Grab your Rectangle Tool <strong><span style="color: #ff6600;">(R)</span></strong> and draw a dark gray box on the stage sized at 550&#215;400. You can resize the box after you draw it in the Properties Window <strong><span style="color: #ff6600;">(CTRL+F3)</span></strong>. Now right click your gray box and select &#8220;Convert to Symbol&#8230;&#8221;. Make sure the Registration is in the top left, the Type is MovieClip, and the name is Preloader. Now you can delete in the Preloader MovieClip from the stage and select it from the Library to continue editing it.</p>
<p>Using the Rectangle Tool again draw a curved rectangle with curve size of 20 in a slightly lighter gray at a size of approximately 500&#215;50. Then write &#8220;GAME IS LOADING&#8221; above it. Feel free to use some creativity with all this if you want. My Preloader currently looks like this.</p>
<div id="attachment_396" class="wp-caption alignnone" style="width: 558px"><img class="size-full wp-image-396" title="cg-1-1" src="http://asgamer.com/wp-content/uploads/2009/04/cg-1-1.jpg" alt="Example of Preloader setup." width="548" height="394" />
<p class="wp-caption-text">Example of Preloader setup.</p>
</div>
<p>Now it&#8217;s time to use our 9-Slice Scaling knowledge. Create a new MovieClip <span style="color: #ff6600;"><strong>(CTRL+F8)</strong></span> and make sure you enable 9-Slice Scaling.</p>
<div id="attachment_387" class="wp-caption alignnone" style="width: 426px"><img class="size-full wp-image-387" title="s9-1" src="http://asgamer.com/wp-content/uploads/2009/04/s9-1.jpg" alt="Simply create a MovieClip and make sure you enable 9-slice scaling." width="416" height="518" />
<p class="wp-caption-text">Simply create a MovieClip and make sure you enable 9-slice scaling.</p>
</div>
<p>Name it PreloaderBar. Now here&#8217;s where you need to be careful. We need the registration point to be at the left of our preloader bar. So draw a square (Hold SHIFT and draw to constrain to a square) in a light gray color. Set its x and y to 0. Now your grid will be out of alignment so line it back up. If you want add another white rectangle on top of our gray square to make a highlight.  It could look something like this.</p>
<div id="attachment_397" class="wp-caption alignnone" style="width: 558px"><img class="size-full wp-image-397" title="cg-1-2" src="http://asgamer.com/wp-content/uploads/2009/04/cg-1-2.jpg" alt="400x magnification of the preloader bar" width="548" height="394" />
<p class="wp-caption-text">400x magnification of the preloader bar</p>
</div>
<p>Now drop this new MovieClip into your Preloader MovieClip and stretch it out so that it fills your loading bar.  It should look something like this.</p>
<div id="attachment_398" class="wp-caption alignnone" style="width: 556px"><img class="size-full wp-image-398" title="cg-1-3" src="http://asgamer.com/wp-content/uploads/2009/04/cg-1-3.jpg" alt="Our Preloader Bar using 9-Slice Scaling ready to be programmed." width="546" height="397" />
<p class="wp-caption-text">Our Preloader Bar using 9-Slice Scaling ready to be programmed.</p>
</div>
<p>Alright. One more thing left in the setup. Select your Preloader Bar and set its instance name as mcPreloaderBar (We&#8217;ll throw mc in front of all our non-coded nested MovieClips for clarity). Okay, and while you are at it&#8230; write down the width of your mcPreloaderBar, we&#8217;ll come back to it and use it later. Mine&#8217;s 474 but yours is likely different, which is completely fine.</p>
<p>Time for code.</p>
<h3>Step 3: Writing Our Preloader Class</h3>
<p>So I don&#8217;t want to write a Preloader class every time I make a game.  Why not write one Preloader class that we can use on any project as long as we maintain the same structure.</p>
<p>Okay so the first thing we need to do is create our Preloader.as file. Our package for this game is going to be &#8220;com.asgamer.snipergame&#8221; because I have no idea exactly what we want to call this game yet. So in the directory you saved your FLA file just create a com folder, inside it an asgamer folder, and inside it a snipergame folder.  Your structure is now setup, save your Preloader.as in the snipergame folder.  If you don&#8217;t understand why we set it up this way, go read the <a title="AS3 Flash Games for Beginners" href="http://asgamer.com/2009/flash-game-design-basics-adding-library-objects-to-stage-with-as3" target="_blank">AS3 Flash Games for Beginners</a> series.</p>
<p>Now let&#8217;s write some code in this Preloader.as file. Don&#8217;t freak out, I&#8217;m going to post all the code but it will be fine&#8230;  I&#8217;ll explain all of it afterwards.</p>
<div class="wp_syntax">
<div class="code">
<pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>asgamer<span style="color: #000066; font-weight: bold;">.</span>snipergame
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">LoaderInfo</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MovieClip</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.*;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> ThePreloader <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">MovieClip</span>
	<span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> fullWidth<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//the width of our mcPreloaderBar at 100%</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> ldrInfo<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">LoaderInfo</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> ThePreloader<span style="color: #000000;">&#40;</span>fullWidth<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> ldrInfo<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">LoaderInfo</span> = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>fullWidth = fullWidth<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>ldrInfo = ldrInfo<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span> checkLoad<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> checkLoad <span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>ldrInfo<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bytesLoaded</span> == ldrInfo<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bytesTotal</span> <span style="color: #000066; font-weight: bold;">&amp;</span>amp<span style="color: #000066; font-weight: bold;">;&amp;</span>amp<span style="color: #000066; font-weight: bold;">;</span> ldrInfo<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bytesTotal</span> <span style="color: #000066; font-weight: bold;">!</span>= <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #009900; font-style: italic;">//loading complete</span>
				<span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Event</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;loadComplete&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				phaseOut<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
&nbsp;
			updateLoader<span style="color: #000000;">&#40;</span>ldrInfo<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bytesLoaded</span> <span style="color: #000066; font-weight: bold;">/</span> ldrInfo<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bytesTotal</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> updateLoader<span style="color: #000000;">&#40;</span>num<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #009900; font-style: italic;">//num is a number between 0 and 1</span>
			mcPreloaderBar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span> = num <span style="color: #000066; font-weight: bold;">*</span> fullWidth<span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> phaseOut<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span> checkLoad<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			phaseComplete<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> phaseComplete<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Event</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;preloaderFinished&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre>
</div>
</div>
<p>Geez&#8230; yeah that&#8217;s a lot. Like I said don&#8217;t freak out. It&#8217;s actually very simple.</p>
<ul>
<li>Okay you know what imports are so skip those.</li>
<li>You know what the class is and the whole extends MovieClip stuff.</li>
<li>If you don&#8217;t know what those are then go read <a title="AS3 Flash Games for Beginners" href="http://asgamer.com/2009/flash-game-design-basics-adding-library-objects-to-stage-with-as3" target="_blank">AS3 Flash Games for Beginners</a> before you write me nasty letters.</li>
<li><strong>private var fullWidth:Number</strong> alright. Remember when we wrote down what our mcPreloaderBar&#8217;s width was. Well this variable will end up holding it. This way we know what our Preloader Bar should look like when the loading is at 100%.</li>
<li><strong>public var ldrInfo:LoaderInfo; </strong>we&#8217;ll get this guy passed into us from the Engine class like fullWidth. Our Engine class will already have a loaderInfo that keeps up with how big our file is and how much of it is loaded. We will just pass that loaderInfo into our preloader and set it as ldrInfo and use it.</li>
<li><strong>addEventListener(Event.ENTER_FRAME, checkLoad); </strong>When we enter the frame&#8230; we run the checkLoad function. Simple.</li>
<li><strong>if (ldrInfo.bytesLoaded == ldrInfo.bytesTotal &amp;&amp; ldrInfo.bytesTotal != 0)</strong>.<strong> </strong>Our buddy ldrInfo has two variables we want to make use of, bytesLoaded and bytesTotal. It&#8217;s pretty obvious but bytesLoaded tells us how much data is loaded while bytesTotal tells us the filesize of our project. So we check to see if the bytesLoaded is as much as the bytesTotal which if true means the swf is loaded. We also make sure bytesTotal doesn&#8217;t equal 0. Because if it does either the ldrInfo hasn&#8217;t kicked in yet or we got a problem. Either way, we don&#8217;t want to run our game if bytesTotal == 0.</li>
<li>if it does return true we call phaseOut and dispatch our loadComplete event.</li>
<li><strong>updateLoader(ldrInfo.bytesLoaded / ldrInfo.bytesTotal); </strong>We pass into updateLoader a value between 0 and 1. As long as we can&#8217;t load more bytes than the total number of bytes then this will always be between 0 and 1. And don&#8217;t worry unless something I&#8217;ve never seen before happens, between 0 and 1 it will always be.</li>
<li><strong>mcPreloaderBar.width = num * fullWidth; </strong>Here&#8217;s why we need a number between 0 and 1. If we get a 0 then our mcPreloaderBar has a width of 0. If we get a 1 then it has a width equal to fullWidth. Makes for a great preloader bar.</li>
<li><strong>private function phaseOut() </strong>Okay so right now&#8230; this function is doing next to nothing. it removes checkLoad event listener and calls phaseComplete. But let&#8217;s assume you want to use <a title="Using Tweener" href="http://asgamer.com/2009/using-tweener-in-as3-to-move-objects">Tweener</a> and animate out your preloader. Well you&#8217;ll do that right here in this function. Then when everything is complete just call phaseComplete to remove your preloader for good.</li>
<li><strong>private function phaseComplete(). </strong>Alright, all we do here is dispatch a &#8220;preloaderFinished&#8221; event. If you set up listeners in the Engine class to catch these events then we can jump to the next phase when the preloader finishes. You&#8217;ll see what I mean when we create our Engine class in just a second.</li>
</ul>
<p>Okay so that&#8217;s our preloader class. How are we going to use it?</p>
<h3>Step 4: Using our Preloader and Exporting Our Classes for ActionScript</h3>
<p>If you remember&#8230; earlier in this tutorial I said we need to remove the &#8220;Export in first frame&#8221; from all our Class linked Library Symbols. Well that&#8217;s true for everything but one symbol. We need to export our preloader in the first frame. So right click your Preloader symbol in the library and &#8220;Export for Actionscript&#8221; make sure to leave &#8220;Export in first frame&#8221; checked. Then set up the class as &#8220;com.asgamer.snipergame.ThePreloader&#8221; without the quotes. Now OK it. the reason we export our Preloader is because we want it to export immediately when the swf starts loading. That way it will show up first.</p>
<p>Now our other &#8220;Export for ActionScript&#8221; Library symbols with classes attached to them need to get exported somehow. We&#8217;re not exporting them on the first frame so how will we export them? Well the idea, as presented at 8bitrocket, is to create a MovieClip and name it AssetHolder. In this AssetHolder MovieClip we put all our &#8220;Export for ActionScript&#8221; symbols simply by dragging them into it. Now what we are going to do with this AssetHolder MovieClip is drop it on Frame 2 of the Main Timeline. Why Frame 2? Because we want to keep frame 1 empty and stop the timeline from playing. Then when everything is loaded, we can play through frame 2 which will have all our &#8220;Export for ActionScript&#8221; symbols. This will result in exporting our symbols and we can now use them the same as if we had exported them on the first frame. We&#8217;ll go ahead a create a frame 3 as well and put a stop on it.</p>
<p>I know this may sound a little confusing so take a look at what my main timeline looks like.</p>
<div id="attachment_401" class="wp-caption alignnone" style="width: 268px"><img class="size-full wp-image-401" title="cg-1-4" src="http://asgamer.com/wp-content/uploads/2009/04/cg-1-4.jpg" alt="Timeline setup for our Game in order to preload our assets." width="258" height="77" />
<p class="wp-caption-text">Timeline setup for our Game in order to preload our assets.</p>
</div>
<p>Okay so let me quickly explain this once more for clarity.  In the actions layer frame 1 and frame 3 have stop(); wrote in their Actions window <span style="color: #ff6600;"><strong>(F9)</strong></span>. In the AssetHolder layer on frame 2 only we put our AssetHolder MovieClip. This setup will allow us to load everything up with our main timeline not leaving frame one. Then once everything is loaded we will call play() and run to frame 3 and stop again. When Flash runs through frame 2 our assets are ready to be used in ActionScript 3.</p>
<p>Okay&#8230; so now we need to setup our Engine Document Class.  If you don&#8217;t know what a Document class is, guess what, <a title="AS3 Flash Games for Beginners" href="http://asgamer.com/2009/flash-game-design-basics-adding-library-objects-to-stage-with-as3" target="_blank">AS3 Flash Games for Beginners</a> will teach you what a Document Class is. So goto your Properties Window <strong><span style="color: #ff6600;">(CTRL+F3)</span></strong> and set your document class to &#8220;com.asgamer.snipergame.Engine&#8221;.</p>
<p>Alright time to write our Engine class. We don&#8217;t need it to do much yet, just manage our Preloader. So this will be a quick and easy class to write. Like before I&#8217;m going to show you the code then explain it afterwards.</p>
<p>Engine.as</p>
<div class="wp_syntax">
<div class="code">
<pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>asgamer<span style="color: #000066; font-weight: bold;">.</span>snipergame
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MovieClip</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Engine <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">MovieClip</span>
	<span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> preloader<span style="color: #000066; font-weight: bold;">:</span>ThePreloader<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Engine<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			preloader = <span style="color: #0033ff; font-weight: bold;">new</span> ThePreloader<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">474</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">loaderInfo</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>preloader<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			preloader<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;loadComplete&quot;</span><span style="color: #000066; font-weight: bold;">,</span> loadAssets<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			preloader<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;preloaderFinished&quot;</span><span style="color: #000066; font-weight: bold;">,</span> showSponsors<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> loadAssets<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">play</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> showSponsors<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeChild</span><span style="color: #000000;">&#40;</span>preloader<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;show sponsors&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre>
</div>
</div>
<p>Okay. Time for the breakdown.</p>
<ul>
<li><strong>private var preloader:ThePreloader; </strong>The instance of our preloader class.</li>
<li><strong>preloader = new ThePreloader(474, this.loaderInfo); </strong>Okay, time to make a new ThePreloader. If you remember we needed to pass in two parameters. The first is the full width of our loading bar. In my case it was 474, yours is probably different so make sure you update it. Second we have to pass in the loaderInfo so we just take the loaderInfo from the document class and pass it into our preloader.</li>
<li><strong>stage.addChild(preloader);</strong> add our Preloader to the stage.</li>
<li><strong>preloader.addEventListener(&#8220;loadComplete&#8221;, loadAssets);</strong> Remember the two events we dispatched from our ThePreloader class? Well here is where we use them.  When the preload is complete we dispatched &#8220;loadComplete&#8221; so we will run the loadAssets function. Then when the phaseOut() function in ThePreloader is complete we dispatch &#8220;preloadFinished&#8221; and catch it here in Engine to run showSponsors.</li>
<li><strong>private function loadAssets(e:Event). </strong>This function is crucial. I know it doesn&#8217;t do much but it does exactly what we need it to. As we noted before, loadAssets is called when the SWF is preloaded. At this point we need to play the main timeline so we can run all the assets that have been exported for ActionScript. So our main timeline will play at frame 1, move through frame 2 and load our game assets, then stop again on a blank frame 3. At this point all our assets will be completely &#8220;Exported for Actionscript&#8221;</li>
<li><strong>private function showSponsors(e:Event). </strong>This does nothing at the moment. Well it removes our preloader but in the next tutorial we&#8217;ll discuss making it work to show our sponsors.</li>
</ul>
<h3>Step 5: Testing your Preloader by Simulating a Download</h3>
<p>Alright. Seriously by now we are all probably ready for this tutorial to end. It&#8217;s a behemoth, I know.  But we really need to test our preloader out and make sure it works. Don&#8217;t worry it&#8217;s a pretty simple and painless process.</p>
<p>To test it out we are going to need a big image. So you can hit up your Documents and find the biggest image you have or just grab this one I threw together.</p>
<div id="attachment_404" class="wp-caption alignnone" style="width: 510px"><img class="size-full wp-image-404" title="preloadme" src="http://asgamer.com/wp-content/uploads/2009/04/preloadme.jpg" alt="Just a big image with a decent filesize so we can test our preloader." width="500" height="500" />
<p class="wp-caption-text">Just a big image with a decent filesize so we can test our preloader.</p>
</div>
<p>Right Click, Save As, all that good stuff. Then just import it into your Flash Library. Now I dropped mine into my AssetHolder MovieClip.  We&#8217;ll delete it back out soon enough, we just need something with some file size so we can test our preloader. I mean if our SWF is 1 kb, then we don&#8217;t really have anything to preload.  This image will make it big enough to run a preloader test.</p>
<p>Once you have your image in there Test your Movie <strong><span style="color: #ff6600;">(CTRL+ENTER)</span></strong>. Now at first it isn&#8217;t going to work. You&#8217;ll see a white screen like nothing happened. So to test our Preloader, on our SWF file that we just rendered goto <strong>View &gt; Simulate Download</strong> or press <strong><span style="color: #ff6600;">(CTRL+ENTER)<br />
</span></strong> again. Now you should see your SWF simulate preloading.  If your SWF preloads too fast you can always adjust the simulation speed under the <strong>View &gt; Download Settings</strong> navigation.</p>
<p>Now one more thing you can do with simulating the download is watch the <strong>Bandwidth Profiler</strong>, press <span style="color: #ff6600;"><strong>(CTRL+B)</strong></span> or select it under the View tab. It looks like this:</p>
<div id="attachment_405" class="wp-caption alignnone" style="width: 561px"><img class="size-full wp-image-405" title="cg-1-5" src="http://asgamer.com/wp-content/uploads/2009/04/cg-1-5.jpg" alt="A screenshot of the Bandwidth Profiler and our Preloader in action" width="551" height="642" />
<p class="wp-caption-text">A screenshot of the Bandwidth Profiler and our Preloader in action</p>
</div>
<p>Notice the Bandwidth Profiler tells you how much of the SWF is loaded. This will help you to assess if your Preloader is working correctly. Especially if you are creating a preloader that does something different after so many percent have loaded.</p>
<p>Anyway, this pretty much covers our tutorial on the preloader for our game. I&#8217;ll bring it up time to time as we develop the game so you remember how to setup your other game assets to be preloaded correctly.</p>
<p>Here&#8217;s the final source code:<br />
<a title="Complete Game Series Preloader Zip Archive" href="http://asgamer.com/wp-content/uploads/2009/04/completegameseries-1-preloader.zip">Creating &amp; Understanding the Preloader Source Code Zip Archive</a><br />
				<!-- Social Sharing Toolkit v2.0.4 | http://www.marijnrongen.com/wordpress-plugins/social_sharing_toolkit/ --></p>
<div class="mr_social_sharing_wrapper"><span class="mr_social_sharing"><a href="http://twitter.com/share?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-creating-understanding-the-preloader&amp;text=Making+a+Complete+Flash+Game%3A+Creating+%26+Understanding+the+Preloader&amp;via=jon_par" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/twitter.png" alt="Share on Twitter" title="Share on Twitter"/></a></span><span class="mr_social_sharing"><g:plusone size="medium" count="false" href="http://asgamer.com/2009/making-a-complete-flash-game-creating-understanding-the-preloader"></g:plusone></span><span class="mr_social_sharing"><a href="http://www.tumblr.com/share/link?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-creating-understanding-the-preloader&amp;name=Making+a+Complete+Flash+Game%3A+Creating+%26+Understanding+the+Preloader" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/tumblr.png" alt="Share on Tumblr" title="Share on Tumblr"/></a></span><span class="mr_social_sharing"><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-creating-understanding-the-preloader&amp;title=Making+a+Complete+Flash+Game%3A+Creating+%26+Understanding+the+Preloader" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/stumbleupon.png" alt="Submit to StumbleUpon" title="Submit to StumbleUpon"/></a></span><span class="mr_social_sharing"><a href="http://del.icio.us/post?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-creating-understanding-the-preloader&amp;title=Making+a+Complete+Flash+Game%3A+Creating+%26+Understanding+the+Preloader" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/delicious.png" alt="Save on Delicious" title="Save on Delicious"/></a></span><span class="mr_social_sharing"><a href="http://digg.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-creating-understanding-the-preloader&amp;title=Making+a+Complete+Flash+Game%3A+Creating+%26+Understanding+the+Preloader" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/digg.png" alt="Digg This" title="Digg This"/></a></span><span class="mr_social_sharing"><a href="http://www.reddit.com/submit?url=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-creating-understanding-the-preloader" target="_blank" class="mr_social_sharing_popup_link"><img src="http://asgamer.com/wp-content/plugins/social-sharing-toolkit/images/buttons/reddit.png" alt="Submit to reddit" title="Submit to reddit"/></a></span><span class="mr_social_sharing"><iframe src="https://www.facebook.com/plugins/like.php?locale=en_US&amp;href=http%3A%2F%2Fasgamer.com%2F2009%2Fmaking-a-complete-flash-game-creating-understanding-the-preloader&amp;layout=standard&amp;show_faces=false&amp;width=51px&amp;height=24px" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:51px; height:24px;" allowTransparency="true"></iframe></span></div>
]]></content:encoded>
			<wfw:commentRss>http://asgamer.com/2009/making-a-complete-flash-game-creating-understanding-the-preloader/feed</wfw:commentRss>
		<slash:comments>37</slash:comments>
		</item>
	</channel>
</rss>
