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

<channel>
	<title>manewc</title>
	<atom:link href="http://manewc.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://manewc.com</link>
	<description>Actionscript Snippets</description>
	<pubDate>Wed, 27 Aug 2008 16:34:34 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>Flash Back!</title>
		<link>http://manewc.com/2008/08/27/flash-back/</link>
		<comments>http://manewc.com/2008/08/27/flash-back/#comments</comments>
		<pubDate>Wed, 27 Aug 2008 16:32:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://manewc.com/?p=183</guid>
		<description><![CDATA[ So I started to work on a project for friend of mine, she is really into designer handmade knits and clothes, anyways, while I was digging through some archived files, I came across this game.. which I never finished.. but it was one of my favorites - built with Flash MX.
You can check out [...]]]></description>
			<content:encoded><![CDATA[<p><img style="float: left; margin: 0 10px 10px 0" title="ico_flash" src="http://manewc.com/wp-content/uploads/2008/08/ico_flash.gif" alt="" width="60" height="60" /> So I started to work on a project for friend of mine, she is really into <a href="http://knitters-delight.blogspot.com" onclick="javascript:pageTracker._trackPageview ('/outbound/knitters-delight.blogspot.com');">designer handmade knits and clothes</a>, anyways, while I was digging through some archived files, I came across this game.. which I never finished.. but it was one of my favorites - built with Flash MX.</p>
<p><a href="http://manewc.com/projects/games/dive/dive.shtml">You can check out my diving game here - just click the jump button when the skeleton is moving fast</a></p>
<p class="addtoany_share_save">
    <a class=".addtoany_share_save" name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/share_save?sitename=manewc&amp;siteurl=http%3A%2F%2Fmanewc.com%2F&amp;linkname=Flash%20Back%21&amp;linkurl=http%3A%2F%2Fmanewc.com%2F2008%2F08%2F27%2Fflash-back%2F"><img src="http://manewc.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="Flash Back!";
		a2a_linkurl="http://manewc.com/2008/08/27/flash-back/";
						a2a_color_main="D7E5ED";a2a_color_border="AECADB";a2a_color_link_text="333333";a2a_color_link_text_hover="333333";    </script>
    <script type="text/javascript" src="http://static.addtoany.com/menu/page.js"></script>

	</p>]]></content:encoded>
			<wfw:commentRss>http://manewc.com/2008/08/27/flash-back/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Google Analytics and AIR</title>
		<link>http://manewc.com/2008/08/26/google-analytics-and-air/</link>
		<comments>http://manewc.com/2008/08/26/google-analytics-and-air/#comments</comments>
		<pubDate>Tue, 26 Aug 2008 17:36:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[AIR]]></category>

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

		<guid isPermaLink="false">http://manewc.com/?p=182</guid>
		<description><![CDATA[So I thought I would take my old post of finding the median value of my Google Analytics and convert this to an Adobe AIR application. Here is the old post.
Here is the code I am beginning with:
&#60;?xml version=&#34;1.0&#34; encoding=&#34;utf-8&#34;?&#62;
  &#60;mx:WindowedApplication xmlns:mx=&#34;http://www.adobe.com/2006/mxml&#34; layout=&#34;absolute&#34; width=&#34;800&#34; height=&#34;800&#34;&#62;
  &#60;mx:Script&#62;
  &#60;![CDATA[
  import flash.filesystem.FileMode;
  import [...]]]></description>
			<content:encoded><![CDATA[<p>So I thought I would take my old post of finding the median value of my Google Analytics and convert this to an Adobe AIR application. <a href="http://manewc.com/2008/04/29/median-chart-of-google-dashboard-analytics-xml-and-yahoo-astra-charts/">Here is the old post.</a></p>
<p>Here is the code I am beginning with:</p>
<p>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br />
  &lt;mx:WindowedApplication xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; layout=&quot;absolute&quot; width=&quot;800&quot; height=&quot;800&quot;&gt;<br />
  &lt;mx:Script&gt;<br />
  &lt;![CDATA[<br />
  import flash.filesystem.FileMode;<br />
  import flash.filesystem.FileStream;<br />
  import flash.filesystem.File;<br />
  import mx.controls.Alert;<br />
  import MedianGraph;</p>
<p>  private function loadGA():void<br />
  {<br />
  if ( !loc.text || loc.text == &quot;Enter Location of XML File&quot;)<br />
  {<br />
  Alert.show (&quot;Please enter location of your Google Analytics file&quot;, &quot;ERROR&quot;);<br />
  }<br />
  else<br />
  {<br />
  // read the file<br />
  var myFile:File = File.documentsDirectory.resolvePath( loc.text );<br />
  var fileStream:FileStream = new FileStream();<br />
  fileStream.open(myFile, FileMode.READ);</p>
<p>  var xml:XML = new XML(fileStream.readUTFBytes(fileStream.bytesAvailable));</p>
<p> var pointList:XMLList = xml.Report.Graph[0].Serie.Point.Value.text();<br />
  var timeList:XMLList =  xml.Report.Graph[0].Serie.Point.Label.text();</p>
<p> var xPoint:Array = new Array;</p>
<p> for each (var graphPoints:XML in pointList)<br />
  {<br />
  xPoint.push( graphPoints );<br />
  }</p>
<p> var tPoint:Array = new Array;</p>
<p> for each (var timePoints:XML in timeList)<br />
  {<br />
  tPoint.push ( timePoints );<br />
  }</p>
<p> var graphArray:Array = new Array;<br />
  for (var c:uint; c &lt; xPoint.length; c++){<br />
  graphArray.push ({point:xPoint[c], time:tPoint[c]})<br />
  }</p>
<p>  // sort the array from lowest to highest<br />
  var medianArray:Array = new Array();<br />
  medianArray = graphArray.sortOn(&quot;point&quot;, Array.NUMERIC);</p>
<p>  // check to see if there is an even or odd numbers in the list<br />
  var evenOdd:uint = medianArray.length%2;<br />
  var medianArrIndex:Number;</p>
<p>  if ( evenOdd == 1 )<br />
  {<br />
  /* odd number */<br />
  /* take the middle value */<br />
  medianArrIndex = medianArray[Math.floor(medianArray.length / 2)].point;<br />
  }<br />
  else<br />
  {<br />
  /* even number */<br />
  /* take the 2 middle numbers, add them together and divide by 2 */<br />
  var middle:Number = medianArray.length / 2;</p>
<p> var lowMiddle:Number = medianArray[middle - 1].point;<br />
  var highMiddle:Number = medianArray[middle].point;<br />
  medianArrIndex = (highMiddle + lowMiddle) / 2;
</p>
<p> var medianPoint:Array = new Array();</p>
<p> /* &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- */<br />
  for (var x:uint; x &lt; medianArray.length; x++)<br />
  {<br />
  medianPoint.push ({point:medianArrIndex, time:tPoint[x]})<br />
  }<br />
  /* &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- */<br />
  }</p>
<p>  Alert.show (&quot;The median point is: &quot; + medianArrIndex);<br />
  fileStream.close();<br />
  }<br />
  }</p>
<p>  private function browseForOpen():void<br />
  {<br />
  var file:File = new File();<br />
  file.addEventListener(Event.SELECT, openHandler);<br />
  file.browseForOpen(&quot;Select a File&quot;);<br />
  }</p>
<p>  private function openHandler(e:Event):void<br />
  {<br />
  loc.text = e.target.nativePath;<br />
  }<br />
  ]]&gt;<br />
  &lt;/mx:Script&gt;<br />
  &lt;mx:TextInput text=&quot;Enter Location of XML File&quot; width=&quot;500&quot; x=&quot;10&quot; y=&quot;3&quot; id=&quot;loc&quot; enter=&quot;loadGA()&quot; /&gt;<br />
  &lt;mx:Button click=&quot;browseForOpen()&quot; label=&quot;Browse for File&quot; x=&quot;511&quot; y=&quot;3&quot; /&gt;<br />
  &lt;mx:Button click=&quot;loadGA()&quot; label=&quot;GO!&quot; x=&quot;650&quot; y=&quot;3&quot; /&gt;<br />
  &lt;/mx:WindowedApplication&gt;</p>
<p class="addtoany_share_save">
    <a class=".addtoany_share_save" name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/share_save?sitename=manewc&amp;siteurl=http%3A%2F%2Fmanewc.com%2F&amp;linkname=Google%20Analytics%20and%20AIR&amp;linkurl=http%3A%2F%2Fmanewc.com%2F2008%2F08%2F26%2Fgoogle-analytics-and-air%2F"><img src="http://manewc.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="Google Analytics and AIR";
		a2a_linkurl="http://manewc.com/2008/08/26/google-analytics-and-air/";
						a2a_color_main="D7E5ED";a2a_color_border="AECADB";a2a_color_link_text="333333";a2a_color_link_text_hover="333333";    </script>
    <script type="text/javascript" src="http://static.addtoany.com/menu/page.js"></script>

	</p>]]></content:encoded>
			<wfw:commentRss>http://manewc.com/2008/08/26/google-analytics-and-air/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Adobe AIR - Select A File</title>
		<link>http://manewc.com/2008/08/25/adobe-air-select-a-file/</link>
		<comments>http://manewc.com/2008/08/25/adobe-air-select-a-file/#comments</comments>
		<pubDate>Mon, 25 Aug 2008 17:35:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[AIR]]></category>

		<guid isPermaLink="false">http://manewc.com/?p=181</guid>
		<description><![CDATA[A simple method to allow the user to select a local file:




	
	
	



    
    
		a2a_linkname="Adobe AIR - Select A File";
		a2a_linkurl="http://manewc.com/2008/08/25/adobe-air-select-a-file/";
						a2a_color_main="D7E5ED";a2a_color_border="AECADB";a2a_color_link_text="333333";a2a_color_link_text_hover="333333";    
    

	]]></description>
			<content:encoded><![CDATA[<p>A simple method to allow the user to select a local file:</p>
<pre name="code" class="c-sharp">
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="800" height="800">
<mx:Script>
	<![CDATA[
		import flash.filesystem.File;
		import mx.controls.Alert;

		private function browseFile():void
		{
			var file:File = new File();
			file.addEventListener(Event.SELECT, openOutput);
			file.browseForOpen("Select a File");
		}

		private function openOutput(e:Event):void
		{
			fileloc.text = e.target.nativePath;
		}
	]]&gt;
</mx:Script>
	<mx:TextInput text="Enter Location of File" width="70%" x="10" y="3" id="fileloc" />
	<mx:Button click="browseFile()" label="Browse for File" x="600" y="3" />
</mx:WindowedApplication>
</pre>
<p class="addtoany_share_save">
    <a class=".addtoany_share_save" name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/share_save?sitename=manewc&amp;siteurl=http%3A%2F%2Fmanewc.com%2F&amp;linkname=Adobe%20AIR%20-%20Select%20A%20File&amp;linkurl=http%3A%2F%2Fmanewc.com%2F2008%2F08%2F25%2Fadobe-air-select-a-file%2F"><img src="http://manewc.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="Adobe AIR - Select A File";
		a2a_linkurl="http://manewc.com/2008/08/25/adobe-air-select-a-file/";
						a2a_color_main="D7E5ED";a2a_color_border="AECADB";a2a_color_link_text="333333";a2a_color_link_text_hover="333333";    </script>
    <script type="text/javascript" src="http://static.addtoany.com/menu/page.js"></script>

	</p>]]></content:encoded>
			<wfw:commentRss>http://manewc.com/2008/08/25/adobe-air-select-a-file/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Trails Animation - Version 2</title>
		<link>http://manewc.com/2008/08/22/trails-animation-version-2/</link>
		<comments>http://manewc.com/2008/08/22/trails-animation-version-2/#comments</comments>
		<pubDate>Fri, 22 Aug 2008 17:15:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Actionscript 3]]></category>

		<guid isPermaLink="false">http://manewc.com/?p=180</guid>
		<description><![CDATA[A new trails animation with a blur effect and a motion of the objects animated towards you. Please note: This is a work in progress and the Main.as file needs to be cleaned up so there aren&#8217;t 2 entries for the image load when the movie clip is duplicated.

<object	type="application/x-shockwave-flash"
			data="/projects/flash/TrailsAnimation2/Main.swf"
			width="700"
			height="700">
	<param name="movie" value="/projects/flash/TrailsAnimation2/Main.swf" />
</object>

package
{
	import flash.display.MovieClip;
	import flash.display.DisplayObject;
	import [...]]]></description>
			<content:encoded><![CDATA[<p>A new trails animation with a blur effect and a motion of the objects animated towards you. <strong>Please note:</strong> This is a work in progress and the Main.as file needs to be cleaned up so there aren&#8217;t 2 entries for the image load when the movie clip is duplicated.</p>

<object	type="application/x-shockwave-flash"
			data="/projects/flash/TrailsAnimation2/Main.swf"
			width="700"
			height="700">
	<param name="movie" value="/projects/flash/TrailsAnimation2/Main.swf" />
</object>
<pre name="code" class="c-sharp">
package
{
	import flash.display.MovieClip;
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.utils.Timer;
	import flash.events.TimerEvent;

	 public class Main extends MovieClip
	 {
		private var clip_arr:Array; // an array of clips
		private var clip_ct:Number = 0;

		private const RADIUS:int=30;
		private const FRICTION:Number=.95;

		public function Main()
		{
			init();
		}

		private function init():void
		{
			stage.frameRate=31;

			clip_arr = new Array();

			var myTimer:Timer = new Timer(5000, 10);
            myTimer.addEventListener("timer", createClip);
            myTimer.start();
		}

		private function createClip(e:TimerEvent):void
		{
			var randXOffset = Math.random() * stage.stageWidth;
			var randYOffset = Math.random() * stage.stageHeight;

			clip_arr.push ( new Image("smiley.png") );

			clip_arr[clip_ct].scaleX = clip_arr[clip_ct].scaleY = 0;
			clip_arr[clip_ct].x=Math.cos(clip_arr[clip_ct].angle*1)*RADIUS + randXOffset;
			clip_arr[clip_ct].y=Math.sin(clip_arr[clip_ct].angle*2)*RADIUS + randYOffset;
			clip_arr[clip_ct].offsetX = randXOffset;
			clip_arr[clip_ct].offsetY = randYOffset;
			clip_arr[clip_ct].angle=0;
			addChild(clip_arr[clip_ct]);

			clip_arr[clip_ct].addEventListener(Event.ENTER_FRAME,go);
			clip_arr[clip_ct].addEventListener(Event.ENTER_FRAME,cleanUp);

			clip_ct++;
		}

		private function go(evt:Event):void
		{
			evt.target.scaleX += .05;
			evt.target.scaleY += .05;

  			evt.target.x=Math.cos(evt.target.angle*2)*RADIUS + evt.target.offsetX;
  			evt.target.y=Math.sin(evt.target.angle*3)*RADIUS + evt.target.offsetY;
  			evt.target.angle+=.05;

			var copy_mc:MovieClip = new Image(&#8221;smiley.png&#8221;);
  			addChild(copy_mc);

			copy_mc.scaleX = evt.target.scaleX;
			copy_mc.scaleY = evt.target.scaleY;
  			copy_mc.x=evt.target.x;
  			copy_mc.y=evt.target.y;
 			copy_mc.addEventListener(Event.ENTER_FRAME,goCopy);

		}

		private function goCopy(evt:Event):void
		{
			evt.target.alpha*=FRICTION;

			var blurRate = Math.floor(Math.abs((evt.target.x - stage.stageWidth/2) / 100) * 2);
            evt.target.blurImage(blurRate,blurRate);

			if(evt.target.alpha<=.3)
			{
				evt.target.removeEventListener(Event.ENTER_FRAME,goCopy);
				var m:MovieClip=evt.target as MovieClip;
				removeChild(m);
			}
		}

		private function cleanUp(evt:Event):void
		{
			if ( evt.target.scaleX >= 3 )
			{
				evt.target.removeEventListener(Event.ENTER_FRAME,go);
				evt.target.removeEventListener(Event.ENTER_FRAME,cleanUp);

				var d:DisplayObject=evt.target as DisplayObject;
				removeChild(d);
			}
		}
	}
}
</pre>
<p>a class to load in the image, although if you use this code you should add in a listener to make sure the image is loaded prior to implementing it</p>
<pre name="code" class="c-sharp">
package
{
	import flash.display.MovieClip;
	import flash.display.Loader;
    import flash.display.LoaderInfo;
	import flash.net.URLLoader;
    import flash.net.URLRequest;
	import flash.filters.BitmapFilterQuality;
    import flash.filters.BlurFilter;

	public class Image extends MovieClip
	{
		// public properties for the class
		public var earl:String;

		public var angle = Number;
		public var offsetX = Number;
		public var offsetY = Number;

		public var imgLoader:Loader = new Loader();

		private var blur:BlurFilter = new BlurFilter();

		public function Image(e:String)
		{
			earl = e;

			// Load in the image
            var imgLoader:Loader = new Loader();
            imgLoader.load(new URLRequest(earl));

			// add image loader
            addChild(imgLoader);

		}

		public function blurImage(blurX:Number=0, blurY:Number=0)
		{
			blur.quality = BitmapFilterQuality.MEDIUM;
            blur.blurX = blurX;
            blur.blurY = blurY;

			this.filters = [blur];
		}
	}
}
</pre>
</pre>
<p class="addtoany_share_save">
    <a class=".addtoany_share_save" name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/share_save?sitename=manewc&amp;siteurl=http%3A%2F%2Fmanewc.com%2F&amp;linkname=Trails%20Animation%20-%20Version%202&amp;linkurl=http%3A%2F%2Fmanewc.com%2F2008%2F08%2F22%2Ftrails-animation-version-2%2F"><img src="http://manewc.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="Trails Animation - Version 2";
		a2a_linkurl="http://manewc.com/2008/08/22/trails-animation-version-2/";
						a2a_color_main="D7E5ED";a2a_color_border="AECADB";a2a_color_link_text="333333";a2a_color_link_text_hover="333333";    </script>
    <script type="text/javascript" src="http://static.addtoany.com/menu/page.js"></script>

	</p>]]></content:encoded>
			<wfw:commentRss>http://manewc.com/2008/08/22/trails-animation-version-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Trails Animation</title>
		<link>http://manewc.com/2008/08/21/trails-animation/</link>
		<comments>http://manewc.com/2008/08/21/trails-animation/#comments</comments>
		<pubDate>Thu, 21 Aug 2008 16:53:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Actionscript 3]]></category>

		<category><![CDATA[Animation Transitions]]></category>

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

		<guid isPermaLink="false">http://manewc.com/?p=179</guid>
		<description><![CDATA[This code was submitted to me via email who requested some assistance to get this trailing animation to be bound by any newly created object. I edited the code slightly and added a Rect class to build my rectangle object (which could be replaced by an image if so desired). I added a timer to [...]]]></description>
			<content:encoded><![CDATA[<p>This code was submitted to me via email who requested some assistance to get this trailing animation to be bound by any newly created object. I edited the code slightly and added a Rect class to build my rectangle object (which could be replaced by an image if so desired). I added a timer to reproduce the object, here is the resulting code/movie:</p>

<object	type="application/x-shockwave-flash"
			data="/projects/flash/TrailsAnimation/Main.swf"
			width="700"
			height="700">
	<param name="movie" value="/projects/flash/TrailsAnimation/Main.swf" />
</object>
<p>The Main.as:</p>
<pre name="code" class="c-sharp">
package
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.utils.Timer;
	import flash.events.TimerEvent;

	 public class Main extends MovieClip
	 {
		private var clip_arr:Array; // an array of clips
		private var clip_ct:Number = 0;

		private var clip_mc:Rect;

		private const RADIUS:int=30;
		private const FRICTION:Number=.95;

		public function Main()
		{
			init();
		}

		private function init():void
		{
			stage.frameRate=31;

			clip_arr = new Array();

			var myTimer:Timer = new Timer(500, 50);
            myTimer.addEventListener("timer", createClip);
            myTimer.start();
		}

		private function createClip(e:TimerEvent):void
		{
			var randXOffset = Math.random() * stage.stageWidth;
			var randYOffset = Math.random() * stage.stageHeight;

			clip_arr.push ( new Rect() );
			clip_arr[clip_ct].x=Math.cos(clip_arr[clip_ct].angle*1)*RADIUS + randXOffset;
			clip_arr[clip_ct].y=Math.sin(clip_arr[clip_ct].angle*2)*RADIUS + randYOffset;
			clip_arr[clip_ct].offsetX = randXOffset;
			clip_arr[clip_ct].offsetY = randYOffset;
			clip_arr[clip_ct].angle=0;
			addChild(clip_arr[clip_ct]);
			clip_arr[clip_ct].addEventListener(Event.ENTER_FRAME,go);

			clip_ct++;
		}

		private function go(evt:Event):void
		{
  			evt.target.x=Math.cos(evt.target.angle*2)*RADIUS + evt.target.offsetX;
  			evt.target.y=Math.sin(evt.target.angle*3)*RADIUS + evt.target.offsetY;
  			evt.target.angle+=.05;

  			var copy_mc:MovieClip=new Rect();
  			addChild(copy_mc);

  			copy_mc.x=evt.target.x;
  			copy_mc.y=evt.target.y;
 			copy_mc.addEventListener(Event.ENTER_FRAME,goCopy);
		}

		private function goCopy(evt:Event):void
		{
			evt.target.alpha*=FRICTION;
			evt.target.scaleY=evt.target.alpha;
			if(evt.target.alpha<=.3)
			{
				evt.target.removeEventListener(Event.ENTER_FRAME,goCopy);
				var m:MovieClip=evt.target as MovieClip;
				removeChild(m);
			}
		}
	}
}
</pre>
<p>The rect class:</p>
<pre name="code" class="c-sharp">
package
{
	import flash.display.MovieClip;

	public class Rect extends MovieClip
	{
		private var xPos:Number;
		private var yPos:Number;
		private var rWidth:Number;
		private var rHeight:Number;
		private var color:uint;

		public var angle = Number;
		public var offsetX = Number;
		public var offsetY = Number;

		public function Rect(xPos:Number=0,yPos:Number=0,rWidth:Number=10,rHeight:Number=10,color:uint=0x336699)
		{
			this.graphics.beginFill(color);
			this.graphics.drawRect(xPos,yPos,rWidth,rHeight);
			this.graphics.endFill();

			this.angle = 0;
		}
	}
}
</pre>
<p class="addtoany_share_save">
    <a class=".addtoany_share_save" name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/share_save?sitename=manewc&amp;siteurl=http%3A%2F%2Fmanewc.com%2F&amp;linkname=Trails%20Animation&amp;linkurl=http%3A%2F%2Fmanewc.com%2F2008%2F08%2F21%2Ftrails-animation%2F"><img src="http://manewc.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="Trails Animation";
		a2a_linkurl="http://manewc.com/2008/08/21/trails-animation/";
						a2a_color_main="D7E5ED";a2a_color_border="AECADB";a2a_color_link_text="333333";a2a_color_link_text_hover="333333";    </script>
    <script type="text/javascript" src="http://static.addtoany.com/menu/page.js"></script>

	</p>]]></content:encoded>
			<wfw:commentRss>http://manewc.com/2008/08/21/trails-animation/feed/</wfw:commentRss>
		</item>
		<item>
		<title>DataGrid Header Column Styles</title>
		<link>http://manewc.com/2008/08/21/datagrid-header-column-styles/</link>
		<comments>http://manewc.com/2008/08/21/datagrid-header-column-styles/#comments</comments>
		<pubDate>Thu, 21 Aug 2008 16:51:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Assistance]]></category>

		<guid isPermaLink="false">http://manewc.com/?p=177</guid>
		<description><![CDATA[Author: Anonymous
Category: Component
Issue: Is there any way to change the individual header styles of the DataGrid Component. ie: Header 1 is text aligned left / Header 2 is text aligned center / Header 3 is text aligned right

    
    
		a2a_linkname="DataGrid Header Column Styles";
		a2a_linkurl="http://manewc.com/2008/08/21/datagrid-header-column-styles/";
						a2a_color_main="D7E5ED";a2a_color_border="AECADB";a2a_color_link_text="333333";a2a_color_link_text_hover="333333";    
   [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Author:</strong> Anonymous</p>
<p><strong>Category:</strong> Component</p>
<p><strong>Issue:</strong> Is there any way to change the individual header styles of the DataGrid Component. ie: Header 1 is text aligned left / Header 2 is text aligned center / Header 3 is text aligned right</p>
<p class="addtoany_share_save">
    <a class=".addtoany_share_save" name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/share_save?sitename=manewc&amp;siteurl=http%3A%2F%2Fmanewc.com%2F&amp;linkname=DataGrid%20Header%20Column%20Styles&amp;linkurl=http%3A%2F%2Fmanewc.com%2F2008%2F08%2F21%2Fdatagrid-header-column-styles%2F"><img src="http://manewc.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="DataGrid Header Column Styles";
		a2a_linkurl="http://manewc.com/2008/08/21/datagrid-header-column-styles/";
						a2a_color_main="D7E5ED";a2a_color_border="AECADB";a2a_color_link_text="333333";a2a_color_link_text_hover="333333";    </script>
    <script type="text/javascript" src="http://static.addtoany.com/menu/page.js"></script>

	</p>]]></content:encoded>
			<wfw:commentRss>http://manewc.com/2008/08/21/datagrid-header-column-styles/feed/</wfw:commentRss>
		</item>
		<item>
		<title>APE Vectors, Built-In Collision Detection, User Control</title>
		<link>http://manewc.com/2008/08/20/ape-vectors-built-in-collision-detection-user-control/</link>
		<comments>http://manewc.com/2008/08/20/ape-vectors-built-in-collision-detection-user-control/#comments</comments>
		<pubDate>Wed, 20 Aug 2008 17:24:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[APE - Actionscript Physics Engine]]></category>

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

		<guid isPermaLink="false">http://manewc.com/?p=175</guid>
		<description><![CDATA[This movie demonstrates the ability to move one object that collides with another object. You have control over the white ball by simply using your arrow keys. I modified the classes slightly and added some more configuration to the circle classes.

<object	type="application/x-shockwave-flash"
			data="/projects/flash/APEVectorsCollision/APEVectors.swf"
			width="700"
			height="700">
	<param name="movie" value="/projects/flash/APEVectorsCollision/APEVectors.swf" />
</object>

package {
	import flash.display.Sprite;
	import flash.events.Event;
	import org.cove.ape.APEngine;
	import org.cove.ape.Vector;
	import org.cove.ape.CircleParticle;
	import org.cove.ape.Group;
	import flash.events.KeyboardEvent;
	import flash.ui.Keyboard;
	import flash.text.TextField;

	public [...]]]></description>
			<content:encoded><![CDATA[<p>This movie demonstrates the ability to move one object that collides with another object. You have control over the white ball by simply using your arrow keys. I modified the classes slightly and added some more configuration to the circle classes.</p>

<object	type="application/x-shockwave-flash"
			data="/projects/flash/APEVectorsCollision/APEVectors.swf"
			width="700"
			height="700">
	<param name="movie" value="/projects/flash/APEVectorsCollision/APEVectors.swf" />
</object>
<pre name="code" class="c-sharp">
package {
	import flash.display.Sprite;
	import flash.events.Event;
	import org.cove.ape.APEngine;
	import org.cove.ape.Vector;
	import org.cove.ape.CircleParticle;
	import org.cove.ape.Group;
	import flash.events.KeyboardEvent;
	import flash.ui.Keyboard;
	import flash.text.TextField;

	public class Main extends Sprite
	{
		private	var cp:Circle = new Circle( stage.stageWidth / 2, stage.stageHeight / 2, 30 );
		private var walls:Walls = new Walls( stage.stageWidth, stage.stageHeight );
		private var ball:Circle = new Circle( stage.stageWidth / 2, stage.stageHeight / 2, 50, 0xb84777 );

		public function Main()
		{
			APEngine.init(1/4);

			// set up the default diplay container
			APEngine.container = this;
			APEngine.addMasslessForce(new Vector(0,0));

			APEngine.addGroup(cp);
			APEngine.addGroup(ball);
			APEngine.addGroup(walls);

			cp.addCollidable ( ball );
			cp.addCollidable ( walls );
			ball.addCollidable ( walls );

			// make the ball move
			ball.cp.velocity = (new Vector(Math.random() * 5, Math.random() * 5));

			stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
            addEventListener(Event.ENTER_FRAME, run);
		}

		private function run(e:Event):void
		{
			APEngine.step();
			APEngine.paint();
		}

		private function keyDownHandler(k:KeyboardEvent):void
		{
			if (k.keyCode == Keyboard.UP) {
				cp.cp.velocity = (new Vector(0, -10));
			} else if (k.keyCode == Keyboard.DOWN) {
				cp.cp.velocity = (new Vector(0, 10));
			} else if (k.keyCode == Keyboard.RIGHT) {
				cp.cp.velocity = (new Vector(10, 0));
			} else if (k.keyCode == Keyboard.LEFT) {
				cp.cp.velocity = (new Vector(-10, 0));
			}
		}
	}
}
</pre>
<p>The Walls class</p>
<pre name="code" class="c-sharp">
package
{
	import org.cove.ape.Group;
	import org.cove.ape.RectangleParticle;  

	public class Walls extends Group
	{

		public function Walls(bw:Number, bh:Number)
		{
			// top
			var t:RectangleParticle = new RectangleParticle(bw/2, -50, bw, 100, 0, true);
			addParticle(t);

			// this is the bottom
			var b:RectangleParticle = new RectangleParticle(bw/2, bh + 50, bw, 100, 0, true);
			addParticle(b);

			// left
			var l:RectangleParticle = new RectangleParticle(-50, bh / 2, 100, bh, 0, true);
			addParticle(l);  

			// right
			var r:RectangleParticle = new RectangleParticle(bw + 50, bh / 2, 100, bh, 0, true);
			addParticle(r);
		}
	}
}
</pre>
<p>The Circle Class</p>
<pre name="code" class="c-sharp">
package
{
	import org.cove.ape.Group;
	import org.cove.ape.CircleParticle;
	import org.cove.ape.Vector;

	public class Circle extends Group
	{
		public var cp:CircleParticle;

		public function Circle(x:uint, y:uint, r:Number=5, c:uint = 0xffffff)
		{
			cp = new CircleParticle(x, y, r, false, 3, .8);
			cp.setStyle(0, 0, 0, c);
			addParticle(cp);
		}
	}
}
</pre>
<p class="addtoany_share_save">
    <a class=".addtoany_share_save" name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/share_save?sitename=manewc&amp;siteurl=http%3A%2F%2Fmanewc.com%2F&amp;linkname=APE%20Vectors%2C%20Built-In%20Collision%20Detection%2C%20User%20Control&amp;linkurl=http%3A%2F%2Fmanewc.com%2F2008%2F08%2F20%2Fape-vectors-built-in-collision-detection-user-control%2F"><img src="http://manewc.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="APE Vectors, Built-In Collision Detection, User Control";
		a2a_linkurl="http://manewc.com/2008/08/20/ape-vectors-built-in-collision-detection-user-control/";
						a2a_color_main="D7E5ED";a2a_color_border="AECADB";a2a_color_link_text="333333";a2a_color_link_text_hover="333333";    </script>
    <script type="text/javascript" src="http://static.addtoany.com/menu/page.js"></script>

	</p>]]></content:encoded>
			<wfw:commentRss>http://manewc.com/2008/08/20/ape-vectors-built-in-collision-detection-user-control/feed/</wfw:commentRss>
		</item>
		<item>
		<title>APE Vectors and Collidable Walls</title>
		<link>http://manewc.com/2008/08/19/ape-vectors-and-collidable-walls/</link>
		<comments>http://manewc.com/2008/08/19/ape-vectors-and-collidable-walls/#comments</comments>
		<pubDate>Tue, 19 Aug 2008 16:57:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[APE - Actionscript Physics Engine]]></category>

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

		<category><![CDATA[manewc.com]]></category>

		<guid isPermaLink="false">http://manewc.com/?p=174</guid>
		<description><![CDATA[So I just added some walls to my little movie here and took out the KEY_UP handler to allow the circle to continuously move around the stage. To activate, simply hit an arrow key.

<object	type="application/x-shockwave-flash"
			data="/projects/flash/APEVectors2/APEVectors.swf"
			width="700"
			height="700">
	<param name="movie" value="/projects/flash/APEVectors2/APEVectors.swf" />
</object>

package {
	import flash.display.Sprite;
	import flash.events.Event;
	import org.cove.ape.APEngine;
	import org.cove.ape.Vector;
	import org.cove.ape.CircleParticle;
	import org.cove.ape.Group;
	import flash.events.KeyboardEvent;
	import flash.ui.Keyboard;
	import flash.text.TextField;

	public class Main extends Sprite
	{
		private	var cp:Circle = new [...]]]></description>
			<content:encoded><![CDATA[<p>So I just added some walls to my little movie here and took out the KEY_UP handler to allow the circle to continuously move around the stage. To activate, simply hit an arrow key.</p>

<object	type="application/x-shockwave-flash"
			data="/projects/flash/APEVectors2/APEVectors.swf"
			width="700"
			height="700">
	<param name="movie" value="/projects/flash/APEVectors2/APEVectors.swf" />
</object>
<pre name="code" class="c-sharp">
package {
	import flash.display.Sprite;
	import flash.events.Event;
	import org.cove.ape.APEngine;
	import org.cove.ape.Vector;
	import org.cove.ape.CircleParticle;
	import org.cove.ape.Group;
	import flash.events.KeyboardEvent;
	import flash.ui.Keyboard;
	import flash.text.TextField;

	public class Main extends Sprite
	{
		private	var cp:Circle = new Circle( stage.stageWidth / 2, stage.stageHeight / 2 );
		private var walls:Walls = new Walls( stage.stageWidth, stage.stageHeight );

		public function Main()
		{
			APEngine.init(1/4);

			// set up the default diplay container
			APEngine.container = this;
			APEngine.addMasslessForce(new Vector(0,0));

			APEngine.addGroup(cp);
			APEngine.addGroup(walls);

			cp.addCollidable ( walls );

			stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
            addEventListener(Event.ENTER_FRAME, run);
		}

		private function run(e:Event):void
		{
			APEngine.step();
			APEngine.paint();
		}

		private function keyDownHandler(k:KeyboardEvent):void
		{
			if (k.keyCode == Keyboard.UP) {
				cp.cp.velocity = (new Vector(0, -5));
			} else if (k.keyCode == Keyboard.DOWN) {
				cp.cp.velocity = (new Vector(0, 5));
			} else if (k.keyCode == Keyboard.RIGHT) {
				cp.cp.velocity = (new Vector(5, 0));
			} else if (k.keyCode == Keyboard.LEFT) {
				cp.cp.velocity = (new Vector(-5, 0));
			}
		}
	}
}
</pre>
<p>The Circle class:</p>
<pre name="code" class="c-sharp">
package
{
	import org.cove.ape.Group;
	import org.cove.ape.CircleParticle;
	import org.cove.ape.Vector;

	public class Circle extends Group
	{
		public var cp:CircleParticle;

		public function Circle(x:uint, y:uint)
		{
			cp = new CircleParticle(x, y, 5, false, 3, .8);
			cp.setStyle(0, 0, 0, Math.random() * 0xffffff);
			addParticle(cp);
		}
	}
}
</pre>
<p>The Wall class:</p>
<pre name="code" class="c-sharp">
package
{
	import org.cove.ape.Group;
	import org.cove.ape.RectangleParticle;  

	public class Walls extends Group
	{

		public function Walls(bw:Number, bh:Number)
		{
			// top
			var t:RectangleParticle = new RectangleParticle(bw/2, 0, bw, 10, 0, true);
			addParticle(t);

			// this is the bottom
			var b:RectangleParticle = new RectangleParticle(bw/2, bh, bw, 100, 0, true);
			addParticle(b);

			// left
			var l:RectangleParticle = new RectangleParticle(0, bh / 2, 10, bh, 0, true);
			addParticle(l);  

			// right
			var r:RectangleParticle = new RectangleParticle(bw, bh / 2, 10, bh, 0, true);
			addParticle(r);
		}
	}
}
</pre>
<p class="addtoany_share_save">
    <a class=".addtoany_share_save" name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/share_save?sitename=manewc&amp;siteurl=http%3A%2F%2Fmanewc.com%2F&amp;linkname=APE%20Vectors%20and%20Collidable%20Walls&amp;linkurl=http%3A%2F%2Fmanewc.com%2F2008%2F08%2F19%2Fape-vectors-and-collidable-walls%2F"><img src="http://manewc.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="APE Vectors and Collidable Walls";
		a2a_linkurl="http://manewc.com/2008/08/19/ape-vectors-and-collidable-walls/";
						a2a_color_main="D7E5ED";a2a_color_border="AECADB";a2a_color_link_text="333333";a2a_color_link_text_hover="333333";    </script>
    <script type="text/javascript" src="http://static.addtoany.com/menu/page.js"></script>

	</p>]]></content:encoded>
			<wfw:commentRss>http://manewc.com/2008/08/19/ape-vectors-and-collidable-walls/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Actionscript Physics Engine Vectors</title>
		<link>http://manewc.com/2008/08/18/actionscript-physics-engine-vectors/</link>
		<comments>http://manewc.com/2008/08/18/actionscript-physics-engine-vectors/#comments</comments>
		<pubDate>Mon, 18 Aug 2008 17:22:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[APE - Actionscript Physics Engine]]></category>

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

		<guid isPermaLink="false">http://manewc.com/?p=173</guid>
		<description><![CDATA[So I was deconstructing a game the other day that was using the APE Actionscript Engine and wanted to note how movement of an object can be created. By creating a new Vector an object can be moved accordingly. To interact with the movie, simply press the arrow keys on your keyboard.
[kml_flashembed movie="/projects/flash/APEVectors/APEVectors.swf" width="700" height="700" [...]]]></description>
			<content:encoded><![CDATA[<p>So I was deconstructing a game the other day that was using the APE Actionscript Engine and wanted to note how movement of an object can be created. By creating a new Vector an object can be moved accordingly. To interact with the movie, simply press the arrow keys on your keyboard.</p>

<object	type="application/x-shockwave-flash"
			data="/projects/flash/APEVectors/APEVectors.swf"
			width="700"
			height="700">
	<param name="movie" value="/projects/flash/APEVectors/APEVectors.swf" />
</object>
<p>A simple circle class:</p>
<pre name="code" class="c-sharp">
package
{
	import org.cove.ape.Group;
	import org.cove.ape.CircleParticle;
	import org.cove.ape.Vector;

	public class Circle extends Group
	{
		public var cp:CircleParticle;

		public function Circle(x:uint, y:uint)
		{
			cp = new CircleParticle(x, y, 5, false, 3, .8);
			cp.setStyle(0, 0, 0, Math.random() * 0xffffff);
			addParticle(cp);
		}
	}
}
</pre>
<p>and the Main Document class:</p>
<pre name="code" class="c-sharp">
package {
	import flash.display.Sprite;
	import flash.events.Event;
	import org.cove.ape.APEngine;
	import org.cove.ape.Vector;
	import org.cove.ape.CircleParticle;
	import org.cove.ape.Group;
	import flash.events.KeyboardEvent;
	import flash.ui.Keyboard;
	import flash.text.TextField;

	public class Main extends Sprite
	{
		private	var cp:Circle = new Circle(stage.stageWidth / 2, stage.stageHeight / 2);

		public function Main()
		{
			APEngine.init(1/4);

			// set up the default diplay container
			APEngine.container = this;
			APEngine.addGroup(cp);

			stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
            stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
			addEventListener(Event.ENTER_FRAME, run);
		}

		private function run(e:Event):void
		{
			APEngine.step();
			APEngine.paint();
		}

		private function keyDownHandler(k:KeyboardEvent):void
		{
			if (k.keyCode == Keyboard.UP) {
				cp.cp.velocity = (new Vector(0, -5));
			} else if (k.keyCode == Keyboard.DOWN) {
				cp.cp.velocity = (new Vector(0, 5));
			} else if (k.keyCode == Keyboard.RIGHT) {
				cp.cp.velocity = (new Vector(5, 0));
			} else if (k.keyCode == Keyboard.LEFT) {
				cp.cp.velocity = (new Vector(-5, 0));
			}
		}

		private function keyUpHandler(k:KeyboardEvent):void {
			cp.cp.velocity = (new Vector(0, 0));
		}

	}
}
</pre>
<p class="addtoany_share_save">
    <a class=".addtoany_share_save" name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/share_save?sitename=manewc&amp;siteurl=http%3A%2F%2Fmanewc.com%2F&amp;linkname=Actionscript%20Physics%20Engine%20Vectors&amp;linkurl=http%3A%2F%2Fmanewc.com%2F2008%2F08%2F18%2Factionscript-physics-engine-vectors%2F"><img src="http://manewc.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="Actionscript Physics Engine Vectors";
		a2a_linkurl="http://manewc.com/2008/08/18/actionscript-physics-engine-vectors/";
						a2a_color_main="D7E5ED";a2a_color_border="AECADB";a2a_color_link_text="333333";a2a_color_link_text_hover="333333";    </script>
    <script type="text/javascript" src="http://static.addtoany.com/menu/page.js"></script>

	</p>]]></content:encoded>
			<wfw:commentRss>http://manewc.com/2008/08/18/actionscript-physics-engine-vectors/feed/</wfw:commentRss>
		</item>
		<item>
		<title>APE Project - Step 8 - Adding a Fixed Bridge</title>
		<link>http://manewc.com/2008/08/15/ape-project-step-8-adding-a-fixed-bridge/</link>
		<comments>http://manewc.com/2008/08/15/ape-project-step-8-adding-a-fixed-bridge/#comments</comments>
		<pubDate>Fri, 15 Aug 2008 18:14:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[APE - Actionscript Physics Engine]]></category>

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

		<guid isPermaLink="false">http://manewc.com/?p=172</guid>
		<description><![CDATA[From a few past experiments [1 &#124; 2 ] I wanted to add a bridge to my movie here. For now:

Hold down the Shift key to and drag your mouse across the stage to draw a rectangle
Hold down the Command (or Ctrl key) key and click an area on the stage to build a bridge

You [...]]]></description>
			<content:encoded><![CDATA[<p>From a few past experiments [<a href="http://manewc.com/2008/03/28/as-3-as-physics-engine-ape-car-demo/">1</a> | <a href="http://manewc.com/2008/03/26/as-3-as-physics-engine-ape-bridge-demo/">2</a> ] I wanted to add a bridge to my movie here. For now:</p>
<ul>
<li>Hold down the Shift key to and drag your mouse across the stage to draw a rectangle</li>
<li>Hold down the Command (or Ctrl key) key and click an area on the stage to build a bridge</li>
</ul>
<p>You can download the files for this project here:</p>
<p><a href="http://www.manewc.com/projects/flash/APEProject8/manewc.zip">http://www.manewc.com/projects/flash/APEProject8/manewc.zip</a></p>

<object	type="application/x-shockwave-flash"
			data="/projects/flash/APEProject8/APEProject.swf"
			width="700"
			height="700">
	<param name="movie" value="/projects/flash/APEProject8/APEProject.swf" />
</object>
<p>Here is the updated Main.as file</p>
<pre name="code" class="c-sharp">
package {
	import flash.display.Sprite;
	import flash.display.Shape;
	import flash.ui.Keyboard;
	import flash.events.MouseEvent;
	import flash.events.KeyboardEvent;
	import flash.events.Event;
	import flash.geom.Rectangle;
	import fl.controls.Button;
	import org.cove.ape.*;

	public class Main extends Sprite {

		private var beginX:Number; // top left x position
		private var beginY:Number; // top left y position
       	private var endX:Number; // bottom right x position
       	private var endY:Number; // bottom right y position  

		private var dynRect:RectangleParticle;
		private var canDraw:Boolean = false; // this allows the drawing of rectangles
		private var circle:CircleParticle;
		private var circleGroup:Group;
        private var defaultGroup:Group;
		private var canDrawBridge:Boolean = false; // this allows the drawing of bridges
		private var bridge:Bridge;
		private var car:Car;
		private var btnCar:Button;

		// rectangle particle dimensions
		private var _xpos:Number;
		private var _ypos:Number;
		private var _rwidth:Number;
		private var _rheight:Number;
		private var _rrotation:Number = 0;

		public function Main()
		{
			init();
		}

		private function init():void
		{
			stage.frameRate = 55;

            // Initialize the engine. The argument here is the time step value.
            // Higher values scale the forces in the sim, making it appear to run
            // faster or slower. Lower values result in more accurate simulations.
            APEngine.init(1/4);  

            // set up the default diplay container
            APEngine.container = this;  

            APEngine.addMasslessForce(new Vector(0,8));  

            defaultGroup = new Group();  

            defaultGroup.collideInternal = true;

			circleGroup = new Group();
			circleGroup.collideInternal = true;

			// this is the bottom
			var rect:RectangleParticle = new RectangleParticle(345, 680, 710, 40, 0, true);
            defaultGroup.addParticle(rect);  

			var l:RectangleParticle = new RectangleParticle(0, stage.stageHeight / 2 - 20, 10, stage.stageHeight-40, 0, true);
            defaultGroup.addParticle(l);

			var r:RectangleParticle = new RectangleParticle(stage.stageWidth, stage.stageHeight / 2 - 20, 10, stage.stageHeight-40, 0, true);
            defaultGroup.addParticle(r);

            APEngine.addGroup(defaultGroup);
			APEngine.addGroup(circleGroup);

			// make the groups collidable
			defaultGroup.addCollidable(circleGroup);

			addEventListener(Event.ENTER_FRAME, run);

			stage.addEventListener(KeyboardEvent.KEY_DOWN, allowDraw);
			stage.addEventListener(KeyboardEvent.KEY_UP, disallowDraw);
			stage.addEventListener(MouseEvent.MOUSE_DOWN, dragDraw);
			stage.addEventListener(MouseEvent.MOUSE_UP, dragDrawStop);

			// build the UI
			buildUI();
		}

		private function allowDraw(event:KeyboardEvent):void
		{
			if ( event.keyCode == 16 )
			{
            	canDraw = true;
			}
			else if ( event.keyCode == 17 ) // 'command'
			{
				canDrawBridge = true;
			}
		}

		private function disallowDraw(event:KeyboardEvent):void {
            if ( canDraw ) canDraw = false;
			if ( canDrawBridge ) canDrawBridge = false;
        }

		private function dragDraw (m:MouseEvent):void
		{
			if ( canDraw )
			{
				beginRectDraw();
			}
			else if ( canDrawBridge )
			{
				beginDrawBridge();
			}
		}

		private function dragDrawStop (m:MouseEvent):void
		{
			if ( canDraw )
			{
				stopRectDraw();
			}
			else if ( canDrawBridge )
			{

			}
		}

		private function beginDrawBridge():void
		{
			// if exists.. delete it for now
			if ( bridge ) APEngine.removeGroup(bridge);

			// add the bridge
			bridge = new Bridge(mouseX, mouseY, 11.9, 55, 5);
			APEngine.addGroup ( bridge );

			// add the collidables
			defaultGroup.addCollidable(bridge);
			circleGroup.addCollidable(bridge);
			if ( car ) car.addCollidable(bridge);
		}

		private function beginRectDraw():void
       	{
			beginX = mouseX;
			beginY = mouseY;
       	}

		private function stopRectDraw():void
       	{
			// set the end points
           	endX = mouseX;
		   	endY = mouseY;

			// now draw the rectangle
			if ( canDraw ) drawRectangle();
		}

		private function drawRectangle():void
		{
			if ( beginY < 660 &#038;&#038; endY < 660 )
			{
				// store the data
				_xpos = beginX + ((endX - beginX)/2);
				_ypos = beginY + ((endY - beginY)/2);
				_rwidth = endX - beginX;
				_rheight = endY - beginY;
				_rrotation = 0;

				dynRect = new RectangleParticle(_xpos, _ypos, _rwidth, _rheight, _rrotation, true);
            	defaultGroup.addParticle(dynRect);

				dynRect.sprite.addEventListener ( MouseEvent.MOUSE_DOWN, rotateRectangle );
			}
		}

		private function rotateRectangle( m:MouseEvent ):void
		{
			if ( !canDraw )
			{
				// increment the angle
				_rrotation += .05;

				// rid of the particle
				defaultGroup.removeParticle(dynRect);

				// redraw the particle
				dynRect = new RectangleParticle(_xpos, _ypos, _rwidth, _rheight, _rrotation, true);
            	defaultGroup.addParticle(dynRect);

				dynRect.sprite.addEventListener ( MouseEvent.MOUSE_DOWN, rotateRectangle );
			}
		}

		private function addBall( m:MouseEvent ):void
        {
            circle = new CircleParticle(Math.random() * stage.stageWidth, Math.random() * 100, Math.random() * 25 + 5);
            circleGroup.addParticle(circle);
        }

		private function addCar ( m:MouseEvent ):void
		{
			btnCar.removeEventListener(MouseEvent.CLICK, addCar);

			car = new Car(Math.random() * 0xffffff,Math.random() * 0xffffff);
			APEngine.addGroup(car);

			defaultGroup.addCollidable(car);
			circleGroup.addCollidable(car);
			if ( bridge ) bridge.addCollidable(car);

			stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
			stage.addEventListener(KeyboardEvent.KEY_UP, keyReleased);

			// change the type of the button
			btnCar.label = "Remove Car";

			btnCar.addEventListener(MouseEvent.CLICK, removeCar);
		}

		private function removeCar ( m:MouseEvent ):void
		{
			btnCar.removeEventListener(MouseEvent.CLICK, removeCar);

			// remove the car
			APEngine.removeGroup(car);

			// change the label
			btnCar.label = "Add Car";

			// change the button action
			btnCar.addEventListener(MouseEvent.CLICK, addCar);
		}

		private function run(e:Event):void
        {
            APEngine.step();
            APEngine.paint();
        }

		private function removeLastBall( m:MouseEvent ):void
		{
			if ( circle ) circle.cleanup();
		}

		private function clearBoard( m:MouseEvent ):void
		{
			APEngine.removeGroup(defaultGroup);
			APEngine.removeGroup(circleGroup);
			if ( bridge ) APEngine.removeGroup(bridge);
			if ( car ) APEngine.removeGroup(car);
			init();

		}

		function keyPressed(event:KeyboardEvent):void {
            var keySpeed:Number = 0.8;  

            if (event.keyCode == Keyboard.UP || event.keyCode == Keyboard.RIGHT)
            {
                car.speed = keySpeed;
            }  

            if (event.keyCode == Keyboard.DOWN || event.keyCode == Keyboard.LEFT)
            {
                car.speed = -keySpeed;
            }
        }  

        function keyReleased(event:KeyboardEvent):void
        {
            car.speed = 0;
        }  

		private function buildUI():void
		{

			// NEW BUTTONS
            var btnAddBall:Button = new Button();
            btnAddBall.width = 65;
            btnAddBall.height = 25;
            btnAddBall.move ( 5, stage.stageHeight - 20 - btnAddBall.height / 2 );
            btnAddBall.label = "Add Ball";      

            addChild(btnAddBall);      

            btnAddBall.addEventListener(MouseEvent.CLICK, addBall);  

			var btnRemoveBall:Button = new Button();
            btnRemoveBall.width = 120;
            btnRemoveBall.height = 25;
            btnRemoveBall.move ( 75, stage.stageHeight - 20 - btnRemoveBall.height / 2 );
            btnRemoveBall.label = "Remove Last Ball";      

            addChild(btnRemoveBall);

            btnRemoveBall.addEventListener(MouseEvent.CLICK, removeLastBall);

			btnCar = new Button();
            btnCar.width = 100;
            btnCar.height = 25;
            btnCar.move ( 200, stage.stageHeight - 20 - btnCar.height / 2 );
            btnCar.label = "Add Car";      

            addChild(btnCar);

            btnCar.addEventListener(MouseEvent.CLICK, addCar);

			var btnClearBoard:Button = new Button();
            btnClearBoard.width = 120;
            btnClearBoard.height = 25;
            btnClearBoard.move ( 575, stage.stageHeight - 20 - btnClearBoard.height / 2 );
            btnClearBoard.label = "Clear Board";      

            addChild(btnClearBoard);

            btnClearBoard.addEventListener(MouseEvent.CLICK, clearBoard);
		}
	}
}
</pre>
<p>The new Car class</p>
<pre name="code" class="c-sharp">
package {

	import org.cove.ape.*;

	public class Car extends Group {

		private var wheelParticleA:WheelParticle;
		private var wheelParticleB:WheelParticle;

		public function Car(colC:uint, colE:uint) {

			wheelParticleA = new WheelParticle(140,10,14,false,2);
			wheelParticleA.setStyle(0, colC, 1, colE);
			addParticle(wheelParticleA);
			wheelParticleA.sprite.cacheAsBitmap = true;

			wheelParticleB = new WheelParticle(200,10,14,false,2);
			wheelParticleB.setStyle(0, colC, 1, colE);
			addParticle(wheelParticleB);
			wheelParticleB.sprite.cacheAsBitmap = true;

			var wheelConnector:SpringConstraint = new SpringConstraint(wheelParticleA, wheelParticleB, 0.5, true, 8);
			wheelConnector.setStyle(0, colC, 1, colE);
			addConstraint(wheelConnector);
		}

		public function set speed(s:Number):void {
			wheelParticleA.angularVelocity = s;
			wheelParticleB.angularVelocity = s;
		}
	}
}
</pre>
<p>The new Bridge class</p>
<pre name="code" class="c-sharp">
package {

	import org.cove.ape.*;

	public class Bridge extends Group {

		public function Bridge(bx:Number, by:Number, yslope:Number, bsize:Number, particleSize:Number=20, colB:uint=0x000000, colC:uint=0x000000, colD:uint=0x000000) {	

			var bridgePAA:CircleParticle = new CircleParticle(bx,by,particleSize,true);
			bridgePAA.setStyle(1, colC, 1, colB);
			addParticle(bridgePAA);

			bx += bsize;
			by += yslope;
			var bridgePA:CircleParticle = new CircleParticle(bx,by,particleSize);
			bridgePA.setStyle(1, colC, 1, colB);
			addParticle(bridgePA);

			bx += bsize;
			by += yslope;
			var bridgePB:CircleParticle = new CircleParticle(bx,by,particleSize);
			bridgePB.setStyle(1, colC, 1, colB);
			addParticle(bridgePB);

			bx += bsize;
			by += yslope;
			var bridgePC:CircleParticle = new CircleParticle(bx,by,particleSize);
			bridgePC.setStyle(1, colC, 1, colB);
			addParticle(bridgePC);

			bx += bsize;
			by += yslope;
			var bridgePD:CircleParticle = new CircleParticle(bx,by,particleSize);
			bridgePD.setStyle(1, colC, 1, colB);
			addParticle(bridgePD);

			bx += bsize;
			by += yslope;
			var bridgePDD:CircleParticle = new CircleParticle(bx,by,particleSize,true);
			bridgePDD.setStyle(1, colC, 1, colB);
			addParticle(bridgePDD);

			var bridgeConnA:SpringConstraint = new SpringConstraint(bridgePAA, bridgePA, 0.9, true, 10, 0.8);

			// collision response on the bridgeConnA will be ignored on
			// on the first 1/4 of the constraint. this avoids blow ups
			// particular to springcontraints that have 1 fixed particle.

			bridgeConnA.fixedEndLimit = 0.25;
			bridgeConnA.setStyle(1, colC, 1, colB);
			addConstraint(bridgeConnA);

			var bridgeConnB:SpringConstraint = new SpringConstraint(bridgePA, bridgePB, 0.9, true, 10, 0.8);
			bridgeConnB.setStyle(1, colC, 1, colB);
			addConstraint(bridgeConnB);

			var bridgeConnC:SpringConstraint = new SpringConstraint(bridgePB, bridgePC, 0.9, true, 10, 0.8);
			bridgeConnC.setStyle(1, colC, 1, colB);
			addConstraint(bridgeConnC);

			var bridgeConnD:SpringConstraint = new SpringConstraint(bridgePC, bridgePD, 0.9, true, 10, 0.8);
			bridgeConnD.setStyle(1, colC, 1, colB);
			addConstraint(bridgeConnD);

			var bridgeConnE:SpringConstraint = new SpringConstraint(bridgePD, bridgePDD, 0.9, true, 10, 0.8);
			bridgeConnE.fixedEndLimit = 0.25;
			bridgeConnE.setStyle(1, colC, 1, colB);
			addConstraint(bridgeConnE);

		}
	}
}
</pre>
<p class="addtoany_share_save">
    <a class=".addtoany_share_save" name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/share_save?sitename=manewc&amp;siteurl=http%3A%2F%2Fmanewc.com%2F&amp;linkname=APE%20Project%20-%20Step%208%20-%20Adding%20a%20Fixed%20Bridge&amp;linkurl=http%3A%2F%2Fmanewc.com%2F2008%2F08%2F15%2Fape-project-step-8-adding-a-fixed-bridge%2F"><img src="http://manewc.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="APE Project - Step 8 - Adding a Fixed Bridge";
		a2a_linkurl="http://manewc.com/2008/08/15/ape-project-step-8-adding-a-fixed-bridge/";
						a2a_color_main="D7E5ED";a2a_color_border="AECADB";a2a_color_link_text="333333";a2a_color_link_text_hover="333333";    </script>
    <script type="text/javascript" src="http://static.addtoany.com/menu/page.js"></script>

	</p>]]></content:encoded>
			<wfw:commentRss>http://manewc.com/2008/08/15/ape-project-step-8-adding-a-fixed-bridge/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
