<?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/"
	>

<channel>
	<title>Flash Game Guide</title>
	<atom:link href="http://www.jimburrows.net/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.jimburrows.net/blog</link>
	<description>A guide to developing games in flash</description>
	<pubDate>Mon, 22 Dec 2008 09:24:14 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Code Tip: Declaring Variables Locally</title>
		<link>http://www.jimburrows.net/blog/?p=70</link>
		<comments>http://www.jimburrows.net/blog/?p=70#comments</comments>
		<pubDate>Mon, 22 Dec 2008 09:22:37 +0000</pubDate>
		<dc:creator>Jim Burrows</dc:creator>
		
		<category><![CDATA[Resources]]></category>

		<guid isPermaLink="false">http://www.jimburrows.net/blog/?p=70</guid>
		<description><![CDATA[When declaring a variable, it's good practice to declare it as locally as possible.  For instance, if you have a function that uses a variable, it's best to declare the variable within that function.
bad code:
var count:int;
function badCode&#40;&#41;:void&#123;
     for&#40;var i:int=0; i&#60;100; i++&#41;&#123;
          [...]]]></description>
			<content:encoded><![CDATA[<p>When declaring a variable, it's good practice to declare it as locally as possible.  For instance, if you have a function that uses a variable, it's best to declare the variable within that function.</p>
<p>bad code:
<pre class="actionscript"><span style="color: #000000; font-weight: bold;">var</span> count:<span style="color: #0066CC;">int</span>;
<span style="color: #000000; font-weight: bold;">function</span> badCode<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
     <span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;">0</span>; i&lt;<span style="color: #cc66cc;">100</span>; i++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
          count=i;
     <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre>
<p>good code:
<pre class="actionscript"><span style="color: #000000; font-weight: bold;">function</span> goodCode<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
     <span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;">0</span>; i&lt;<span style="color: #cc66cc;">100</span>; i++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
          <span style="color: #000000; font-weight: bold;">var</span> count=i;
     <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre>
<p>In the second example, the variable "count" is declared and initialized locally within the function.  Because of this, "count" will get garbage collected when the function is done running.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jimburrows.net/blog/?feed=rss2&amp;p=70</wfw:commentRss>
		</item>
		<item>
		<title>Massively Multiplayer Online Gaming</title>
		<link>http://www.jimburrows.net/blog/?p=63</link>
		<comments>http://www.jimburrows.net/blog/?p=63#comments</comments>
		<pubDate>Sat, 20 Dec 2008 21:12:19 +0000</pubDate>
		<dc:creator>Jim Burrows</dc:creator>
		
		<category><![CDATA[Games]]></category>

		<category><![CDATA[Resources]]></category>

		<category><![CDATA[AS3]]></category>

		<category><![CDATA[Flash]]></category>

		<category><![CDATA[Massively Multiplayer Online Gaming]]></category>

		<category><![CDATA[MMO]]></category>

		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.jimburrows.net/blog/?p=63</guid>
		<description><![CDATA[I found this tutorial on gotoandplay.com about creating a massively multiplayer online game.  It's a great read for more advanced users:
MMOs
]]></description>
			<content:encoded><![CDATA[<p>I found this tutorial on gotoandplay.com about creating a massively multiplayer online game.  It's a great read for more advanced users:<br />
<a href="http://www.gotoandplay.it/_articles/2007/07/building_mmo.php">MMOs</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jimburrows.net/blog/?feed=rss2&amp;p=63</wfw:commentRss>
		</item>
		<item>
		<title>Song Drop of the Day 12/20</title>
		<link>http://www.jimburrows.net/blog/?p=46</link>
		<comments>http://www.jimburrows.net/blog/?p=46#comments</comments>
		<pubDate>Sat, 20 Dec 2008 09:29:00 +0000</pubDate>
		<dc:creator>Jim Burrows</dc:creator>
		
		<category><![CDATA[Songs]]></category>

		<category><![CDATA[Ace]]></category>

		<category><![CDATA[Bittersweet]]></category>

		<category><![CDATA[Enders]]></category>

		<category><![CDATA[MP3]]></category>

		<category><![CDATA[Song]]></category>

		<category><![CDATA[Symphony]]></category>

		<guid isPermaLink="false">http://www.jimburrows.net/blog/?p=46</guid>
		<description><![CDATA[Since listening to music is such a HUGE part of my AS3 coding experiences, I've decided to add a "Song Drop of the Day" category.  I'll add a new song to stream everyday - usually something that gets me excited to code.  Hope you enjoy my first entry.











Ace Enders - Bittersweet Symphony
]]></description>
			<content:encoded><![CDATA[<p>Since listening to music is such a HUGE part of my AS3 coding experiences, I've decided to add a "Song Drop of the Day" category.  I'll add a new song to stream everyday - usually something that gets me excited to code.  Hope you enjoy my first entry.<br />
<object width='250' height='20'>
<param name='src' value='http://www.jimburrows.net/blog/mp3/Bittersweet.mp3'>
<param name='type' value='audio/mpeg'>
<param name='autostart' value='0'>
<param name='showcontrols' value='1'>
<param name='showstatusbar' value='1'>
<param name='loop' value='false'>
<param name='volume' value='50'>
<embed src ='http://www.jimburrows.net/blog/mp3/Bittersweet.mp3' type='audio/mpeg' autoplay='false' autostart='0' width='250' height='20' controller='1' showstatusbar='1' PlayCount ='1' volume='50' loop='false' bgcolor='#000000' kioskmode='true'>
</embed></object>
<br />
Ace Enders - Bittersweet Symphony</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jimburrows.net/blog/?feed=rss2&amp;p=46</wfw:commentRss>
<enclosure url="http://www.jimburrows.net/blog/mp3/Bittersweet.mp3" length="5485018" type="audio/mpeg" />
<enclosure url="http://jimburrows.net/blog/mp3/Bittersweet.mp3" length="5485018" type="audio/mpeg" />
		</item>
		<item>
		<title>Breakout</title>
		<link>http://www.jimburrows.net/blog/?p=18</link>
		<comments>http://www.jimburrows.net/blog/?p=18#comments</comments>
		<pubDate>Mon, 15 Dec 2008 21:19:34 +0000</pubDate>
		<dc:creator>Jim Burrows</dc:creator>
		
		<category><![CDATA[Games]]></category>

		<category><![CDATA[3]]></category>

		<category><![CDATA[action]]></category>

		<category><![CDATA[Actionscript]]></category>

		<category><![CDATA[AS3]]></category>

		<category><![CDATA[Flash]]></category>

		<category><![CDATA[Game]]></category>

		<category><![CDATA[Guide]]></category>

		<category><![CDATA[script]]></category>

		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.jimburrows.net/blog/?p=18</guid>
		<description><![CDATA[[kml_flashembed movie="http://www.jimburrows.net/blog/Games/Breakout.swf" height="500" width="600" /]
In this tutorial we will focus on creating a very simple, yet popular, arcade game from the past.  I call it Breakout, but I've seen it called by many other names.  The object is to take out all the bricks at the top of the screen by using a [...]]]></description>
			<content:encoded><![CDATA[<p>[kml_flashembed movie="http://www.jimburrows.net/blog/Games/Breakout.swf" height="500" width="600" /]</p>
<p>In this tutorial we will focus on creating a very simple, yet popular, arcade game from the past.  I call it Breakout, but I've seen it called by many other names.  The object is to take out all the bricks at the top of the screen by using a bar located at the bottom of the screen to deflect a ball back up to the top to take out bricks.  The round ends when all bricks have been cleared.  The game ends when the ball goes through the bottom of the screen.  I'll start out by showing the code in full, and then I'll break it down and explain the working parts.</p>
<p><span id="more-18"></span></p>
<p>Full Code:</p>
<pre class="actionscript"><span style="color: #000000; font-weight: bold;">var</span> _left, _right:<span style="color: #0066CC;">Boolean</span>=<span style="color: #000000; font-weight: bold;">false</span>;
<span style="color: #000000; font-weight: bold;">var</span> movementspeed:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">0</span>;
<span style="color: #000000; font-weight: bold;">var</span> MAXMOVEMENTSPEED:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;">10</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> brickarray:<span style="color: #0066CC;">Array</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> numberofcolumns:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;">6</span>;
<span style="color: #000000; font-weight: bold;">var</span> numberofrows:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;">4</span>;
<span style="color: #000000; font-weight: bold;">var</span> brickcount:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;">0</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> ballmovementspeedX:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">9</span>+<span style="color: #0066CC;">round</span>;
<span style="color: #000000; font-weight: bold;">var</span> ballmovementspeedY:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">9</span>+<span style="color: #0066CC;">round</span>;
<span style="color: #000000; font-weight: bold;">var</span> ballvelocity:<span style="color: #0066CC;">Number</span> = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sqrt</span><span style="color: #66cc66;">&#40;</span>ballmovementspeedX*ballmovementspeedX+ballmovementspeedY*ballmovementspeedY<span style="color: #66cc66;">&#41;</span>;
&nbsp;
ball.<span style="color: #006600;">x</span>=<span style="color: #cc66cc;">300</span>;
ball.<span style="color: #006600;">y</span>=<span style="color: #cc66cc;">457</span>;
bar.<span style="color: #006600;">x</span>=<span style="color: #cc66cc;">300</span>;
bar.<span style="color: #006600;">y</span>=<span style="color: #cc66cc;">492</span>;
bar.<span style="color: #0066CC;">width</span>=<span style="color: #cc66cc;">125</span>-<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>round<span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">&#41;</span>*<span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">/***********Brick Placement************/</span>
<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;">0</span>; i&lt;numberofrows; i++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> j:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;">0</span>; j&lt;numberofcolumns; j++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">var</span> brick:Brick = <span style="color: #000000; font-weight: bold;">new</span> Brick<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        container_mc.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>brick<span style="color: #66cc66;">&#41;</span>;
        brick.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">30</span>+<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span>+brick.<span style="color: #0066CC;">width</span><span style="color: #66cc66;">&#41;</span>*j;
        brick.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">30</span>+<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">5</span>+brick.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span>*i;
        brickarray.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>brick<span style="color: #66cc66;">&#41;</span>;
		brickcount++;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**************Round Start*************/</span>
ball.<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>KeyboardEvent.<span style="color: #006600;">KEY_DOWN</span>, startBall<span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">function</span> startBall<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:KeyboardEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">keyCode</span>==Keyboard.<span style="color: #0066CC;">SPACE</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		addEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, playGame<span style="color: #66cc66;">&#41;</span>;
		bar.<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>KeyboardEvent.<span style="color: #006600;">KEY_DOWN</span>, keyPressed<span style="color: #66cc66;">&#41;</span>;
		bar.<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>KeyboardEvent.<span style="color: #006600;">KEY_UP</span>, keyReleased<span style="color: #66cc66;">&#41;</span>;
		addEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, moveTheBar<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/********************************************************
*********Three Event Listeners For Bar Movement**********
********************************************************/</span>
<span style="color: #000000; font-weight: bold;">function</span> keyPressed<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:KeyboardEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">keyCode</span>==Keyboard.<span style="color: #0066CC;">LEFT</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		_left=<span style="color: #000000; font-weight: bold;">true</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">keyCode</span>==Keyboard.<span style="color: #0066CC;">RIGHT</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		_right=<span style="color: #000000; font-weight: bold;">true</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> keyReleased<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:KeyboardEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">keyCode</span>==Keyboard.<span style="color: #0066CC;">LEFT</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		_left=<span style="color: #000000; font-weight: bold;">false</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">keyCode</span>==Keyboard.<span style="color: #0066CC;">RIGHT</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		_right=<span style="color: #000000; font-weight: bold;">false</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> moveTheBar<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>_left==<span style="color: #000000; font-weight: bold;">false</span> &amp;<span style="color: #808080; font-style: italic;">#038;&amp;#038; _right==false){</span>
		movementspeed/=<span style="color: #cc66cc;">1.1</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>_left==<span style="color: #000000; font-weight: bold;">true</span> &amp;<span style="color: #808080; font-style: italic;">#038;&amp;#038; movementspeed&gt;=MAXMOVEMENTSPEED/-1+.8){</span>
		movementspeed-=.<span style="color: #cc66cc;">8</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>_right==<span style="color: #000000; font-weight: bold;">true</span> &amp;<span style="color: #808080; font-style: italic;">#038;&amp;#038; movementspeed&lt;=MAXMOVEMENTSPEED-.8){</span>
		movementspeed+=.<span style="color: #cc66cc;">8</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>bar.<span style="color: #006600;">x</span>&lt;bar.<span style="color: #0066CC;">width</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		bar.<span style="color: #006600;">x</span>=bar.<span style="color: #0066CC;">width</span>/<span style="color: #cc66cc;">2</span>+.<span style="color: #cc66cc;">1</span>;
		movementspeed=<span style="color: #cc66cc;">0</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>bar.<span style="color: #006600;">x</span>&gt;stage.<span style="color: #006600;">stageWidth</span>-bar.<span style="color: #0066CC;">width</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		bar.<span style="color: #006600;">x</span>=<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span>-bar.<span style="color: #0066CC;">width</span>/<span style="color: #cc66cc;">2</span>-.<span style="color: #cc66cc;">1</span>;
		movementspeed=<span style="color: #cc66cc;">0</span>;
	<span style="color: #66cc66;">&#125;</span>
	bar.<span style="color: #006600;">x</span>+=movementspeed;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/***************************************************
*********************Game Play**********************
***************************************************/</span>
<span style="color: #000000; font-weight: bold;">function</span> playGame<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;">0</span>; i&lt;brickarray.<span style="color: #0066CC;">length</span>; i++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>brickarray<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">leftBrick</span>.<span style="color: #006600;">hitTestObject</span><span style="color: #66cc66;">&#40;</span>ball<span style="color: #66cc66;">&#41;</span> || brickarray<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">rightBrick</span>.<span style="color: #006600;">hitTestObject</span><span style="color: #66cc66;">&#40;</span>ball<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			container_mc.<span style="color: #006600;">removeChild</span><span style="color: #66cc66;">&#40;</span>brickarray<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
			brickarray.<span style="color: #0066CC;">splice</span><span style="color: #66cc66;">&#40;</span>i,<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
			ballmovementspeedX/=<span style="color: #cc66cc;">-1</span>;
			brickcount--;
			score+=<span style="color: #cc66cc;">10</span>*<span style="color: #0066CC;">round</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>brickarray<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">bottomBrick</span>.<span style="color: #006600;">hitTestObject</span><span style="color: #66cc66;">&#40;</span>ball<span style="color: #66cc66;">&#41;</span> || brickarray<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">topBrick</span>.<span style="color: #006600;">hitTestObject</span><span style="color: #66cc66;">&#40;</span>ball<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			container_mc.<span style="color: #006600;">removeChild</span><span style="color: #66cc66;">&#40;</span>brickarray<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
			brickarray.<span style="color: #0066CC;">splice</span><span style="color: #66cc66;">&#40;</span>i,<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
			ballmovementspeedY/=<span style="color: #cc66cc;">-1</span>;
			brickcount--;
			score+=<span style="color: #cc66cc;">10</span>*<span style="color: #0066CC;">round</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>ball.<span style="color: #006600;">hitTestObject</span><span style="color: #66cc66;">&#40;</span>bar<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		ballmovementspeedX=<span style="color: #66cc66;">&#40;</span>ball.<span style="color: #006600;">x</span>-bar.<span style="color: #006600;">x</span><span style="color: #66cc66;">&#41;</span>/<span style="color: #66cc66;">&#40;</span>bar.<span style="color: #0066CC;">width</span><span style="color: #66cc66;">&#41;</span>*ballvelocity;
		ballmovementspeedY=<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sqrt</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">abs</span><span style="color: #66cc66;">&#40;</span>ballvelocity*ballvelocity-ballmovementspeedX*ballmovementspeedX<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>ball.<span style="color: #006600;">x</span>&lt;ball.<span style="color: #0066CC;">width</span>/<span style="color: #cc66cc;">2</span> || ball.<span style="color: #006600;">x</span>&gt;stage.<span style="color: #006600;">stageWidth</span>-ball.<span style="color: #0066CC;">width</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		ballmovementspeedX/=<span style="color: #cc66cc;">-1</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>ball.<span style="color: #006600;">y</span>&lt;ball.<span style="color: #0066CC;">height</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		ballmovementspeedY/=<span style="color: #cc66cc;">-1</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>ball.<span style="color: #006600;">y</span>&gt;stage.<span style="color: #006600;">stageHeight</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		removeEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, playGame<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">gotoAndStop</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>brickcount==<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		removeEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, playGame<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">gotoAndStop</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	ball.<span style="color: #006600;">x</span>+=ballmovementspeedX;
	ball.<span style="color: #006600;">y</span>-=ballmovementspeedY;
	scoreText.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;Score: &quot;</span> + score;
&nbsp;
<span style="color: #66cc66;">&#125;</span></pre>
<p>Alright Let's break this down:</p>
<pre class="actionscript"><span style="color: #000000; font-weight: bold;">var</span> _left, _right:<span style="color: #0066CC;">Boolean</span>=<span style="color: #000000; font-weight: bold;">false</span>;
<span style="color: #000000; font-weight: bold;">var</span> movementspeed:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">0</span>;
<span style="color: #000000; font-weight: bold;">var</span> MAXMOVEMENTSPEED:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;">10</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> brickarray:<span style="color: #0066CC;">Array</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> numberofcolumns:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;">6</span>;
<span style="color: #000000; font-weight: bold;">var</span> numberofrows:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;">4</span>;
<span style="color: #000000; font-weight: bold;">var</span> brickcount:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;">0</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> ballmovementspeedX:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">9</span>+<span style="color: #0066CC;">round</span>;
<span style="color: #000000; font-weight: bold;">var</span> ballmovementspeedY:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">9</span>+<span style="color: #0066CC;">round</span>;
<span style="color: #000000; font-weight: bold;">var</span> ballvelocity:<span style="color: #0066CC;">Number</span> = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sqrt</span><span style="color: #66cc66;">&#40;</span>ballmovementspeedX*ballmovementspeedX+ballmovementspeedY*ballmovementspeedY<span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>Here we declare our variables, no big surprise here.  movementspeed controls our bar's speed, and ballmovementspeedX,Y controls our ball's speed, obviously.  If you notice, the initial ballmovementspeed will be 10(9+round).  The subsequent rounds after that will each increase the ball's speed by 1, making each round more difficult than the last.  The only tricky one here is ballvelocity.  If you're familiar with the pythagorean theorem, that is how ballvelocity is derived.  Later on, you will see how that ensures that the ball maintains the same velocity no matter what part of the bar it hits.</p>
<pre class="actionscript">&nbsp;
ball.<span style="color: #006600;">x</span>=<span style="color: #cc66cc;">300</span>;
ball.<span style="color: #006600;">y</span>=<span style="color: #cc66cc;">457</span>;
bar.<span style="color: #006600;">x</span>=<span style="color: #cc66cc;">300</span>;
bar.<span style="color: #006600;">y</span>=<span style="color: #cc66cc;">492</span>;
bar.<span style="color: #0066CC;">width</span>=<span style="color: #cc66cc;">125</span>-<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>round<span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">&#41;</span>*<span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>Here, we initialize properties of both the ball and the bar.  Since this is a multi round game, I want these values to be re-initialized after each round, so this code is added.  Without this code, the ball and the bar would start the next round where they left off the previous round.  The last line of code here is for game difficulty.  The bar's width starts out at 125 in the first round, and each round after that it shrinks by 5 pixels.</p>
<pre class="actionscript">&nbsp;
<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;">0</span>; i&lt;numberofrows; i++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> j:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;">0</span>; j&lt;numberofcolumns; j++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">var</span> brick:Brick = <span style="color: #000000; font-weight: bold;">new</span> Brick<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
                container_mc.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>brick<span style="color: #66cc66;">&#41;</span>;
                brick.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">30</span>+<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span>+brick.<span style="color: #0066CC;">width</span><span style="color: #66cc66;">&#41;</span>*j;
                brick.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">30</span>+<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">5</span>+brick.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span>*i;
                brickarray.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>brick<span style="color: #66cc66;">&#41;</span>;
		brickcount++;
      <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre>
<p>First off, for this to work, I had to make a movieclip of a brick.  If you go to the library and right click on that movieclip, and select "properties," there is an option to Export for Actionscript.  Check that box, and now we can reference that brick without ever putting it onto the stage.  I gave mine a class name of "Brick."  In this double for loop, every iteration will create a new Brick with the instance name of "brick."  Once a brick is created, it needs to be added to the stage.  That is handled with the addChild method.  You can add them directly to the next open layer in the stage by just using addChild(brick), but I wanted to put them all in one movieclip, in case I ever wanted to remove them all at once.  brick.x and brick.y control where each brick is placed.  The brick is then pushed into our array so that it can be easily accessed later for collision detection.  Lastly, the brickcount variable is incremented so that we can keep track of how many bricks are on the stage.</p>
<pre class="actionscript">&nbsp;
ball.<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>KeyboardEvent.<span style="color: #006600;">KEY_DOWN</span>, startBall<span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">function</span> startBall<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:KeyboardEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">keyCode</span>==Keyboard.<span style="color: #0066CC;">SPACE</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		addEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, playGame<span style="color: #66cc66;">&#41;</span>;
		bar.<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>KeyboardEvent.<span style="color: #006600;">KEY_DOWN</span>, keyPressed<span style="color: #66cc66;">&#41;</span>;
		bar.<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>KeyboardEvent.<span style="color: #006600;">KEY_UP</span>, keyReleased<span style="color: #66cc66;">&#41;</span>;
		addEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, moveTheBar<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre>
<p>This is pretty self explanatory as well.  I wanted the ball to start moving when the Spacebar is hit, so I added a listener for that.  When the spacebar is hit, all of the other listeners are then invoked.  This presents the user from doing anything until the spacebar is clicked.</p>
<pre class="actionscript">&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> keyPressed<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:KeyboardEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">keyCode</span>==Keyboard.<span style="color: #0066CC;">LEFT</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		_left=<span style="color: #000000; font-weight: bold;">true</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">keyCode</span>==Keyboard.<span style="color: #0066CC;">RIGHT</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		_right=<span style="color: #000000; font-weight: bold;">true</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> keyReleased<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:KeyboardEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">keyCode</span>==Keyboard.<span style="color: #0066CC;">LEFT</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		_left=<span style="color: #000000; font-weight: bold;">false</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">keyCode</span>==Keyboard.<span style="color: #0066CC;">RIGHT</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		_right=<span style="color: #000000; font-weight: bold;">false</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre>
<p>Now I'll go over each of the three bar movement functions.  The first two just "listen" for when the left and right arrows are pressed down or released.  Our two boolean values, _left and _right, are set accordingly.  The last function has all the controls, we'll break that down in pieces:</p>
<pre class="actionscript">&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> moveTheBar<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>_left==<span style="color: #000000; font-weight: bold;">false</span> &amp;<span style="color: #808080; font-style: italic;">#038;&amp;#038; _right==false){</span>
		movementspeed/=<span style="color: #cc66cc;">1.1</span>;
	<span style="color: #66cc66;">&#125;</span></pre>
<p>This if statement checks if none of the keys are being pressed.  When that is true, the movementspeed of the bar is continually divided by 1.1.  This gives it that "slowing down" effect when no keys are pressed.</p>
<pre class="actionscript">&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>_left==<span style="color: #000000; font-weight: bold;">true</span> &amp;<span style="color: #808080; font-style: italic;">#038;&amp;#038; movementspeed&gt;=MAXMOVEMENTSPEED/-1+.8){</span>
		movementspeed-=.<span style="color: #cc66cc;">8</span>;
	<span style="color: #66cc66;">&#125;</span></pre>
<p>This IF statement is executed when the left arrow key is held down.  For each frame that the left arrow is held down, movementspeed is decremented by .8.  This way, the bar doesnt automatically stop and move full speed to the left when the left arrow is down.  If the bar is quickly going to the right, it will first slow down, stop, and then accelerate to the left.</p>
<pre class="actionscript">&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>_right==<span style="color: #000000; font-weight: bold;">true</span> &amp;<span style="color: #808080; font-style: italic;">#038;&amp;#038; movementspeed&lt;=MAXMOVEMENTSPEED-.8){</span>
		movementspeed+=.<span style="color: #cc66cc;">8</span>;
	<span style="color: #66cc66;">&#125;</span></pre>
<p>Same thing as with the left.</p>
<pre class="actionscript"><span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>bar.<span style="color: #006600;">x</span>&lt;bar.<span style="color: #0066CC;">width</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		bar.<span style="color: #006600;">x</span>=bar.<span style="color: #0066CC;">width</span>/<span style="color: #cc66cc;">2</span>+.<span style="color: #cc66cc;">1</span>;
		movementspeed=<span style="color: #cc66cc;">0</span>;
	<span style="color: #66cc66;">&#125;</span></pre>
<p>This IF statement makes sure the bar can't go off the stage to the left.  When it reaches a certain point, it's like hitting a wall, and the movementspeed is set to 0.  Adding the .1 is very important here, otherwise the bar would just be stuck on the left wall forever.  By adding the .1, it basically "pushes" the bar off the wall.</p>
<pre class="actionscript"><span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>bar.<span style="color: #006600;">x</span>&gt;stage.<span style="color: #006600;">stageWidth</span>-bar.<span style="color: #0066CC;">width</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		bar.<span style="color: #006600;">x</span>=<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span>-bar.<span style="color: #0066CC;">width</span>/<span style="color: #cc66cc;">2</span>-.<span style="color: #cc66cc;">1</span>;
		movementspeed=<span style="color: #cc66cc;">0</span>;
	<span style="color: #66cc66;">&#125;</span></pre>
<p>Same thing we did for the left wall, we do for the right wall.</p>
<pre class="actionscript">bar.<span style="color: #006600;">x</span>+=movementspeed;
<span style="color: #66cc66;">&#125;</span></pre>
<p>In this one line, we tell the bar to constantly be moving at a rate of "movementspeed."  If movement speed is positive, the bar will move to the right.  If it's negative, to the left.</p>
<p>Lastly is our giant Game Play function.  I will break that up into pieces:</p>
<pre class="actionscript">&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> playGame<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;">0</span>; i&lt;brickarray.<span style="color: #0066CC;">length</span>; i++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>brickarray<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">leftBrick</span>.<span style="color: #006600;">hitTestObject</span><span style="color: #66cc66;">&#40;</span>ball<span style="color: #66cc66;">&#41;</span> || brickarray<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">rightBrick</span>.<span style="color: #006600;">hitTestObject</span><span style="color: #66cc66;">&#40;</span>ball<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			container_mc.<span style="color: #006600;">removeChild</span><span style="color: #66cc66;">&#40;</span>brickarray<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
			brickarray.<span style="color: #0066CC;">splice</span><span style="color: #66cc66;">&#40;</span>i,<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
			ballmovementspeedX/=<span style="color: #cc66cc;">-1</span>;
			brickcount--;
			score+=<span style="color: #cc66cc;">10</span>*<span style="color: #0066CC;">round</span>;
		<span style="color: #66cc66;">&#125;</span></pre>
<p>Before I begin, I must add that within the movieclip of each brick, I have 4 invisible movieclips, named leftBrick, rightBrick, bottomBrick, topBrick.  These are basically 4 lines that go around the perimeter of the brick, and are used for collision detection.  So in this first IF statement, I check for when the ball has collided with the left or right side of one of the bricks.  Since this is an ENTER_FRAME listener, the for loop is constantly searching through the brickarray for when one of of its bricks is hit by the ball.  When this occurs, the brick is first removed.  The next line of code is very important.  Since a brick was removed from our array, we don't want there to be an open spot in the brick array that our for loop will be checking.  The splice method will take care of that.  It takes in two parameters.  The first tells where at in brickarray to start removing from, and the second parameter is for how many to remove from that starting point.  We only want that one brick to be removed, so our position is "i" and only 1.  This will shift the positions of the array that were above that down, and decrement brickarray.length by one.  Next, we want the ball to change directions, so by dividing it by negative one, we keep the same speed, just in a different direction.  brickcount is then decremented so we can keep track of how many bricks are left on the stage.  Lastly, our score is updated.</p>
<pre class="actionscript">&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>brickarray<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">bottomBrick</span>.<span style="color: #006600;">hitTestObject</span><span style="color: #66cc66;">&#40;</span>ball<span style="color: #66cc66;">&#41;</span> || brickarray<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">topBrick</span>.<span style="color: #006600;">hitTestObject</span><span style="color: #66cc66;">&#40;</span>ball<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			container_mc.<span style="color: #006600;">removeChild</span><span style="color: #66cc66;">&#40;</span>brickarray<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
			brickarray.<span style="color: #0066CC;">splice</span><span style="color: #66cc66;">&#40;</span>i,<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
			ballmovementspeedY/=<span style="color: #cc66cc;">-1</span>;
			brickcount--;
			score+=<span style="color: #cc66cc;">10</span>*<span style="color: #0066CC;">round</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span></pre>
<p>This IF statement is pretty much the same as the previous one, however this one checks for collision between the ball and the bottom and top of the brick.  The only difference here is that the Y direction is reversed, instead of the X direction.</p>
<pre class="actionscript">&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>ball.<span style="color: #006600;">hitTestObject</span><span style="color: #66cc66;">&#40;</span>bar<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		ballmovementspeedX=<span style="color: #66cc66;">&#40;</span>ball.<span style="color: #006600;">x</span>-bar.<span style="color: #006600;">x</span><span style="color: #66cc66;">&#41;</span>/<span style="color: #66cc66;">&#40;</span>bar.<span style="color: #0066CC;">width</span><span style="color: #66cc66;">&#41;</span>*ballvelocity;
		ballmovementspeedY=<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sqrt</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">abs</span><span style="color: #66cc66;">&#40;</span>ballvelocity*ballvelocity-ballmovementspeedX*ballmovementspeedX<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span></pre>
<p>In this IF statement, we check for when the ball hits the bar.  The first line of code checks where at on the bar the ball hit, and accordingly sends the ball off in that direction.  That same line of code is basically getting a percentage of the ballvelocity based on what part of the bar it hit.  The further away from the center of the bar the ball hits, the higher the ballmovementspeedX will be.  The second line of code takes into effect our ballvelocity that we declared from the top.  Once again, we use the pythagorean theorem to determine the ballmovementspeedY.  This maintains the same ball velocity through the entire round, no matter what part of the bar the ball hits.</p>
<pre class="actionscript">&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>ball.<span style="color: #006600;">x</span>&lt;ball.<span style="color: #0066CC;">width</span>/<span style="color: #cc66cc;">2</span> || ball.<span style="color: #006600;">x</span>&gt;stage.<span style="color: #006600;">stageWidth</span>-ball.<span style="color: #0066CC;">width</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		ballmovementspeedX/=<span style="color: #cc66cc;">-1</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>ball.<span style="color: #006600;">y</span>&lt;ball.<span style="color: #0066CC;">height</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		ballmovementspeedY/=<span style="color: #cc66cc;">-1</span>;
	<span style="color: #66cc66;">&#125;</span></pre>
<p>These two IF statements check when the ball has "hit" either the left, right, or top walls of the game.  When this occurs, the balls direction is changed accordingly.</p>
<pre class="actionscript">&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>ball.<span style="color: #006600;">y</span>&gt;stage.<span style="color: #006600;">stageHeight</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		removeEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, playGame<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">gotoAndStop</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span></pre>
<p>Just like the previous IF statements, this one checks if the ball has "hit" the bottom wall of the game.  However, in this case, the game is over.  I still it go to and stop on frame 4 of my movie, where I have a little Game Over screen.</p>
<pre class="actionscript">&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>brickcount==<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		removeEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, playGame<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">gotoAndStop</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span></pre>
<p>Here we check for when all the bricks are gone.  In this case, the round is over, and we can continue to Frame 3 where we have a "Round Over" screen.  We have to remove our event listener for playGame, otherwise the .swf will still be continuously checking for all this IF conditions.  But don't worry, it's added back on at the beginning of each round.</p>
<pre class="actionscript">&nbsp;
	ball.<span style="color: #006600;">x</span>+=ballmovementspeedX;
	ball.<span style="color: #006600;">y</span>-=ballmovementspeedY;</pre>
<p>Similar to our bar movement, this just continuously updates the position of our ball.</p>
<pre class="actionscript">&nbsp;
scoreText.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;Score: &quot;</span> + score;</pre>
<p>Last, but certainly not least, our score is updated.  I created a dynamic textbox at the top of the stage that I gave an instance name of "scoreText" to.  Make sure if you're using dynamic text boxes that you embed whatever font you're using.</p>
<p>Side Note: On frame 1 of my .fla, I declared these two variables:</p>
<pre class="actionscript"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">round</span>:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;">1</span>;
<span style="color: #000000; font-weight: bold;">var</span> score:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;">0</span>;</pre>
<p>I declared these on frame one, because I didn't want them to be reinitialized at the beginning of each round.  They will only get reinitialized when a new game is started.</p>
<p>Please, leave me any questions or comments about this.  I am open to all criticisms.  If you have a request to add some other functionality to it, let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jimburrows.net/blog/?feed=rss2&amp;p=18</wfw:commentRss>
		</item>
	</channel>
</rss>
