<?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>ClickPopMedia &#187; Tutorials</title>
	<atom:link href="http://www.clickpopmedia.com/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.clickpopmedia.com</link>
	<description>ClickPopMedia is a great little design and illustration firm.</description>
	<lastBuildDate>Thu, 03 Dec 2009 17:28:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Password information storage and security</title>
		<link>http://www.clickpopmedia.com/2009/03/26/password-information-storage-and-security/</link>
		<comments>http://www.clickpopmedia.com/2009/03/26/password-information-storage-and-security/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 06:06:11 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Sean]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[checksum]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[md5]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[passwords]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[user authentication]]></category>

		<guid isPermaLink="false">http://www.clickpopmedia.com/?p=470</guid>
		<description><![CDATA[There are several techniques used for storing passwords; some are very good, while some are downright terrible.  Without mentioning the name of the organizations (for security purposes), I am, and have been associated with 2 groups that, without a doubt in my mind, store passwords in an extremely insecure manner.  And of course, they&#8217;re not [...]]]></description>
			<content:encoded><![CDATA[<p>There are several techniques used for storing passwords; some are very good, while some are downright terrible.  Without mentioning the name of the organizations (for security purposes), I am, and have been associated with 2 groups that, without a doubt in my mind, store passwords in an extremely insecure manner.  And of course, they&#8217;re not alone.</p>
<p>It is easy to spot an organization that stores passwords either completely unencrypted or encrypted using a method that allows for decryption easily.  One method to spot this insecure behavior is the ability to &#8220;recover your password&#8221; without the need of resetting it.  If you can recover your password, then someone else can easily access it as well (with the right tools).  Another method is one to spot carefully&#8230; it&#8217;s not to fear when a company requires your password to be different from your previous X passwords, but when they also look for similarities and judge your password to be &#8220;too close&#8221;.  This may come off as being a very secure tactic, when indeed it must mean that they are storing not just one, but several old passwords in a way that would make them, once again, an easy target.</p>
<p>So now we know some things to spot visibly that should throw up some caution flags.  What else is there to know.  There are methods of storing passwords that are more secure.  For instance, storing a &#8220;hash&#8221; or checksum of a password using an irreversible, or one-way, algorithm is a good start.  There are several hashing methods out there, some of which are better than others, but before we continue, allow me to explain what a hash is and how it can benefit secure data storage.<span id="more-470"></span></p>
<p>Sparing you from all the techno-jargon, a &#8220;hash&#8221; or checksum is an &#8220;encrypted&#8221; form of a variable.  That&#8217;s a few quotes thrown in there, technically the term hash is misused by the Internet community as is encrypted when talking about a checksum.  Encrypted would technically make the statement that the process is reversible using some sort of key.  When in all actuality there is no key, it is a one-way cypher resulting in a fixed length string of letters and numbers that is unique to the variable data.  A common hash string (MD5) is 128-bit or 32 hexadecimal characters.  In short you have 32 characters ranging from 0-9 and A-F, 16 possible choices for each character position, giving you approximately 340,000,000,000,000,000,000,000,000,000,000,000,000 possibilities.  This doesn&#8217;t eliminate the possibility of duplicate checksums, but obviously the chances of that occurrence are highly unlikely.  The benefit of storing a data in &#8220;hash&#8221; form is that if a person gets a hold of a list of passwords, they are much easier to enter than if they get a hold of just your password hashes, but there is still a weakness.</p>
<p>Passwords are only as good as the people that make them.  Of course a developer can submit their users to a multitude of password rules, eliminating common passwords and other occurrences, but you&#8217;re still left with the possibility of 2 people having the same password.  If 2 people have the same password, they therefor have the same hash.  So how do we eliminate this?  Now it&#8217;s getting fun!</p>
<p>Eliminating possible duplicate hashes in your database is the fun part, and the part that can really help you push forward into the realm of password security.  Salting your passwords is the easiest method to eliminate this rare phenomenon. A salt is small bit of data added &#8220;somewhere&#8221; to your password string.  As I said, this is where it can be a lot of fun if you&#8217;re creative.  The salt has to be stored, and should be unique to each individual user, otherwise you still have the possibility of identical hashes with the same password.  Attaching information collected during the registration process is a good start, or even using the &#8220;id&#8221; of the user.  Or you can be creative and use multiple items or even multiple times of running it through a hashing function.  This ultimately will be up to you, but I will give you a little guidance.</p>
<p>For convenience we will keep this easy.  The salt variable will be left undetermined in this sample so that you can fill it in with whatever you like.  Feel free to play around with it.</p>
<p><strong>&lt;?php<br />
$salt=X;  //undetermined, replace X with something of your choosing.<br />
$password=$_REQUEST['password'];  //Sent from a form, or other type of post/get data set.<br />
$seasoned_password=$salt.$password; //This will joint the 2 together;<br />
$password_hash=md5($seasoned_password);  //This can now be stored in the database along with the salt.</strong><br />
?&gt;</p>
<p>Storing a salted hashed password will effectively eliminate the chances for duplicate password hashes, as long as the salt is wide enough variable.  Remember never to store your salt as it&#8217;s own field, hide it as something else.</p>
<p>I am indeed sorry if this was a little long and drawn out.  Security is not something to be taken lightly, and I hope this helps give insight in to how you can help protect your users passwords as well as the data you wish to protect.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.clickpopmedia.com/2009/03/26/password-information-storage-and-security/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Have a Heart &#8211; Illustrator Tutorial</title>
		<link>http://www.clickpopmedia.com/2009/02/26/how-to-have-a-heart-illustrator-tutorial/</link>
		<comments>http://www.clickpopmedia.com/2009/02/26/how-to-have-a-heart-illustrator-tutorial/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 18:00:01 +0000</pubDate>
		<dc:creator>VQ</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[VQ]]></category>
		<category><![CDATA[Vector]]></category>
		<category><![CDATA[illustrator]]></category>

		<guid isPermaLink="false">http://www.clickpopmedia.com/?p=472</guid>
		<description><![CDATA[
I posted a simple heart vector last week, which I actually had a fair amount of fun making. As I was making it, I noticed how many shortcuts and simple techniques make the process of vector illustration so much easier. I&#8217;ve learned a ton of great stuff from Vectips, Vectortuts, and Abduzeedo and wanted to [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-485" title="step13" src="http://www.clickpopmedia.com/wp-content/uploads/2009/02/step13.png" alt="step13" width="600" height="477" /></p>
<p>I posted a simple <a href="http://www.clickpopmedia.com/2009/02/20/have-a-heart-happy-valentines-6/">heart vector</a> last week, which I actually had a fair amount of fun making. As I was making it, I noticed how many shortcuts and simple techniques make the process of vector illustration so much easier. I&#8217;ve learned a ton of great stuff from <a href="http://vectips.com/">Vectips</a>, <a href="http://vector.tutsplus.com/">Vectortuts</a>, and <a href="http://abduzeedo.com/">Abduzeedo</a> and wanted to pass along some workflow tips of my own. Have fun.</p>
<p>Oh, I should stress (as though it&#8217;s not already obvious), I&#8217;m no anatomist.</p>
<p><span id="more-472"></span></p>
<p><img class="alignnone size-full wp-image-473" title="step01" src="http://www.clickpopmedia.com/wp-content/uploads/2009/02/step01.png" alt="step01" width="600" height="477" /></p>
<p>First, I always find it helpful to start with a reference sketch. So go ahead and scribble up a heart, or grab the image from above. I&#8217;m sure you noticed my ugly mug in the background. I though it added just a sinister air that complements the tutorial nicely.</p>
<p><img class="alignnone size-full wp-image-474" title="step02" src="http://www.clickpopmedia.com/wp-content/uploads/2009/02/step02.png" alt="step02" width="600" height="477" /></p>
<p>We&#8217;re going to start by tracing the major central shape of the heart that we&#8217;ll build from. I always like to trace using no fill, and a really bright, contrasting color, so I don&#8217;t lose my lines.</p>
<p><img class="alignnone size-full wp-image-475" title="step03" src="http://www.clickpopmedia.com/wp-content/uploads/2009/02/step03.png" alt="step03" width="600" height="477" /></p>
<p>Now we&#8217;ll trace the little veins/arteries/i don&#8217;t know, with a much thicker brush with round edges. Make sure to make the overlap the the border of your first shape.</p>
<p><img class="alignnone size-full wp-image-476" title="step04" src="http://www.clickpopmedia.com/wp-content/uploads/2009/02/step04.png" alt="step04" width="600" height="477" /></p>
<p>Now we&#8217;ll go through the process of blocking out the rest of your shapes. If you like, you can make the cava&#8217;s, aorta, veins, and arteries connect and end in different ways where they won&#8217;t show up in the final piece, but for my purposes, I was only concerned with the parts that would show up at the end. This step is really just more tracing.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.clickpopmedia.com/2009/02/26/how-to-have-a-heart-illustrator-tutorial/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Introduction to my PHP/MySQL User Authentication system</title>
		<link>http://www.clickpopmedia.com/2009/02/20/introduction-to-my-phpmysql-user-authentication-system/</link>
		<comments>http://www.clickpopmedia.com/2009/02/20/introduction-to-my-phpmysql-user-authentication-system/#comments</comments>
		<pubDate>Sat, 21 Feb 2009 02:45:42 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Sean]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sean metzgar]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[user authentication]]></category>

		<guid isPermaLink="false">http://www.clickpopmedia.com/2009/02/20/introduction-to-my-phpmysql-user-authentication-system/</guid>
		<description><![CDATA[I thought I&#8217;d take a few minutes to go over the basics of what I&#8217;m going to be accomplishing over the next few weeks.  I plan on guiding everyone through some of the basics of building your own user authentication system.  This will include many segments varying from storing password information securely, user [...]]]></description>
			<content:encoded><![CDATA[<p>I thought I&#8217;d take a few minutes to go over the basics of what I&#8217;m going to be accomplishing over the next few weeks.  I plan on guiding everyone through some of the basics of building your own user authentication system.  This will include many segments varying from storing password information securely, user registration (and required information), password recovery vs. password reset, analyzing security vulnerabilities, possible applications and a wide variety of other topics that could possibly go along.</p>
<p>I will be starting off with a very basic set of security rules that you will need to keep in mind in order to maintain a secure list of users and password information.  Without going in to further details, I can&#8217;t stress enough the huge mistake that many authentication systems use by limiting the size, type, and strength of a users passwords as well as the mistake of how the information is stored.  I plan on analyzing a few preexisting systems and show some fundamental flaws associated with them, and provide tips to help safeguard your data from any unwanted guests.</p>
<p>Please be sure to check back soon, as I will be posting in the next few days.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.clickpopmedia.com/2009/02/20/introduction-to-my-phpmysql-user-authentication-system/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Updated: Vector Tutorial &#8211; Obama Logo (Added .ai and .eps Assets)</title>
		<link>http://www.clickpopmedia.com/2009/01/23/vector-tutorial-obama-logo/</link>
		<comments>http://www.clickpopmedia.com/2009/01/23/vector-tutorial-obama-logo/#comments</comments>
		<pubDate>Fri, 23 Jan 2009 21:11:37 +0000</pubDate>
		<dc:creator>VQ</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[VQ]]></category>
		<category><![CDATA[Vector]]></category>
		<category><![CDATA[illustrator]]></category>
		<category><![CDATA[logo]]></category>
		<category><![CDATA[obama]]></category>
		<category><![CDATA[tutorail]]></category>

		<guid isPermaLink="false">http://www.clickpopmedia.com/?p=379</guid>
		<description><![CDATA[
No matter what you think of his politics, U.S. presidential cantidate Barack Obama has a pretty incredible marketing and design machine behind him. One strong example of this is his &#8220;O&#8221; logo. Simple, attractive, symbolic, it&#8217;s undeniably an effective logo.
Another aspect of the Obama campaign that is attractive to a lot of American&#8217;s is the [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-381" title="Obama Logo" src="http://www.clickpopmedia.com/wp-content/uploads/2008/08/obama.jpg" alt="" /></p>
<p>No matter what you think of his politics, U.S. presidential cantidate <a href="http://www.barackobama.com">Barack Obama</a> has a pretty incredible marketing and design machine behind him. One strong example of this is his &#8220;O&#8221; logo. Simple, attractive, symbolic, it&#8217;s undeniably an effective logo.</p>
<p>Another aspect of the Obama campaign that is attractive to a lot of American&#8217;s is the grass-roots, everybody can be involved attitude that they&#8217;ve been trying quite successfully to convey. In honor of that attitude, and just in time for the Democratic Convention, I thought I would show some really helpful Illustrator techniques by making the Obama logo. In this tutorial, we&#8217;ll be going over the Pathfinder, Envelope Warps, Opacity Masks, and Gradient Meshes. And we&#8217;ll use a drop shadow!</p>
<p>What&#8217;s that? You don&#8217;t think we can do it? I have three words for you my friend.</p>
<p>Yes. We. Can.</p>
<p><span id="more-379"></span></p>
<p><strong>Step 1. Get Yourself Ready<br />
</strong></p>
<p style="text-align: center;"><img class="alignnone size-full wp-image-385" title="Obama 1" src="http://www.clickpopmedia.com/wp-content/uploads/2008/08/01.jpg" alt="" width="400" height="400" /></p>
<p style="text-align: left;">I&#8217;m working with a 400px by 400px artboard. I&#8217;ve set a verticle gradient from #0768A4 to #168ACB. Also, it&#8217;s important you&#8217;re working in CMYK for this tutorial. I&#8217;ll explain later when we get down to the Opacity Masks.</p>
<p style="text-align: left;"><strong>Step 2. Lay the Foundation<br />
</strong></p>
<p style="text-align: center;"><img class="alignnone size-full wp-image-386" title="Obama 2" src="http://www.clickpopmedia.com/wp-content/uploads/2008/08/02.jpg" alt="" width="400" height="400" /></p>
<p style="text-align: left;">Make a 350px by 350px white circle in the middle of your artboard.</p>
<p style="text-align: left;"><strong>Step 3. Lay Another Foundation<br />
</strong></p>
<p style="text-align: center;"><img class="alignnone size-full wp-image-387" title="Obama 3" src="http://www.clickpopmedia.com/wp-content/uploads/2008/08/03.jpg" alt="" width="400" height="400" /></p>
<p style="text-align: left;">Select your cirlce and copy in front (ctrl + f, <em>mac</em> cmd + f) to make a copy in the same position. Size it down to 320px by 320px and apply the same gradient that you have on the background. You&#8217;ll want to have the light blue on the bottom of this circle, and push it up past the middle.</p>
<p style="text-align: left;"><strong>Step 4. And a Third Foundation<br />
</strong></p>
<p style="text-align: center;"><img class="alignnone size-full wp-image-388" title="Obama 4" src="http://www.clickpopmedia.com/wp-content/uploads/2008/08/04.jpg" alt="" width="400" height="400" /></p>
<p style="text-align: left;">Now copy in front (ctrl + f, <em>mac </em>cmd + f) again, size the circle down to 175px by 175px, and change the fill to white.</p>
<p style="text-align: left;"><strong>Step 5. Stripes<br />
</strong></p>
<p style="text-align: center;"><img class="alignnone size-full wp-image-390" title="Obama 5" src="http://www.clickpopmedia.com/wp-content/uploads/2008/08/05.jpg" alt="" width="400" height="400" /></p>
<p style="text-align: left;">Now we have to make the gently sloping stripes that represent the bountiful fields of the American mid-west. We start to do this by making five rectangles, alternating red and white. You can start by making one rectangle, then hold down alt (<em>mac</em> option) and drag the shape to make another copy. Line them up, and repeat till you have your five stripes.</p>
<p style="text-align: left;"><strong>Step 6. Bendy Stripes<br />
</strong></p>
<p style="text-align: center;"><img class="alignnone size-full wp-image-392" title="Obama 6" src="http://www.clickpopmedia.com/wp-content/uploads/2008/08/06.jpg" alt="" width="400" height="400" /></p>
<p style="text-align: left;">Now it&#8217;s time to get your warp on! Yeah! Hit ctrl + alt + shift + w (<em>mac </em>cmd + option + shift + w) or go to Object&gt;Envelope Distort&gt;Make With Warp&#8230; A dialogue box will pop up. Click the preview box, so you can see what you&#8217;re doing, and set distortion just the way you like it. I have mine set to Arc, with the bend at 25%, and the horizontal distortion at -50%.</p>
<p style="text-align: left;"><strong>Step 7. Bendy, Stripey Ground<br />
</strong></p>
<p style="text-align: center;"><img class="alignnone size-full wp-image-394" title="Obama 7" src="http://www.clickpopmedia.com/wp-content/uploads/2008/08/07.jpg" alt="" width="400" height="400" /></p>
<p style="text-align: left;">Now you want to size up, rotate, and align your stripes. You want the top of your shape stopping slightly below the halfway mark of your innermost white circle, representing the sunrise of a new day or something. The bottom of the stripes need to cover the bottom of the inner blue circle.</p>
<p style="text-align: left;"><strong>Step 8. Pathfinding<br />
</strong></p>
<p style="text-align: center;"><img class="alignnone size-full wp-image-395" title="Obama 8" src="http://www.clickpopmedia.com/wp-content/uploads/2008/08/08.jpg" alt="" width="400" height="400" /></p>
<p style="text-align: left;">Now we&#8217;re going to use an incredibly helpful tool that I&#8217;ve used in <a href="http://www.clickpopmedia.com/2008/03/27/fun-with-illustrator-happy-little-clouds/">other tutorial&#8217;s</a>. Say hello to the Pathfinder. Select the inner blue circle, copy it in front (ctrl + f, <em>mac</em> cmd + f) and move the copy to the front (ctr + shift + ], <em>mac</em> cmd + shift + ] ). Now select your stripes, expand (Object&gt;Envelope&gt;Expand) and ungroup (ctrl + shift + g, <em>mac </em>cmd + shift + g) them. Finally, select your stripes and the blue circle copy, and hit the crop button in the pathfinder window. You should end up with this:</p>
<p style="text-align: center;"><img class="alignnone size-full wp-image-397" title="Obama 9" src="http://www.clickpopmedia.com/wp-content/uploads/2008/08/09.jpg" alt="" width="400" height="400" /></p>
<p style="text-align: left;">Now, if you&#8217;re the boring type, you could stop right here with a perfectly functional Obama logo. If you&#8217;re the adverterous type, why don&#8217;t you continue with me?</p>
<p style="text-align: left;"><strong>Step 9.</strong> <strong>Depth and Shadow</strong></p>
<p style="text-align: center;"><img class="alignnone size-full wp-image-398" title="Obama 10" src="http://www.clickpopmedia.com/wp-content/uploads/2008/08/10.jpg" alt="" width="400" height="400" /></p>
<p style="text-align: left;">Now you&#8217;re going to copy the big white circle from the back, and move it to the front (remember that one? ctrl + shift + ], <em>mac </em>cmd + shift + ] ). Here&#8217;s another really great illustrator thing, the gradient mesh. Object&gt;Create Gradient Mesh, then a dialogue window will popup. I set it to 3 columns and three rows. The more detail you want on your gradient, the more rows and columns you should set. For our purposes, 3 is fine.</p>
<p style="text-align: left;">Now we&#8217;re going to begin adding color to individual points on our mesh. Anywhere you want to darken (in my case the bottom left side of the logo) should be assigned darker shades.</p>
<p style="text-align: left;">In the transparency panel, we&#8217;re going to set the blend mode to multiply, and the opacity to 80.</p>
<p style="text-align: left;"><strong>Step 10. The Bright Horizon<br />
</strong></p>
<p style="text-align: center;"><img class="alignnone size-full wp-image-399" title="Obama 11" src="http://www.clickpopmedia.com/wp-content/uploads/2008/08/11.jpg" alt="" width="400" height="400" /></p>
<p style="text-align: left;">Now we have to make the bright glow coming up from beyond the horizon. Any ideas on how to do this? If you said, &#8220;Let&#8217;s just use a simple white to black gradient with the blend mode set to lighten or screen.&#8221; you&#8217;d be wrong. Dead wrong.</p>
<p style="text-align: left;">Because of some problem, which I won&#8217;t pretend to understand, with working with CMYK in Illustrator, sometimes you can&#8217;t do lighten or screen gradients. Why don&#8217;t we just work with RGB then? Because the gradients look cruddy, that&#8217;s why.</p>
<p style="text-align: left;">The solution lies in something called an Opacity Mask. First select your inner blue circle, copy it, and move it to the front. Now set the fill to white and set the blend mode to <strong>lighten</strong>. While in the transparency panel, open up the more options menu and select <strong>Make Opacity Mask</strong>. Now with your opacity mask selected, make a rectangle with a white to black gradient fill. Keep in mind, the white area displays fully what&#8217;s underneath, and as you&#8217;re getting closer to black, it masks more and more.</p>
<p style="text-align: left;"><strong>Step 11. More Practice Masking</strong></p>
<p style="text-align: center;"><img class="alignnone size-full wp-image-400" title="Obama 12" src="http://www.clickpopmedia.com/wp-content/uploads/2008/08/12.jpg" alt="" width="400" height="400" /></p>
<p style="text-align: left;">Now we need to set up another opacity mask for the &#8220;shine&#8221; cast by the rising sun. Copy, paste, and move to front The blue circle. Size it down slightly, and align it with the bottom of the original blue circle. Now Copy this circle, but don&#8217;t paste it yet. Set the blend mode of the white circle to <strong>Screen</strong><img src="file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/moz-screenshot.jpg" alt="" />.</p>
<p style="text-align: left;">Now create an Opacity Mask on this layer, like you did for your last layer. With the opacity layer selected, paste the circle into it from your clipboard and set the fill to a black to white gradient.  Play around with your gradient till you get the effect you want.</p>
<p style="text-align: center;"><img class="alignnone size-full wp-image-401" title="Obama 13" src="http://www.clickpopmedia.com/wp-content/uploads/2008/08/13.jpg" alt="" width="400" height="400" /><strong></strong></p>
<p style="text-align: left;"><strong>Step 12. The Finishing Touch</strong></p>
<p style="text-align: center;"><img class="alignnone size-full wp-image-403" title="Obama 14" src="http://www.clickpopmedia.com/wp-content/uploads/2008/08/14.jpg" alt="" width="400" height="400" /></p>
<p style="text-align: left;">To finish things off we&#8217;re going to add a little dropshadow. Select Effect&gt;Stylize&gt;Drop Shadow, set your settings, and go for it. I have the mode set to Multiply, opacity at 75%, x offset -10px, y offset 10px, and blur to 15px.</p>
<p style="text-align: center;"><img class="alignnone size-full wp-image-404" title="Obama Logo" src="http://www.clickpopmedia.com/wp-content/uploads/2008/08/end.jpg" alt="" width="400" height="400" /></p>
<p style="text-align: left;">I hope you enjoyed this tutorial. In the next politically minded tutorial, I&#8217;m going to show you how to make a Shepard Farey inspired John McCain poster like <a href="http://www.clickpopmedia.com/projects/mccain/posters/McCain-Kids.pdf">this one:</a></p>
<p style="text-align: center;"><a href="http://www.clickpopmedia.com/projects/mccain/posters/McCain-Kids.pdf"><img class="alignnone" title="Kids" src="http://www.clickpopmedia.com/projects/mccain/McCain-Kids.jpg" alt="" width="300" height="388" /></a></p>
<p style="text-align: center;"><strong><a href="http://www.clickpopmedia.com/Freebies/obama.zip">Download the Obama Logo Asset Files Vectors</a></strong></p>
<p style="text-align: left;"><strong>GodBless:VQ</strong></p>
<p style="text-align: center;">
]]></content:encoded>
			<wfw:commentRss>http://www.clickpopmedia.com/2009/01/23/vector-tutorial-obama-logo/feed/</wfw:commentRss>
		<slash:comments>44</slash:comments>
		</item>
		<item>
		<title>Collision Detection and Game Design</title>
		<link>http://www.clickpopmedia.com/2008/07/07/collision-detection-and-game-design/</link>
		<comments>http://www.clickpopmedia.com/2008/07/07/collision-detection-and-game-design/#comments</comments>
		<pubDate>Mon, 07 Jul 2008 23:58:21 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Paul]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Asteroids]]></category>
		<category><![CDATA[Collision Detection]]></category>
		<category><![CDATA[Game Development]]></category>

		<guid isPermaLink="false">http://www.clickpopmedia.com/?p=353</guid>
		<description><![CDATA[

This is the second step in my series of tutorial, the first being Easy Keyboard Controls and Game Design. In this tutorial I will be building on what we already have, adding asteroids and the ability to crash into them.
I&#8217;ve made a few minor changes to the original code and graphics since the last tutorial, [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="550" height="400" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://www.clickpopmedia.com/wp-content/uploads/2008/07/asteroids.swf" /><embed type="application/x-shockwave-flash" width="550" height="400" src="http://www.clickpopmedia.com/wp-content/uploads/2008/07/asteroids.swf"></embed></object></p>
<p style="text-align: left;">
This is the second step in my series of tutorial, the first being <a href="http://www.clickpopmedia.com/2008/06/25/easy-keyboard-controls-and-game-design/">Easy Keyboard Controls and Game Design</a>. In this tutorial I will be building on what we already have, adding asteroids and the ability to crash into them.<br />
<span id="more-353"></span>I&#8217;ve made a few minor changes to the original code and graphics since the last tutorial, but nothing big.</p>
<p>So I create a MovieClip with 3 frames and a different asteroid shape on each frame (you could have more or less if you wanted).  I give the asteroids their own class since each is going to have to move independently.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw3">public</span> <span class="kw3">static</span> const LARGE:<span class="kw3">String</span> = <span class="st0">&quot;large&quot;</span>;<br />
<span class="kw3">public</span> <span class="kw3">static</span> const MEDIUM:<span class="kw3">String</span> = <span class="st0">&quot;medium&quot;</span>;<br />
<span class="kw3">public</span> <span class="kw3">static</span> const SMALL:<span class="kw3">String</span> = <span class="st0">&quot;small&quot;</span>;</p>
<p><span class="kw3">public</span> <span class="kw2">var</span> speedX:<span class="kw3">Number</span>;<br />
<span class="kw3">public</span> <span class="kw2">var</span> speedY:<span class="kw3">Number</span>;<br />
<span class="kw3">public</span> <span class="kw2">var</span> <span class="kw3">size</span>:<span class="kw3">String</span>;<br />
&#8230;<br />
<span class="kw3">public</span> <span class="kw2">function</span> Move<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">x</span> += speedX;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">y</span> += speedY;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="kw3">this</span>.<span class="me1">x</span> &gt; <span class="nu0">550</span> + <span class="kw3">this</span>.<span class="kw3">width</span>/<span class="nu0">2</span><span class="br0">&#41;</span> <span class="kw3">this</span>.<span class="me1">x</span> = -<span class="kw3">this</span>.<span class="kw3">width</span>/<span class="nu0">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="kw3">this</span>.<span class="me1">x</span> &lt; -<span class="kw3">this</span>.<span class="kw3">width</span>/<span class="nu0">2</span><span class="br0">&#41;</span> <span class="kw3">this</span>.<span class="me1">x</span> = <span class="nu0">550</span> + <span class="kw3">this</span>.<span class="kw3">width</span>/<span class="nu0">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="kw3">this</span>.<span class="me1">y</span> &gt; <span class="nu0">400</span> + <span class="kw3">this</span>.<span class="kw3">height</span>/<span class="nu0">2</span><span class="br0">&#41;</span> <span class="kw3">this</span>.<span class="me1">y</span> = -<span class="kw3">this</span>.<span class="kw3">height</span>/<span class="nu0">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="kw3">this</span>.<span class="me1">y</span> &lt; -<span class="kw3">this</span>.<span class="kw3">height</span>/<span class="nu0">2</span><span class="br0">&#41;</span> <span class="kw3">this</span>.<span class="me1">y</span> = <span class="nu0">400</span> + <span class="kw3">this</span>.<span class="kw3">height</span>/<span class="nu0">2</span>;<br />
<span class="br0">&#125;</span></div>
<p>What I&#8217;ve done here is give my Asteroid class X and Y speed properties that work with the <strong>Move()</strong> method for motion.  I intend to call the <strong>Move()</strong> method for each asteroid in the <strong>MainLoop()</strong> function.</p>
<p>On creation (in the constructor) I want to know if this asteroid is actually a piece of a larger asteroid or not.  If it is I&#8217;m going to be passing it the base asteroid that this one is breaking off of to use it&#8217;s X:Y coordinates and speed, plus to know what size to make the new asteroid.</p>
<p>Now back to the <strong>Main</strong> class (in the <a href="http://www.clickpopmedia.com/2008/06/25/easy-keyboard-controls-and-game-design/">last tutorial</a> I called this the <strong>Asteroids</strong> class but changed it to <strong>Main</strong> since I wanted an <strong>Asteroid</strong> class).</p>
<p>We need to keep track of our asteroids.  To do that we will use an <strong>Array</strong>.  We will add this to the <strong>Main</strong> constructor:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw3">public</span> <span class="kw2">function</span> Main<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; dCount = <span class="nu0">0</span>;<br />
&#8230;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="me1">refresh_tf</span>.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">MOUSE_UP</span>, resetGame<span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; asteroids = <span class="kw2">new</span> <span class="kw3">Array</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span><span class="br0">&#40;</span><span class="kw2">var</span> i:<span class="kw3">int</span> = <span class="nu0">0</span>; i&lt;<span class="nu0">6</span>; i++<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; asteroids.<span class="kw3">push</span><span class="br0">&#40;</span><span class="kw2">new</span> Asteroid<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">stage</span>.<span class="me1">addChild</span><span class="br0">&#40;</span>asteroids<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
<p>This is just adding 6 asteroids to the stage and giving a click event to a reset button I decided to add.<br />
<strong>dCount</strong> stands for Death Count with an obvious purpose.</p>
<p>The <strong>resetGame()</strong> function is just resetting all the properties to the default.  I still have to make sure to remove all the asteroids before adding all new ones, but that&#8217;s it.</p>
<p>I moved the contents of the <strong>MainLoop()</strong> from the <a href="http://www.clickpopmedia.com/2008/06/25/easy-keyboard-controls-and-game-design/">previous tutorial</a> into a function called <strong>shipControl()</strong> which is now being called from the new <strong>MainLoop()</strong>;</p>
<p>Our revised <strong>MainLoop()</strong> method is as follows:</p>
<div class="dean_ch" style="white-space: wrap;">protected <span class="kw2">function</span> MainLoop<span class="br0">&#40;</span><span class="kw3">e</span>:TimerEvent<span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span><span class="br0">&#40;</span><span class="kw2">var</span> i <span class="kw1">in</span> asteroids<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; asteroids<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">Move</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>dead<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; deathTime&#8211;;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>deathTime &lt;=<span class="nu0">0</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dead = <span class="kw2">false</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; invincibleTime = <span class="nu0">150</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; invincible = <span class="kw2">true</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addChild<span class="br0">&#40;</span>ship_mc<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shipControl<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>!invincible<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; collisionCheck<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="kw3">e</span>.<span class="me1">currentTarget</span>.<span class="me1">currentCount</span>%<span class="nu0">10</span> == <span class="nu0">0</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ship_mc.<span class="kw3">visible</span> = <span class="br0">&#40;</span>ship_mc.<span class="kw3">visible</span><span class="br0">&#41;</span>? <span class="kw2">false</span>: <span class="kw2">true</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; invincibleTime&#8211;;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>invincibleTime &lt;= <span class="nu0">0</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ship_mc.<span class="kw3">visible</span> = <span class="kw2">true</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; invincible = <span class="kw2">false</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
<p>These nested <strong>if..else</strong> statements are here to handle death and resurrection (RIGHT ON!).</p>
<p>So we have our asteroids flying about the screen, but we have yet to make them destroy your ship.  You should notice above the call for to a method call <strong>collisionCheck()</strong>;<br />
Here is that function now:</p>
<div class="dean_ch" style="white-space: wrap;">protected <span class="kw2">function</span> collisionCheck<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> p1:Point = <span class="kw2">new</span> Point<span class="br0">&#40;</span>ship_mc.<span class="me1">p1</span>.<span class="me1">x</span>, ship_mc.<span class="me1">p1</span>.<span class="me1">y</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; p1 = ship_mc.<span class="kw3">localToGlobal</span><span class="br0">&#40;</span>p1<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> p2:Point = <span class="kw2">new</span> Point<span class="br0">&#40;</span>ship_mc.<span class="me1">p2</span>.<span class="me1">x</span>, ship_mc.<span class="me1">p2</span>.<span class="me1">y</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; p2 = ship_mc.<span class="kw3">localToGlobal</span><span class="br0">&#40;</span>p2<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> p3:Point = <span class="kw2">new</span> Point<span class="br0">&#40;</span>ship_mc.<span class="me1">p3</span>.<span class="me1">x</span>, ship_mc.<span class="me1">p3</span>.<span class="me1">y</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; p3 = ship_mc.<span class="kw3">localToGlobal</span><span class="br0">&#40;</span>p3<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> p4:Point = <span class="kw2">new</span> Point<span class="br0">&#40;</span>ship_mc.<span class="me1">p4</span>.<span class="me1">x</span>, ship_mc.<span class="me1">p4</span>.<span class="me1">y</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; p4 = ship_mc.<span class="kw3">localToGlobal</span><span class="br0">&#40;</span>p4<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> p5:Point = <span class="kw2">new</span> Point<span class="br0">&#40;</span>ship_mc.<span class="me1">p5</span>.<span class="me1">x</span>, ship_mc.<span class="me1">p5</span>.<span class="me1">y</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; p5 = ship_mc.<span class="kw3">localToGlobal</span><span class="br0">&#40;</span>p5<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span><span class="br0">&#40;</span><span class="kw2">var</span> i <span class="kw1">in</span> asteroids<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="br0">&#40;</span>asteroids<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">hitTestPoint</span><span class="br0">&#40;</span>p1.<span class="me1">x</span>, p1.<span class="me1">y</span>, <span class="kw2">true</span><span class="br0">&#41;</span> ||<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; asteroids<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">hitTestPoint</span><span class="br0">&#40;</span>p2.<span class="me1">x</span>, p2.<span class="me1">y</span>, <span class="kw2">true</span><span class="br0">&#41;</span> ||<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; asteroids<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">hitTestPoint</span><span class="br0">&#40;</span>p3.<span class="me1">x</span>, p3.<span class="me1">y</span>, <span class="kw2">true</span><span class="br0">&#41;</span> ||<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; asteroids<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">hitTestPoint</span><span class="br0">&#40;</span>p4.<span class="me1">x</span>, p4.<span class="me1">y</span>, <span class="kw2">true</span><span class="br0">&#41;</span> ||<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; asteroids<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">hitTestPoint</span><span class="br0">&#40;</span>p5.<span class="me1">x</span>, p5.<span class="me1">y</span>, <span class="kw2">true</span><span class="br0">&#41;</span><span class="br0">&#41;</span> &amp;amp;&amp;amp; !dead<span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; destroyShip<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; remove<span class="br0">&#40;</span>i<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
<p>Each asteroid does a <strong>hitTest</strong> with each point on my <strong>ship_mc</strong>.  It&#8217;s important that I&#8217;m using <strong>hitTestPoint()</strong> here because it is capable of checking based on the actual shape of the movie clip.  A regular <strong>hitTest</strong> between two <strong>MovieClips</strong> will only check to see if the bounding boxes are overlapping&#8230;  in our case that could still be quite 20 pixels or more away from an actual collision.  This is exactly what makes realistic 2D physics so difficult in ActionScript.</p>
<p>Anyways, the Hit Test may be a little buggy in some cases, but <strong>hitTestPoint</strong> works pretty well for us here.  After we detect a hit of course we have to destroy the ship and asteroid and set the death timer.  the <strong>destroyShip()</strong> function is trivial enough, but I would like to take a quick look at a line from the remove() method:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw3">stage</span>.<span class="me1">addChild</span><span class="br0">&#40;</span>asteroids<span class="br0">&#91;</span>asteroids.<span class="kw3">push</span><span class="br0">&#40;</span><span class="kw2">new</span> Asteroid<span class="br0">&#40;</span>asteroids<span class="br0">&#91;</span>num<span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="nu0">-1</span><span class="br0">&#93;</span><span class="br0">&#41;</span>;</div>
<p>I really just need to explain how this slightly complicated jumble works.  Reading this from the inner most parenthases out;</p>
<p>We are creating a new Asteroid object (passing it our parent asteroid that has just been destroyed).<br />
<strong>new Asteroid(asteroids[num])</strong></p>
<p>We add that Asteroid object to the end of our asteroids Array which is returning the new length of the Array.<br />
<strong>asteroids.push(&#8230;)</strong></p>
<p>We then use that new length (minus 1) to add our newest asteroid to the stage.<br />
<strong>stage.addChild(asteroids[...-1]);</strong></p>
<p>Eh, see now?  Collision detection is easy!  I think my next installment might be a little more interesting when I add levels, lives, and a scoring system.</p>
<p>&#8230;  No bullets you ask?  Well that&#8217;s just an extension of what I&#8217;ve already written here right?  The only extra thing you have to remember is that the bullets have a limited lifespan.</p>
<p>If you are still confused and can&#8217;t do it on your own (if you want to <em>learn</em> you really aught to at least try) then you can always check out the finished source when it&#8217;s released.</p>
<p>The source code for the example in this tutorial can be found here: <a href="http://www.clickpopmedia.com/wp-content/uploads/2008/07/asteroidsv2source.rar">Asteroids &#8211; V2 Source</a></p>
<p><a href="http://www.clickpopmedia.com/2008/06/25/easy-keyboard-controls-and-game-design/">&lt; Lesson 1: Easy Keyboard Controls and Game Design</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.clickpopmedia.com/2008/07/07/collision-detection-and-game-design/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Easy Keyboard Controls and Game Design</title>
		<link>http://www.clickpopmedia.com/2008/06/25/easy-keyboard-controls-and-game-design/</link>
		<comments>http://www.clickpopmedia.com/2008/06/25/easy-keyboard-controls-and-game-design/#comments</comments>
		<pubDate>Thu, 26 Jun 2008 01:21:07 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Paul]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Asteroids]]></category>
		<category><![CDATA[Game Development]]></category>
		<category><![CDATA[Keyboard]]></category>

		<guid isPermaLink="false">http://www.clickpopmedia.com/?p=340</guid>
		<description><![CDATA[
In this tutorial I will be going over some of the basic elements to making a game in Flash. This being the first in a short series of tutorials on the subject, I will cover the main game loop and keyboard controls.

First off we need to set up some simple graphics.  I did some [...]]]></description>
			<content:encoded><![CDATA[<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="550" height="400" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://www.clickpopmedia.com/wp-content/uploads/2008/06/asteroids.swf" /><embed type="application/x-shockwave-flash" width="550" height="400" src="http://www.clickpopmedia.com/wp-content/uploads/2008/06/asteroids.swf"></embed></object><br />
In this tutorial I will be going over some of the basic elements to making a game in Flash. This being the first in a short series of tutorials on the subject, I will cover the main game loop and keyboard controls.<br />
<span id="more-340"></span><br />
First off we need to set up some simple graphics.  I did some REALLY simple graphics as you can see.  The <strong>ship_mc</strong> being just a triangle and on the 3rd frame of the ship movie clip it get&#8217;s a little fire tail.  Since I am just imitating <em>Atari Interactive, Inc.</em>&#8217;s<em> Asteroids</em>, we don&#8217;t really need anything more then that for now.<br />
Now, to get our initial code setup:</p>
<div class="dean_ch" style="white-space: wrap;">package <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> flash.<span class="me1">display</span>.<span class="me1">*</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> flash.<span class="me1">events</span>.<span class="me1">*</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> flash.<span class="kw3">text</span>.<span class="me1">*</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> flash.<span class="me1">utils</span>.<span class="me1">Timer</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">class</span> Asteroids <span class="kw3">extends</span> <span class="kw3">MovieClip</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; protected <span class="kw2">var</span> mainTimer:Timer;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> Asteroids<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mainTimer = <span class="kw2">new</span> Timer<span class="br0">&#40;</span><span class="nu0">20</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mainTimer.<span class="me1">addEventListener</span><span class="br0">&#40;</span>TimerEvent.<span class="me1">TIMER</span>, MainLoop<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ship_mc.<span class="kw3">stop</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">addEventListener</span><span class="br0">&#40;</span>Event.<span class="me1">DEACTIVATE</span>, deactive<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">addEventListener</span><span class="br0">&#40;</span>Event.<span class="me1">ACTIVATE</span>, active<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">stage</span>.<span class="me1">addEventListener</span><span class="br0">&#40;</span>KeyboardEvent.<span class="me1">KEY_DOWN</span>, kDown<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">stage</span>.<span class="me1">addEventListener</span><span class="br0">&#40;</span>KeyboardEvent.<span class="me1">KEY_UP</span>, kUp<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; protected <span class="kw2">function</span> MainLoop<span class="br0">&#40;</span><span class="kw3">e</span>:TimerEvent<span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; protected <span class="kw2">function</span> deactive<span class="br0">&#40;</span><span class="kw3">e</span>:Event<span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mainTimer.<span class="kw3">stop</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; protected <span class="kw2">function</span> active<span class="br0">&#40;</span><span class="kw3">e</span>:Event<span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mainTimer.<span class="kw3">start</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; protected <span class="kw2">function</span> kDown<span class="br0">&#40;</span><span class="kw3">e</span>:KeyboardEvent<span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; protected <span class="kw2">function</span> kUp<span class="br0">&#40;</span><span class="kw3">e</span>:KeyboardEvent<span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
<p>So far this is just a skeleton of our game.  We have our <strong>KEY_DOWN</strong> and <strong>KEY_UP</strong> events which will handle all of our keyboard controls later.  But, more importantly, we have our <strong>mainTimer</strong>.  By setting up our game engine to run based on a timer I can later change the frame rate without changing the game dynamics (I left the frame rate at 12/sec for the example above).  This is also useful if your game has too many graphical elements and the frame rate drops on some machines, this will preserve the speed of the game itself.<br />
So, please notice that I have the Timer set to &#8220;tick&#8221; every 20 milliseconds (1000 milliseconds to 1 seconds) which is about 50 ticks per second. Because of that, we are going to have some small values to work with when playing with flight speed and rotation in our ship.<br />
But, first let us think about keyboard controls:</p>
<div class="dean_ch" style="white-space: wrap;">protected <span class="kw2">var</span> thrust:<span class="kw3">Boolean</span>;<br />
protected <span class="kw2">var</span> rpm:<span class="kw3">Number</span>;<br />
protected <span class="kw2">function</span> kDown<span class="br0">&#40;</span><span class="kw3">e</span>:KeyboardEvent<span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
<span class="co1">//&nbsp; &nbsp; &nbsp; trace(e.keyCode);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">37</span> || <span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">65</span> || <span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">100</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rpm = <span class="nu0">-4</span>;<br />
<span class="co1">//&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; trace(&quot;LEFT&quot;);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">38</span> || <span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">87</span> || <span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">104</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; thrust = <span class="kw2">true</span>;<br />
<span class="co1">//&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; trace(&quot;UP&quot;);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">39</span> || <span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">68</span> || <span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">102</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rpm = <span class="nu0">4</span>;<br />
<span class="co1">//&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; trace(&quot;RIGHT&quot;);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
protected <span class="kw2">function</span> kUp<span class="br0">&#40;</span><span class="kw3">e</span>:KeyboardEvent<span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">37</span> || <span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">65</span> || <span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">100</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rpm = <span class="nu0">0</span>;<br />
<span class="co1">//&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; trace(&quot;LEFT&quot;);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">38</span> || <span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">87</span> || <span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">104</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; thrust = <span class="kw2">false</span>;<br />
<span class="co1">//&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; trace(&quot;UP&quot;);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">39</span> || <span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">68</span> || <span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">102</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rpm = <span class="nu0">0</span>;<br />
<span class="co1">//&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; trace(&quot;RIGHT&quot;);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
<p><strong>rpm</strong> and <strong>thrust</strong> are going to control our ships flight in the <strong>MainLoop</strong> later.  The <strong>keyCode</strong> is a number which represents the key being pressed or released on the keyboard.  I prefer to set a value on down because the <strong>KEY_DOWN</strong> event will be fired off numerous times very quickly if the key is held too long.  I have the controls set up to work with WASD, the arrow keys, or the num pad.<br />
To find the key values I just traced <strong>e.keyCode</strong> in the <strong>kUp()</strong> function and tried pressing the keys in question.  This got me the numbers you see in the code above.  The commented out traces are there to make sure we have the correct keys, since we don&#8217;t have any other indicator yet.</p>
<p>The next step is a simple one (except for some of the math):</p>
<div class="dean_ch" style="white-space: wrap;">protected const TOP_SPEED:<span class="kw3">Number</span> = <span class="nu0">10</span>;<br />
protected const ACCELERATION:<span class="kw3">Number</span> = .<span class="nu0">1</span>;<br />
protected const FRICTION:<span class="kw3">Number</span> = .<span class="nu0">995</span>;</p>
<p>protected <span class="kw2">var</span> mainTimer:Timer;<br />
protected <span class="kw2">var</span> speedX:<span class="kw3">Number</span>;<br />
protected <span class="kw2">var</span> speedY:<span class="kw3">Number</span>;</p>
<p><span class="kw3">public</span> <span class="kw2">function</span> Asteroids<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; rpm = <span class="nu0">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; speedX = <span class="nu0">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; speedY = <span class="nu0">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &#8230;<br />
<span class="br0">&#125;</span></p>
<p>protected <span class="kw2">function</span> MainLoop<span class="br0">&#40;</span><span class="kw3">e</span>:TimerEvent<span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ship_mc.<span class="me1">rotation</span> += rpm;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> dx:<span class="kw3">Number</span> = ACCELERATION * <span class="kw3">Math</span>.<span class="kw3">cos</span><span class="br0">&#40;</span><span class="br0">&#40;</span>ship_mc.<span class="me1">rotation*</span><span class="kw3">Math</span>.<span class="kw3">PI</span><span class="br0">&#41;</span>/<span class="nu0">180</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> dy:<span class="kw3">Number</span> = ACCELERATION * <span class="kw3">Math</span>.<span class="kw3">sin</span><span class="br0">&#40;</span><span class="br0">&#40;</span>ship_mc.<span class="me1">rotation*</span><span class="kw3">Math</span>.<span class="kw3">PI</span><span class="br0">&#41;</span>/<span class="nu0">180</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>thrust<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; speedX += dx;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; speedY += dy;<br />
<span class="co1">//We want to have a max speed in any direction of the compass</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> speed = speedX*speedX + speedY*speedY;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>speed &gt;= TOP_SPEED*TOP_SPEED<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; speedX *= <span class="br0">&#40;</span>TOP_SPEED*TOP_SPEED<span class="br0">&#41;</span>/speed;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; speedY *= <span class="br0">&#40;</span>TOP_SPEED*TOP_SPEED<span class="br0">&#41;</span>/speed;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ship_mc.<span class="kw3">gotoAndStop</span><span class="br0">&#40;</span><span class="nu0">3</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ship_mc.<span class="kw3">gotoAndStop</span><span class="br0">&#40;</span><span class="nu0">1</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="co1">//I know there is no friction in space, but I can&#8217;t remember if Asteroids had it or not.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; speedX *= FRICTION;<br />
&nbsp; &nbsp; &nbsp; &nbsp; speedY *= FRICTION;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; ship_mc.<span class="me1">x</span> += speedX;<br />
&nbsp; &nbsp; &nbsp; &nbsp; ship_mc.<span class="me1">y</span> += speedY;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>ship_mc.<span class="me1">x</span> &gt; <span class="nu0">560</span><span class="br0">&#41;</span> ship_mc.<span class="me1">x</span> = <span class="nu0">-10</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>ship_mc.<span class="me1">x</span> &lt; <span class="nu0">-10</span><span class="br0">&#41;</span> ship_mc.<span class="me1">x</span> = <span class="nu0">560</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>ship_mc.<span class="me1">y</span> &gt; <span class="nu0">410</span><span class="br0">&#41;</span> ship_mc.<span class="me1">y</span> = <span class="nu0">-10</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>ship_mc.<span class="me1">y</span> &lt; <span class="nu0">-10</span><span class="br0">&#41;</span> ship_mc.<span class="me1">y</span> = <span class="nu0">410</span>;<br />
<span class="br0">&#125;</span></div>
<p>Here we have initialized some variables in the constructor first.  Then we filled in our <strong>MainLoop</strong> to give our spaceship some life.  I would think the <strong>rotation</strong> is self evident&#8230;  it&#8217;s the first line of the method.  I used some constants in my math (<strong>ACCELERATION, TOP_SPEED,</strong> and <strong>FRICTION</strong>) so that I can easily adjust the game settings all in one place, without searching for the parts of the code that I need changed.<br />
The last group of <strong>if</strong> statements above are checking to see in our ship has flown off the screen and if it has it will be moved to the other side.</p>
<p>That&#8217;s all for now.  Next time I will probably add some asteroids and talk a little about <a href="http://www.clickpopmedia.com/2008/07/07/collision-detection-and-game-design/">collision detection</a>.</p>
<p>You can download the source for this example here: <a href="http://www.clickpopmedia.com/wp-content/uploads/2008/06/asteroidssource.rar">AsteroidsSource.rar</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.clickpopmedia.com/2008/06/25/easy-keyboard-controls-and-game-design/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Realistic Shadow Effects using Filters</title>
		<link>http://www.clickpopmedia.com/2008/06/11/realistic-shadow-effects-using-filters/</link>
		<comments>http://www.clickpopmedia.com/2008/06/11/realistic-shadow-effects-using-filters/#comments</comments>
		<pubDate>Wed, 11 Jun 2008 15:37:42 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Paul]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[DropShadowFilter]]></category>
		<category><![CDATA[Filters]]></category>

		<guid isPermaLink="false">http://www.clickpopmedia.com/?p=329</guid>
		<description><![CDATA[
I have another simple but neat, little tutorial here on Flash CS3 filters.  This time I&#8217;m not using Tweens at all.  Our effect is going to use the MouseEvent.MOUSE_MOVE event to create the illusion of a light source coming from our cursor.

To begin with we are going to make our Shadows class.  [...]]]></description>
			<content:encoded><![CDATA[<pre><center><embed src="http://www.clickpopmedia.com/wp-content/uploads/2008/06/shadows.swf" width="550" height="400" allowscriptaccess="always" allowfullscreen="true"></center></pre>
<p>I have another simple but neat, little tutorial here on Flash CS3 filters.  This time I&#8217;m not using <strong>Tweens</strong> at all.  Our effect is going to use the <strong>MouseEvent.MOUSE_MOVE</strong> event to create the illusion of a light source coming from our cursor.</p>
<p><span id="more-329"></span></p>
<p>To begin with we are going to make our Shadows class.  This class is going to extend <strong>MovieClip</strong>, have a <strong>DropShadowFilter</strong> pre-applied to it and a public method to change the drop shadow filters distance and angle.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw3">public</span> <span class="kw2">class</span> Shadows <span class="kw3">extends</span> <span class="kw3">MovieClip</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw3">static</span> <span class="kw2">var</span> All:<span class="kw3">Array</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; protected <span class="kw2">var</span> txtF:<span class="kw3">TextField</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; protected <span class="kw2">var</span> drop:DropShadowFilter;<br />
&nbsp; &nbsp; &nbsp; &nbsp; protected <span class="kw2">var</span> distance:<span class="kw3">Number</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; protected <span class="kw2">var</span> angle:<span class="kw3">Number</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; protected <span class="kw2">var</span> dropAlpha:<span class="kw3">Number</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; protected <span class="kw2">var</span> blurX:<span class="kw3">Number</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; protected <span class="kw2">var</span> blurY:<span class="kw3">Number</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> Shadows<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>Shadows.<span class="me1">All</span> == <span class="kw2">null</span><span class="br0">&#41;</span> Shadows.<span class="me1">All</span> = <span class="kw2">new</span> <span class="kw3">Array</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; distance = <span class="nu0">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; angle = <span class="nu0">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dropAlpha = <span class="nu0">1</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; blurX = <span class="nu0">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; blurX = <span class="nu0">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; drop = <span class="kw2">new</span> DropShadowFilter<span class="br0">&#40;</span>distance, angle, <span class="nu0">0</span>, dropAlpha, blurX, blurY<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">filters</span> = <span class="br0">&#91;</span>drop<span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Shadows.<span class="me1">All</span>.<span class="kw3">push</span><span class="br0">&#40;</span><span class="kw3">this</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> lightSource<span class="br0">&#40;</span>X:<span class="kw3">Number</span>, Y:<span class="kw3">Number</span><span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> dx:<span class="kw3">Number</span> = <span class="br0">&#40;</span><span class="kw3">this</span>.<span class="me1">x</span> + <span class="br0">&#40;</span><span class="kw3">this</span>.<span class="kw3">width</span>/<span class="nu0">2</span><span class="br0">&#41;</span><span class="br0">&#41;</span>-X;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> dy:<span class="kw3">Number</span> = <span class="br0">&#40;</span><span class="kw3">this</span>.<span class="me1">y</span> + <span class="br0">&#40;</span><span class="kw3">this</span>.<span class="kw3">height</span>/<span class="nu0">2</span><span class="br0">&#41;</span><span class="br0">&#41;</span>-Y;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; angle = <span class="br0">&#40;</span><span class="nu0">180</span> * <span class="kw3">Math</span>.<span class="kw3">atan</span><span class="br0">&#40;</span>dy/dx<span class="br0">&#41;</span><span class="br0">&#41;</span> / <span class="kw3">Math</span>.<span class="kw3">PI</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>dx &lt; <span class="nu0">0</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; angle += <span class="nu0">180</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; distance = <span class="kw3">Math</span>.<span class="kw3">sqrt</span><span class="br0">&#40;</span>dy*dy + dx*dx<span class="br0">&#41;</span>/<span class="nu0">10</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dropAlpha = <span class="nu0">10</span>/distance;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; blurX = <span class="kw3">Math</span>.<span class="kw3">abs</span><span class="br0">&#40;</span>dx/<span class="nu0">20</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; blurY = <span class="kw3">Math</span>.<span class="kw3">abs</span><span class="br0">&#40;</span>dy/<span class="nu0">20</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; drop = <span class="kw2">new</span> DropShadowFilter<span class="br0">&#40;</span>distance, angle, <span class="nu0">0</span>, dropAlpha, blurX, blurY<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">filters</span> = <span class="br0">&#91;</span>drop<span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
<p>I hope  you can see what is going on in the code.  I&#8217;m simply setting all my variables equal to 0 or 1, depending on what it&#8217;s for, and applying my filter in the constructor.  Also note that I&#8217;m saving all my objects in a static array.  This makes it easier to call all the <strong>lightSource()</strong> methods at once in a for loop later.</p>
<p>In the <strong>lightSource()</strong> method we have a little bit of math that you might be unfamiliar with.<br />
My variables <strong>dy</strong> and <strong>dx</strong> stand for distance y or x and I&#8217;m setting them equal to the distance from the point given and the center of my ShadowObject.</p>
<p><strong>angle</strong> is going to be the angle of the drop shadow and it needs to be in degrees.  <strong>Math.atan()</strong> is called arc-tangent in the Trigonometry world and it gives your the value of the angle opposite the Y side of a right triangle in radians.  If that doesn&#8217;t make sense, just know that it&#8217;s giving me that angle I need, but in the wrong units. I convert it by multiplying by 180 and dividing by PI.<strong> Math.atan()</strong> only returns a value between -pi/2 and pi/2 (-90 to 90 degrees) which only covers half a circle, so I have to check if we actually need the other side.  And, that&#8217;s what my if() statement is for.</p>
<p><strong>distance</strong> is calculated using the Pythagorean theorem C^2 = A^2 + B^2 (and then divided by 10 otherwise it&#8217;s just too much).<strong></strong></p>
<p><strong>DropAlpha</strong>, <strong>blurX</strong>, and <strong>blurY</strong> are all set pretty clearly (blur has to be positive, thus the <strong>Math.abs()</strong> or absolute value).</p>
<p>Finally our function creates a new drop filter with our new values and applies it to our Shadow object.</p>
<p>Except for trying to remember the math involved, this one has been pretty easy so far, huh?  Well then, let&#8217;s try using it in a project!</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">var</span> str = <span class="kw2">new</span> <span class="kw3">String</span><span class="br0">&#40;</span><span class="st0">&quot;ClickPop&quot;</span><span class="br0">&#41;</span>;<br />
<span class="kw2">var</span> str2 = <span class="kw2">new</span> <span class="kw3">String</span><span class="br0">&#40;</span><span class="st0">&quot;Media&quot;</span><span class="br0">&#41;</span>;<br />
<span class="kw2">var</span> letter:Shadows;<br />
<span class="kw2">var</span> newX:<span class="kw3">Number</span> = <span class="nu0">30</span>;<br />
<span class="kw2">var</span> overLetter:<span class="kw3">TextField</span>;</p>
<p><span class="kw1">for</span><span class="br0">&#40;</span><span class="kw2">var</span> i=<span class="nu0">0</span>; i&lt;str.<span class="kw3">length</span>; i++<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; letter = <span class="kw2">new</span> Shadows<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; letter.<span class="me1">x</span> = newX;<br />
&nbsp; &nbsp; &nbsp; &nbsp; letter.<span class="me1">y</span> = <span class="nu0">80</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; overLetter = <span class="kw2">new</span> <span class="kw3">TextField</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; overLetter.<span class="kw3">text</span> = str.<span class="kw3">charAt</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; overLetter.<span class="kw3">setTextFormat</span><span class="br0">&#40;</span><span class="kw2">new</span> <span class="kw3">TextFormat</span><span class="br0">&#40;</span><span class="st0">&quot;Georgia&quot;</span>, <span class="nu0">100</span>, 0&#215;0000FF, <span class="kw2">true</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; overLetter.<span class="kw3">autoSize</span> = TextFieldAutoSize.<span class="kw3">LEFT</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; letter.<span class="me1">addChild</span><span class="br0">&#40;</span>overLetter<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; addChild<span class="br0">&#40;</span>letter<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; newX += letter.<span class="kw3">width</span>;<br />
<span class="br0">&#125;</span><br />
newX = <span class="nu0">80</span>;<br />
<span class="kw1">for</span><span class="br0">&#40;</span>i=<span class="nu0">0</span>; i&lt;str2.<span class="kw3">length</span>; i++<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; letter = <span class="kw2">new</span> Shadows<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; letter.<span class="me1">x</span> = newX;<br />
&nbsp; &nbsp; &nbsp; &nbsp; letter.<span class="me1">y</span> = <span class="nu0">180</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; overLetter = <span class="kw2">new</span> <span class="kw3">TextField</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; overLetter.<span class="kw3">text</span> = str2.<span class="kw3">charAt</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; overLetter.<span class="kw3">setTextFormat</span><span class="br0">&#40;</span><span class="kw2">new</span> <span class="kw3">TextFormat</span><span class="br0">&#40;</span><span class="st0">&quot;Georgia&quot;</span>, <span class="nu0">100</span>, 0&#215;0000FF, <span class="kw2">true</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; overLetter.<span class="kw3">autoSize</span> = TextFieldAutoSize.<span class="kw3">LEFT</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; letter.<span class="me1">addChild</span><span class="br0">&#40;</span>overLetter<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; addChild<span class="br0">&#40;</span>letter<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; newX += letter.<span class="kw3">width</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="kw2">function</span> changeLight<span class="br0">&#40;</span>event:MouseEvent<span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span><span class="br0">&#40;</span><span class="kw2">var</span> i=<span class="nu0">0</span>; i&lt;Shadows.<span class="me1">All</span>.<span class="kw3">length</span>; i++<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Shadows.<span class="me1">All</span><span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">lightSource</span><span class="br0">&#40;</span><span class="kw3">stage</span>.<span class="me1">mouseX</span>, <span class="kw3">stage</span>.<span class="me1">mouseY</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
<span class="kw3">stage</span>.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">MOUSE_MOVE</span>, changeLight<span class="br0">&#41;</span>;</div>
<p>So, there it is.  I&#8217;m adding each letter to a different Shadow object so that their shadows move independently.  I then update all the shadow light sources to the mouse&#8217;s X and Y coordinates every time the mouse moves.  SO EASY!!</p>
<p>I have a few more ideas for cool effects that you can make with filters and I will probably post about them soon.</p>
<p>Download the Source Code for the example used in this post here: <a href="http://www.clickpopmedia.com/wp-content/uploads/2008/06/shadows.zip">ShadowsSource.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.clickpopmedia.com/2008/06/11/realistic-shadow-effects-using-filters/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Cool Rollover Effects with Filters</title>
		<link>http://www.clickpopmedia.com/2008/05/28/cool-rollover-effects-with-filters/</link>
		<comments>http://www.clickpopmedia.com/2008/05/28/cool-rollover-effects-with-filters/#comments</comments>
		<pubDate>Wed, 28 May 2008 05:15:51 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Paul]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Filters]]></category>
		<category><![CDATA[Menu]]></category>
		<category><![CDATA[Rollover Effects]]></category>

		<guid isPermaLink="false">http://www.clickpopmedia.com/?p=317</guid>
		<description><![CDATA[
Above is a little example menu I made for a fake game called &#8220;Top Secret.&#8221;  Don&#8217;t expect a game to start when you click on the Play button.  Instead, when you click a button you will get a little menu to change the rollover effects of said button.
What I&#8217;m going to be talking [...]]]></description>
			<content:encoded><![CDATA[<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="550" height="400" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://www.clickpopmedia.com/wp-content/uploads/2008/05/topsecret.swf" /><embed type="application/x-shockwave-flash" width="550" height="400" src="http://www.clickpopmedia.com/wp-content/uploads/2008/05/topsecret.swf"></embed></object></p>
<p>Above is a little example menu I made for a fake game called &#8220;Top Secret.&#8221;  Don&#8217;t expect a game to start when you click on the Play button.  Instead, when you click a button you will get a little menu to change the rollover effects of said button.</p>
<p>What I&#8217;m going to be talking about for the next&#8230; however long you read this, is how to recreate these cool effects for your own projects. Hopefully you will come up with some better ideas for using filters then just rollover effects.<br />
<span id="more-317"></span><br />
<strong>Setting Up The Example:</strong><br />
I simply typed all the text you see using whatever font seemed nice.  I then selected each TextField and broke them apart by pressing Ctrl+B twice.  After making each button into a MovieClip and giving them appropriate instance names (i.e. the Play button has a name of &#8220;<strong>play_mc</strong>&#8221; and you can see this in the popup menu) I felt like it was high time to make some cool rollover effects!</p>
<p><strong>Working w/ The Code:</strong><br />
I&#8217;m just going to talk about the one filter here, since the others are all pretty much the same.</p>
<p>To make a blur effect we need to create a new AS class file (one for each button).  We are going to use Tweens, Filters, Events, and we are extending a MovieClip, so we need to import the apropriate library classes for those:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw3">import</span> flash.<span class="me1">display</span>.<span class="me1">*</span>;<br />
<span class="kw3">import</span> flash.<span class="me1">events</span>.<span class="me1">*</span>;<br />
<span class="kw3">import</span> flash.<span class="me1">filters</span>.<span class="me1">*</span>;<br />
<span class="kw3">import</span> fl.<span class="me1">transitions</span>.<span class="me1">*</span>;<br />
<span class="kw3">import</span> fl.<span class="me1">transitions</span>.<span class="me1">easing</span>.<span class="me1">*</span>;</div>
<p>The star in <strong>flash.events.*;</strong> just means &#8220;all of them&#8221; and it&#8217;s a quick way of importing lots of stuff at once.</p>
<p>Start out with making and applying our filter to get an idea of what we want:</p>
<div class="dean_ch" style="white-space: wrap;">blur = <span class="kw2">new</span> BlurFilter<span class="br0">&#40;</span><span class="nu0">8</span>, <span class="nu0">4</span>, <span class="nu0">1</span><span class="br0">&#41;</span>; <span class="co1">//blurX, blurY, quality</span><br />
<span class="kw3">this</span>.<span class="me1">filters</span> = <span class="br0">&#91;</span>blur<span class="br0">&#93;</span>;</div>
<p>This is the default value/filter you see before you change any settings in my example movie above.</p>
<p>The <strong>filters</strong> property that I&#8217;m setting in the above code is an Array property of any DisplayObject (including Sprites, MovieClips, and any other children thereof).  That is why I need the square brackets, because it&#8217;s an Array.</p>
<p>With the filter in place we need to check for our <strong>MOUSE_OVER</strong> and <strong>MOUSE_OUT</strong> events and tween the blur filter.</p>
<p>A <strong>Tween</strong> object can change any <strong>Number</strong> property of almost any object over time using <strong>easing functions</strong>.  To read more on Tweens you can check out <a href="http://www.clickpopmedia.com/2008/03/10/tween-intro/">Intro to ActionScript 3.0 Tweening</a>.</p>
<div class="dean_ch" style="white-space: wrap;">protected <span class="kw2">var</span> blurX_tw:Tween;<br />
protected <span class="kw2">var</span> blurY_tw:Tween;</p>
<p><span class="kw3">public</span> <span class="kw2">function</span> <span class="coMULTI">/*CONSTRUCTOR*/</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">MOUSE_OVER</span>, Over<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">MOUSE_OUT</span>, Out<span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; blurX_tw = <span class="kw2">new</span> Tween<span class="br0">&#40;</span>blur, <span class="st0">&quot;blurX&quot;</span>, Regular.<span class="me1">easeInOut</span>, <span class="nu0">8</span>, <span class="nu0">8</span>, <span class="nu0">1</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; blurX_tw.<span class="me1">addEventListener</span><span class="br0">&#40;</span>TweenEvent.<span class="me1">MOTION_CHANGE</span>, updateBlurFilter<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; blurY_tw = <span class="kw2">new</span> Tween<span class="br0">&#40;</span>blur, <span class="st0">&quot;blurY&quot;</span>, Regular.<span class="me1">easeInOut</span>, <span class="nu0">4</span>, <span class="nu0">4</span>, <span class="nu0">1</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; blurY_tw.<span class="me1">addEventListener</span><span class="br0">&#40;</span>TweenEvent.<span class="me1">MOTION_CHANGE</span>, updateBlurFilter<span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
protected <span class="kw2">function</span> updateBlurFilter<span class="br0">&#40;</span><span class="kw3">e</span>:TweenEvent<span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">filters</span> = <span class="br0">&#91;</span><span class="kw3">e</span>.<span class="me1">currentTarget</span>.<span class="me1">obj</span><span class="br0">&#93;</span>;<br />
<span class="br0">&#125;</span><br />
protected <span class="kw2">function</span> Over<span class="br0">&#40;</span>event:MouseEvent<span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; blurX_tw.<span class="me1">continueTo</span><span class="br0">&#40;</span><span class="nu0">0</span>, <span class="nu0">10</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; blurY_tw.<span class="me1">continueTo</span><span class="br0">&#40;</span><span class="nu0">0</span>, <span class="nu0">10</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
protected <span class="kw2">function</span> Out<span class="br0">&#40;</span>event:MouseEvent<span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; blurX_tw.<span class="me1">continueTo</span><span class="br0">&#40;</span><span class="nu0">8</span>, <span class="nu0">15</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; blurY_tw.<span class="me1">continueTo</span><span class="br0">&#40;</span><span class="nu0">4</span>, <span class="nu0">15</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></div>
<p>Ah! Well there we go.  We now have a tween that effects our X&amp;Y blur. Notice that we have an event listener on those two tweens for <strong>TweenEvent.MOTION_CHANGE</strong>.  This is because the blur filter that we are tweening is NOT the filter that is on our MovieClip.  So for every step that the tween changes the blur values, we need to reapply the filter to our Button.</p>
<p>I&#8217;m sure you have noticed that I am making most of my functions and variables <strong>protected</strong>.  This is because <strong>protected</strong> is just like <strong>private</strong>, but private will not be inherited by child classes and protected will.  I want to keep inheritance because this way I can (and have) make a base class with all my effects and just have my button classes extend that base.</p>
<p>If you download the source for my example movie <a href="http://www.clickpopmedia.com/wp-content/uploads/2008/05/topsecretsource.zip">HERE</a>, you will notice that I have almost all my code within the Rollover class and all my button classes are extending that one.</p>
<p>Once again, you can download the source for this tutorial and example movie here: <a href="http://www.clickpopmedia.com/wp-content/uploads/2008/05/topsecretsource.zip">TopSecret Example Source Code (ZIP &#8211; 958 KB)</a></p>
<p>If you are interested in some of the components I used or want to know more about working with colors, let me know in a comment and maybe I will make a separate tutorial on them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.clickpopmedia.com/2008/05/28/cool-rollover-effects-with-filters/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Creating an XML Gallery with ActionScript 3.0</title>
		<link>http://www.clickpopmedia.com/2008/05/14/creating-an-xml-gallery-with-actionscript-30/</link>
		<comments>http://www.clickpopmedia.com/2008/05/14/creating-an-xml-gallery-with-actionscript-30/#comments</comments>
		<pubDate>Thu, 15 May 2008 02:37:28 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[DIY]]></category>
		<category><![CDATA[Just for Fun!]]></category>
		<category><![CDATA[Paul]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[VQ]]></category>
		<category><![CDATA[Beginner]]></category>
		<category><![CDATA[Gallery]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.clickpopmedia.com/?p=309</guid>
		<description><![CDATA[For any dynamic Flash project, XML will be a powerful tool.  One of the most common examples (and one of the simplest) is a picture gallery like the one I have here:

Images came from http://www.stockvault.net/
I will be talking about how to use Flash and XML to make a simple, yet superfly, gallery.

So, let us [...]]]></description>
			<content:encoded><![CDATA[<p>For any dynamic Flash project, XML will be a powerful tool.  One of the most common examples (and one of the simplest) is a picture gallery like the one I have here:</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="600" height="700" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://www.clickpopmedia.com/wp-content/uploads/2008/05/xmlgallery.swf" /><embed type="application/x-shockwave-flash" width="600" height="700" src="http://www.clickpopmedia.com/wp-content/uploads/2008/05/xmlgallery.swf"></embed></object><br />
<em>Images came from <a href="http://www.stockvault.net/">http://www.stockvault.net/</a></em></p>
<p>I will be talking about how to use Flash and XML to make a simple, yet superfly, gallery.<br />
<span id="more-309"></span><br />
So, let us  start off by looking at my XML file&#8217;s structure:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="sc3"><span class="re1">&lt;gallery</span> <span class="re0">dir</span>=<span class="st0">&quot;//url/Photos/&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;img</span> <span class="re0">id</span>=<span class="st0">&#8216;0&#8242;</span> <span class="re0">file</span>=<span class="st0">&quot;photo_7030_20070301.jpg&quot;</span> <span class="re0">width</span>=<span class="st0">&#8216;500&#8242;</span> <span class="re0">height</span>=<span class="st0">&#8216;375&#8242;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Cute Puppy! &nbsp;Who couldn&#8217;t love that face?<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/img<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;img</span> <span class="re0">id</span>=<span class="st0">&#8216;1&#8242;</span> <span class="re0">file</span>=<span class="st0">&quot;photo_4095_20070301.jpg&quot;</span> <span class="re0">width</span>=<span class="st0">&#8216;500&#8242;</span> <span class="re0">height</span>=<span class="st0">&#8216;375&#8242;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Three Friendly Cats.<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/img<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;img</span> <span class="re0">id</span>=<span class="st0">&#8216;2&#8242;</span> <span class="re0">file</span>=<span class="st0">&quot;photo_4281_20070301.jpg&quot;</span> <span class="re0">width</span>=<span class="st0">&#8216;500&#8242;</span> <span class="re0">height</span>=<span class="st0">&#8216;375&#8242;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; The Terror of the UnderSofa!<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/img<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;img</span> <span class="re0">id</span>=<span class="st0">&#8216;3&#8242;</span> <span class="re0">file</span>=<span class="st0">&quot;photo_6257_20070301.jpg&quot;</span> <span class="re0">width</span>=<span class="st0">&#8216;500&#8242;</span> <span class="re0">height</span>=<span class="st0">&#8216;375&#8242;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Bored? Let&#8217;s play catch!<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/img<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;img</span> <span class="re0">id</span>=<span class="st0">&#8216;4&#8242;</span> <span class="re0">file</span>=<span class="st0">&quot;photo_6882_20070301.jpg&quot;</span> <span class="re0">width</span>=<span class="st0">&#8216;500&#8242;</span> <span class="re0">height</span>=<span class="st0">&#8216;377&#8242;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; It may be natural, but this picture still feels weird to me.<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/img<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;img</span> <span class="re0">id</span>=<span class="st0">&#8216;5&#8242;</span> <span class="re0">file</span>=<span class="st0">&quot;photo_7241_20070301.jpg&quot;</span> <span class="re0">width</span>=<span class="st0">&#8216;500&#8242;</span> <span class="re0">height</span>=<span class="st0">&#8216;375&#8242;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; My cats hate the snow.<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/img<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;img</span> <span class="re0">id</span>=<span class="st0">&#8216;6&#8242;</span> <span class="re0">file</span>=<span class="st0">&quot;photo_7538_20070507.jpg&quot;</span> <span class="re0">width</span>=<span class="st0">&#8216;500&#8242;</span> <span class="re0">height</span>=<span class="st0">&#8216;622&#8242;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;![CDATA[&lt;I&gt;LOOK&lt;/I&gt; IT'S &lt;B&gt;HTML&lt;/B&gt;!!!]]&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/img<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;img</span> <span class="re0">id</span>=<span class="st0">&#8216;7&#8242;</span> <span class="re0">file</span>=<span class="st0">&quot;photo_7915_20070609.jpg&quot;</span> <span class="re0">width</span>=<span class="st0">&#8216;500&#8242;</span> <span class="re0">height</span>=<span class="st0">&#8216;371&#8242;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Skinny cats are OK too.<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/img<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/gallery<span class="re2">&gt;</span></span></span></div>
<p>XML is very simple to understand if you know anything about HTML&#8217;s tag structure.  The XML document has a root <strong>tag</strong> &lt;gallery&gt; that has an <strong>attribute</strong> dir=&#8221;//url/Photos/&#8221;.  Every tag has to be closed within it&#8217;s own level of the tree.   Our gallery tag is closed at the bottom of the document with <strong>&lt;/gallery&gt;</strong>.   This means that all the  <strong>&lt;img&gt;</strong> tags are elements inside the gallery element (both open and close tags combined make up an element).</p>
<p>Our <strong>&lt;img&gt;</strong> tags have several attributes, such as the images file name and it&#8217;s pixel demensions.  Inside each <strong>&lt;img&gt;</strong> element we have a short comment about the image that will be displayed in a TextField in our Flash movie.</p>
<blockquote><p>One important thing to notice here is that if you want to have HTML in your TextField then you need to tell the code that something is a string containing HTML and not more elements.  We do this with a special bracket &lt;![CDATA[  <em>HTML GOES HERE</em> ]]&gt;  Isn&#8217;t that GREAT!  That right there probably made this whole tutorial worth while (that was a problem that took me a long time to solve).</p></blockquote>
<p>OK, now that we&#8217;ve looked at the XML we need to make it work with ActionScript 3. In Adobe Flash CS3 I created a new AS3 FLA doc and a new AS doc.  In the FLA I simply created some very basic MovieClips for my left and right arrows and I placed a TextField at the bottom of my stage (which I set to 600 X 700 with a black background).  After naming my instances and setting up the Document Class linkage I was done with the FLA side of thing and the rest is ActionScript.</p>
<p>Our Document Class has to extend MovieClip so we take our first steps thusly:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw3">public</span> <span class="kw2">class</span> Main <span class="kw3">extends</span> <span class="kw3">MovieClip</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">var</span> currentImg:<span class="kw3">Number</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">var</span> lastImg:<span class="kw3">Number</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">var</span> <span class="kw3">xml</span>:<span class="kw3">XML</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">var</span> loader:Loader;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">var</span> xmlLoader:URLLoader;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> Main<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; loader = <span class="kw2">new</span> Loader<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addChild<span class="br0">&#40;</span>loader<span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlLoader = <span class="kw2">new</span> URLLoader<span class="br0">&#40;</span><span class="kw2">new</span> URLRequest<span class="br0">&#40;</span><span class="st0">&quot;//url/gallery.xml&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlLoader.<span class="me1">addEventListener</span><span class="br0">&#40;</span>Event.<span class="me1">COMPLETE</span>, <span class="kw3">parseXML</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; left_mc.<span class="kw3">stop</span><span class="br0">&#40;</span><span class="br0">&#41;</span>; <span class="co1">//Need to stop the arrows from flickering</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; right_mc.<span class="kw3">stop</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
<p>In our constructor we are initializing our Loader which will contain the loaded images and we are loading our XML document.  When the XML doc is done loading, the function parseXML will handle the content.</p>
<div class="dean_ch" style="white-space: wrap;">protected <span class="kw2">function</span> <span class="kw3">parseXML</span><span class="br0">&#40;</span>event:Event<span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; left_mc.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">MOUSE_UP</span>, nextImg<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; left_mc.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">MOUSE_OUT</span>, arrowOut<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; left_mc.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">MOUSE_OVER</span>, arrowOver<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; right_mc.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">MOUSE_UP</span>, prevImg<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; right_mc.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">MOUSE_OUT</span>, arrowOut<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; right_mc.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">MOUSE_OVER</span>, arrowOver<span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">xml</span> = <span class="kw2">new</span> <span class="kw3">XML</span><span class="br0">&#40;</span>event.<span class="me1">currentTarget</span>.<span class="kw3">data</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; lastImg = <span class="kw3">xml</span>.<span class="me1">img</span>.<span class="kw3">length</span><span class="br0">&#40;</span><span class="br0">&#41;</span> &#8211; <span class="nu0">1</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; currentImg = <span class="nu0">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; loadImg<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></div>
<p>I&#8217;ve recently gotten into the habit of using protected functions rather then private functions.  There is only one difference between the two and that&#8217;s that private <em>anything</em> won&#8217;t be inherited by child classes.<br />
In this function I set the MouseEvents for the arrows because if the XML failed to load, there would be no reason for the arrows to work.</p>
<p>Alright, so I saved my XML tree in the var <strong>xml</strong> for ease of use later.  I also saved the number of images in my XML doc using the <strong>length()</strong> method.  Something to know about the length method is it will only tell you how many elements there are of that tag type at that level.  For example, if I were to have child elements inside my <strong>img</strong> elements that would not affect the return value of <strong>xml.img.length();</strong> It&#8217;s only telling you how many img elements are children of <strong>gallery</strong> (<strong>gallery</strong> is accessed with the var <strong>xml</strong> directly).</p>
<div class="dean_ch" style="white-space: wrap;">protected <span class="kw2">function</span> loadImg<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; loader.<span class="me1">x</span> = <span class="br0">&#40;</span><span class="kw3">stage</span>.<span class="kw3">width</span> &#8211; <span class="kw3">Number</span><span class="br0">&#40;</span><span class="kw3">xml</span>.<span class="me1">img</span><span class="br0">&#91;</span>currentImg<span class="br0">&#93;</span>.@<span class="kw3">width</span><span class="br0">&#41;</span><span class="br0">&#41;</span>/<span class="nu0">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; loader.<span class="me1">y</span> = <span class="br0">&#40;</span><span class="kw3">stage</span>.<span class="kw3">height</span> &#8211; <span class="nu0">50</span> &#8211; <span class="kw3">Number</span><span class="br0">&#40;</span><span class="kw3">xml</span>.<span class="me1">img</span><span class="br0">&#91;</span>currentImg<span class="br0">&#93;</span>.@<span class="kw3">height</span><span class="br0">&#41;</span><span class="br0">&#41;</span>/<span class="nu0">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; loader.<span class="kw3">load</span><span class="br0">&#40;</span><span class="kw2">new</span> URLRequest<span class="br0">&#40;</span><span class="kw3">xml</span>.@dir + <span class="kw3">xml</span>.<span class="me1">img</span><span class="br0">&#91;</span>currentImg<span class="br0">&#93;</span>.@file<span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; loader.<span class="me1">contentLoaderInfo</span>.<span class="me1">addEventListener</span><span class="br0">&#40;</span>Event.<span class="me1">COMPLETE</span>, loadFin<span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
protected <span class="kw2">function</span> loadFin<span class="br0">&#40;</span>event:Event<span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; textDisp_TF.<span class="kw3">htmlText</span> = <span class="kw3">xml</span>.<span class="me1">img</span><span class="br0">&#91;</span>currentImg<span class="br0">&#93;</span>;<br />
<span class="br0">&#125;</span></div>
<p>In that first function I&#8217;m just going to focus on the one line with the URLRequest.  In order to traverse an XML tree you need start with the base.  Your XML var (in our case it&#8217;s called <strong>xml</strong>) points to that base (in this case the base is <strong>gallery</strong>).  So when we want to access the attribute <strong>dir</strong> in the tag <strong>gallery</strong>, we need to type <strong>xml.@dir</strong> and this will return <em>&#8220;//url/Photos/&#8221;</em>.  The &#8216;@&#8217; symbol denotes that it&#8217;s an attribute and not an element (tag).</p>
<p>Getting the file name is just one step further.  <strong>currentImg</strong> is a Number variable that stores which image we are on.  Thinking of our XML var as something similar to a bunch of nested arrays we can see how you might access a specific file name with <strong>xml.img[currentImg].@file</strong> This says we want the file attribute in the [currentImg] (first second so forth) img element which is in our base element.  There are quite a few ways of finding what you need in an XML doc and you can learn more about them<a href="http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&amp;file=00000129.html"> here</a>.</p>
<p>In the second function we are displaying the text from within our XML img element.  Here we aren&#8217;t accessing any attributes or anything, this is where we get the content between the open &lt;img&gt; and close &lt;/img&gt; tags.</p>
<p>Finally we have the arrow MouseEvent handlers:</p>
<div class="dean_ch" style="white-space: wrap;">protected <span class="kw2">function</span> arrowOut<span class="br0">&#40;</span>event:MouseEvent<span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">MovieClip</span><span class="br0">&#40;</span>event.<span class="me1">currentTarget</span><span class="br0">&#41;</span>.<span class="kw3">gotoAndStop</span><span class="br0">&#40;</span><span class="nu0">1</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p>protected <span class="kw2">function</span> arrowOver<span class="br0">&#40;</span>event:MouseEvent<span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">MovieClip</span><span class="br0">&#40;</span>event.<span class="me1">currentTarget</span><span class="br0">&#41;</span>.<span class="kw3">gotoAndStop</span><span class="br0">&#40;</span><span class="nu0">2</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p>protected <span class="kw2">function</span> nextImg<span class="br0">&#40;</span>event:MouseEvent<span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; loader.<span class="me1">unload</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; currentImg = <span class="br0">&#40;</span>currentImg &lt; lastImg<span class="br0">&#41;</span>? currentImg + <span class="nu0">1</span> : <span class="nu0">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; loadImg<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p>protected <span class="kw2">function</span> prevImg<span class="br0">&#40;</span>event:MouseEvent<span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; loader.<span class="me1">unload</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; currentImg = <span class="br0">&#40;</span>currentImg &gt; <span class="nu0">0</span><span class="br0">&#41;</span>? currentImg &#8211; <span class="nu0">1</span> : lastImg;<br />
&nbsp; &nbsp; &nbsp; &nbsp; loadImg<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></div>
<p>Once again I&#8217;m using the less obvious form of the if..else statement.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw1">if</span><span class="br0">&#40;</span>num&gt;<span class="nu0">5</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; num = <span class="nu0">5</span>;<br />
<span class="br0">&#125;</span><span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; num = <span class="nu0">0</span>;<br />
<span class="br0">&#125;</span><br />
<span class="co1">//OR, THIS NEXT PART DOES THE SAME THING</span><br />
num = <span class="br0">&#40;</span>num&gt;<span class="nu0">5</span><span class="br0">&#41;</span>? <span class="nu0">5</span> : <span class="nu0">0</span>;</div>
<p>Well that&#8217;s about it for this level of a gallery.  You can make galleries look really nice with fade transitions between images, small loading animations for larger images, scrollable thumbnail selection menu&#8230;  etc.</p>
<p>Here is a downloadable source of my example file (images not included&#8230; get them <a href="http://www.stockvault.net/">here</a>): <a href="http://www.clickpopmedia.com/wp-content/uploads/2008/05/xmlgallery.zip">XMLGallery.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.clickpopmedia.com/2008/05/14/creating-an-xml-gallery-with-actionscript-30/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Turning the Default Wordpress Theme into Something Wonderful: Structure</title>
		<link>http://www.clickpopmedia.com/2008/05/06/default-wordpress-to-wonderful/</link>
		<comments>http://www.clickpopmedia.com/2008/05/06/default-wordpress-to-wonderful/#comments</comments>
		<pubDate>Tue, 06 May 2008 05:00:09 +0000</pubDate>
		<dc:creator>VQ</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[VQ]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[theming]]></category>

		<guid isPermaLink="false">http://www.clickpopmedia.com/?p=295</guid>
		<description><![CDATA[
I have to get this out of the way, I am a huge fan of Wordpress. Both our blogs use Wordpress. Whenever I get a web design project, my first thought is, &#8220;How can I best utilize Wordpress for this project.&#8221; Granted, my second thought is frequently, &#8220;Maybe Wordpress isn&#8217;t the best solution for this [...]]]></description>
			<content:encoded><![CDATA[<p><img style="float:left; padding-right:10px;" title="logo1" src="http://www.clickpopmedia.com/wp-content/uploads/2008/05/logo1.jpg" alt="" /><br />
I have to get this out of the way, I am a huge fan of Wordpress. Both our blogs use Wordpress. Whenever I get a web design project, my first thought is, &#8220;How can I best utilize Wordpress for this project.&#8221; Granted, my second thought is frequently, &#8220;Maybe Wordpress isn&#8217;t the best solution for this [flash, static, e-commerce] site.&#8221; Be that as it may, Wordpress is still by far my favorite blogging platform. And it&#8217;s not just for blogging. With a few minor changes WP can become a truly powerful CMS as well. So if you&#8217;re looking for a free, powerful, and open platform with an <em>insane </em>developer community, look no further than your new best friend Wordpress.</p>
<p>This is the first in a series on turning the Default WP Theme into something wonderful. Today we&#8217;re going to go over the basic structure of a Wordpress Theme. I&#8217;m not going to go over the WP installation process, so check out the <a href="http://wordpress.org/docs/installation/5-minute/">Wordpress 5 Minute Install</a> if you need some help with that (if you are having any issues with the install, feel free to ask me).</p>
<blockquote><p>By the way, we&#8217;ll be using Wordpress 2.5.1, the shiny new version of this beautiful platform.</p></blockquote>
<p><span id="more-295"></span></p>
<p style="border-bottom:1px dotted #777777;">
<h3><strong>Wp-Theme Structure: Your Main Page</strong></h3>
<p style="padding-left: 30px;"><strong>style.css:<br />
</strong>This is your CSS stylesheet for your WP theme.  If you&#8217;re not familiar, CSS (Cascading Style Sheets) is a way to define the font, layout, design of your website.  CSS is great because you can use one document to set the style of your entire site. Thus, if you want to change the color of all the links on your entire site, you can just change the CSS link tag. <a href="http://w3schools.com/css/default.asp">W3schools is a great resouce</a>. Maybe we&#8217;ll do a css tutorial some time too.</p>
<p style="padding-left: 30px;"><strong>header.php:<br />
</strong>Header.php contains your posts meta tag and title information, links to stylesheets, rss information, and links to javascript. It also contains your header image and the top of your container (Page) &lt;div&gt; (which sets the border around your page, as well as other things such as size, positioning, etc.).<strong><br />
</strong></p>
<p style="padding-left: 30px;"><strong>index.php:<br />
</strong>This is the main body of the page that someone sees when they go to www.[Your Web Page].com/[WP Folder].  It contains includes for the header, sidebar, and footer.</p>
<p style="padding-left: 30px;">Index.php also contains the heart of a WP page: <strong>The Loop</strong>.  The loop is what WP uses to show posts, and information associated with posts, such as the author, tags, metadata.  By editing the loop you can make WP do all sorts of neat and helpful things.</p>
<p style="padding-left: 30px;"><strong>sidebar.php:<br />
</strong>The sidebar contains all of your navigation in the default theme (we&#8217;ll be changing this as we go).  It includes your searchform, login and administrative links, and gives you the option to display lists of categories, authors, archives, and links. There are also areas in the sidebar that display specific information depending on the page you are on.</p>
<p style="padding-left: 60px;"><strong>searchform.php:<br />
</strong>Searchform is exactly what it says.  It is the form that holds your search field and button.</p>
<p style="padding-left: 30px;"><strong>footer.php:<br />
</strong>By default this<strong> </strong>file closes your container (Page) &lt;div&gt;.  It also includes post and comments rss a link to wordpress.org (a nice thing to keep).</p>
<p>Press on to the next page: Individual Posts, Archives, and Search Results</p>
]]></content:encoded>
			<wfw:commentRss>http://www.clickpopmedia.com/2008/05/06/default-wordpress-to-wonderful/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

