<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>manewc &#187; Actionscript 3</title>
	<atom:link href="http://manewc.com/category/actionscript-3/feed/" rel="self" type="application/rss+xml" />
	<link>http://manewc.com</link>
	<description>iPhone, Flash, Flex, AIR, &#38; Web Development</description>
	<lastBuildDate>Sat, 31 Oct 2009 16:47:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Downloading Multiple Files with Flex 3 and AMFPHP</title>
		<link>http://manewc.com/2008/12/22/downloading-multiple-files-with-flex-3/</link>
		<comments>http://manewc.com/2008/12/22/downloading-multiple-files-with-flex-3/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 16:44:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[AMFPHP]]></category>
		<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Flex Web Development]]></category>

		<guid isPermaLink="false">http://manewc.com/?p=254</guid>
		<description><![CDATA[
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_Main_2005764400"
			class="flashmovie"
			width="700"
			height="540">
	<param name="movie" value="/projects/flex3/MultipleFileDownloadAMFPHP/Main.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/projects/flex3/MultipleFileDownloadAMFPHP/Main.swf"
			name="fm_Main_2005764400"
			width="700"
			height="540">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
I originally was thinking that I would be able to do this by having the user select the files of their choice and click one button to download the items. So depending on their selection the Flex app would download the first item, then upon complete download of the first item [...]]]></description>
			<content:encoded><![CDATA[
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_Main_913963835"
			class="flashmovie"
			width="700"
			height="540">
	<param name="movie" value="/projects/flex3/MultipleFileDownloadAMFPHP/Main.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/projects/flex3/MultipleFileDownloadAMFPHP/Main.swf"
			name="fm_Main_913963835"
			width="700"
			height="540">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>I originally was thinking that I would be able to do this by having the user select the files of their choice and click one button to download the items. So depending on their selection the Flex app would download the first item, then upon complete download of the first item it would download the second item and so on.. Unfortunately I could not get this to work on various browsers as the dialog box to download the file location would never appear on the second file. So with a little exploring I was able to accomplish the task of downloading multiple files of the users choosing with the use of:</p>
<p>Here is a list of things that I needed to get this working.</p>
<ol>
<li><a href="http://www.amfphp.org">AMFPHP</a> &#8211; Lee Brimelow has an excellent tutorial to get you started: <a href="http://www.gotoandlearn.com/play?id=78">http://www.gotoandlearn.com/play?id=78</a></li>
<li>PHP Class file to create zip documents from an array. You can find the one I used here: <a href="http://www.phpconcept.net/pclzip/index.en.php">http://www.phpconcept.net/pclzip/index.en.php</a> (note I am using PHP 5.*)</li>
<li>I also grabbed this class file from <a href="http://www.flexexamples.com">FlexExamples.com</a> for <a href="http://blog.flexexamples.com/2008/01/27/using-a-checkbox-control-as-a-list-item-renderer-in-flex/">using a checkbox control as a list item renderer</a></li>
</ol>
<p>Here is the process:</p>
<ol>
<li>So first the user will select the files he/she wishes to download</li>
<li>The user will need to click a button to notify the server the array of files and generate a unique .zip document</li>
<li>The download button will need to be active once the zip file is created so the user can then download the new .zip file</li>
<li>User clicks the download button to download the file</li>
<li>Will need to run a cron to delete all the generated .zip files as to not load up my server. (I won&#8217;t cover this step)</li>
</ol>
<p>Honestly I am not a PHP programmer, but this is the Service Class that I put in my Service folder in my AMFPHP setup&#8230;</p>
<p>The file name is ZipFile.php (also don&#8217;t forget to inlude the library for zipping files)</p>
<pre name="code" class="c-sharp">
&lt;?php

class ZipFile
{
	/**
	* Demo ZipFile
	* @returns file name of zip object
	*/

	function ZipFileTest($fileArr) // this is what gets called from flash
	{
		// include the library from http://www.phpconcept.net/pclzip/index.en.php
		include_once("pclzip.lib.php");

		// create a unique file name.. this is prepended with manewc.com-
		$uniqueFileName = uniqid("manewc.com-");

		// create the zip
		$archive = new PclZip('../relative/path/to/put/this/zip/file'.$uniqueFileName.'.zip');

		$v_list = $archive->create($fileArr);

  		if ($v_list == 0) {
    		$status = "Error : ".$archive->errorInfo(true);
  		}
  		else
  		{
  			$status = $uniqueFileName;
  		}

		return $status;

	}
}

?$gt;
</pre>
<p>In Flex, I just need to add the ListItemValueObject.as file from <a href="http://blog.flexexamples.com/2008/01/27/using-a-checkbox-control-as-a-list-item-renderer-in-flex/">FlexExamples.com</a>. I added this file in src/com/flexexamples/.</p>
<p>Here is my Main.mxml file to create the ui:</p>
<p><strong>Please note that my editor generally does not render my flex code properly.. check this file here: <a href="http://manewc.com/projects/flex3/MultipleFileDownloadAMFPHP/Main.mxml.txt">Main.mxml.txt</a></strong></p>
<pre name="code" class="c-sharp">
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
    xmlns:mx="http://www.adobe.com/2006/mxml"
    xmlns:vo="com.flexexamples.*"
    layout="absolute"
    creationComplete="init()">

    <mx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import flash.net.FileReference;
            import com.flexexamples.*;

            import mx.events.CollectionEvent;
            import mx.utils.ObjectUtil;

            private var phpArr:String = "";
            private var tArr:Array;

            public var DOWNLOAD_URL:String;
            public var _fr:FileReference = new FileReference();
            // private var _dlFileName:String;

            private function init():void {
                arrColl.dispatchEvent(new CollectionEvent(CollectionEvent.COLLECTION_CHANGE));
            }

            private function arrColl_collectionChange(evt:CollectionEvent):void {
                try {
                    tArr = arrColl.source.filter(selectedOnly);
                    textArea.text = ObjectUtil.toString(tArr);
                    lbl.text = tArr.length.toString() + " item(s) selected";
                } catch (err:Error) {
                    // ignore.
                }
            }

            private function selectedOnly(item:ListItemValueObject, idx:uint, arr:Array):Boolean {
                return item.isSelected;
            }

            private function amfphp():void
            {
                // create the array of files:
                // var filesToDL:Array = new Array("../../projects/flex3/FileDownloadMultiple/life-1.jpg","../../projects/flex3/FileDownloadMultiple/life-2.jpg");

                var filesToDL:Array = new Array();
                for ( var k:int=0; k < tArr.length; k++ )
                {
                    filesToDL[k] = tArr[k].fileLocation;
                }

                // mx.controls.Alert.show ( "Item: " + filesToDL );

                // reconfigure Array so PHP can interpret
                phpArr = "";
                for ( var u:int=0; u < filesToDL.length; u++ )
                {
                    phpArr += filesToDL[u];

                    if ( u < filesToDL.length - 1 )
                    {
                        phpArr += ",";
                    }
                }

                txtOutput.htmlText = "Waiting for status...\n" + phpArr + " (" + filesToDL.length + " items)\n";

                //connect
                var gw:NetConnection = new NetConnection();
                gw.connect( "../../../amfphp/gateway.php" );

                // 2 functions called when data is passed back..
                // one for success, one for failure
                var res:Responder = new Responder ( onResult, onFault );

                // the php method, the result, parameters
                gw.call ( "ZipFile.ZipFileTest", res, phpArr);

            }

            private function onResult ( responds:Object ):void
            {
                txtOutput.htmlText = "File to download: " + responds;

                // file to download name:
                DOWNLOAD_URL = responds as String;

                // all set, now activate the download file button
                btnDownload.enabled = true;
            }

            private function onFault ( responds:Object):void
            {
                for ( var i in responds )
                {
                    txtOutput.htmlText = "Error: " + responds[i];
                }
            }

            private function downloadFile():void
            {
                // disable the download button
                btnDownload.enabled = false;

                // mx.controls.Alert.show( "test" + DOWNLOAD_URL );
                _fr = new FileReference;
                _fr.addEventListener(Event.OPEN, openHandler);
                _fr.addEventListener(ProgressEvent.PROGRESS, progressHandler);
                _fr.addEventListener(Event.COMPLETE, completeHandler);

                // DOWNLOAD_URL = "http://manewc.com/projects/download/archive.zip";
                if ( DOWNLOAD_URL != "" )
                {
                    // DOWNLOAD_URL = "";
                }

                DOWNLOAD_URL = "../../download/" + DOWNLOAD_URL + ".zip";
                 txtOutput.htmlText = "DLURL: " + DOWNLOAD_URL;

                var request:URLRequest = new URLRequest();
                request.url = DOWNLOAD_URL;
                _fr.download(request);
            }

            /**
         * When the OPEN event has dispatched, change the progress bar's label
         * and enable the "Cancel" button, which allows the user to abort the
         * download operation.
         */
        private function openHandler(event:Event):void {
            pb.label = "DOWNLOADING %3%%";
            txtOutput.htmlText = "DOWNLOADING %3%%";
        }

        /**
         * While the file is downloading, update the progress bar's status and label.
         */
        private function progressHandler(event:ProgressEvent):void {
            pb.setProgress(event.bytesLoaded, event.bytesTotal);
            txtOutput.htmlText = "DOWNLOADING... " + (event.bytesLoaded/event.bytesTotal) + "%";
        }

        /**
         * Once the download has completed, change the progress bar's label and
         * disable the "Cancel" button since the download is already completed.
         */
        private function completeHandler(event:Event):void {
            // loadedStatus = true;
               pb.label = "DOWNLOAD COMPLETE";
            pb.setProgress(0, 100);
            //btn.enabled = false;
            txtOutput.htmlText = "DOWNLOADING... COMPLETE"

        }
        ]]&gt;
    </mx:Script>
    <mx:Text id="txtOutput" x="261.5" y="40" width="366.5"/>
    <mx:Button x="261.5" y="10" label="Download File" click="downloadFile()" enabled="false" id="btnDownload"/>

    <mx:Panel title="Download File Progress" paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10" x="261.5" y="68">
    <mx:ProgressBar id="pb" label="progress" mode="manual" />
    </mx:Panel>

    <mx:Array id="arr">
        <vo:ListItemValueObject label="Flash Files" isSelected="true" fileLocation="../../projects/flash/PapervisionCubeSides/PapervisionCubeSides.zip" />
        <vo:ListItemValueObject label="Image One" isSelected="true" fileLocation="../../projects/flex3/FileDownloadMultiple/life-1.jpg" />
        <vo:ListItemValueObject label="Image Two" isSelected="true" fileLocation="../../projects/flex3/FileDownloadMultiple/life-2.jpg" />
    </mx:Array>

    <mx:ArrayCollection id="arrColl"
            source="{arr}"
            collectionChange="arrColl_collectionChange(event);" />

    <mx:Panel id="panel"
            title="Items"
            status="{arrColl.length} total"
            styleName="opaquePanel" x="10" y="10">
        <mx:List id="list"
                dataProvider="{arrColl}"
                alternatingItemColors="[#cccccc, #ffffff]"
                width="150"
                rowCount="8">
            <mx:itemRenderer>
                <mx:Component>
                    <mx:CheckBox selectedField="isSelected"
                            change="onChange(event);">
                        <mx:Script>
                            <![CDATA[
                                private function onChange(evt:Event):void {
                                    data.isSelected = !data.isSelected;
                                }
                            ]]&gt;
                        </mx:Script>
                    </mx:CheckBox>
                </mx:Component>
            </mx:itemRenderer>
        </mx:List>
        <mx:Label id="lbl" />
        <mx:ControlBar horizontalAlign="right" height="40">
            <mx:Button id="btnRun" label="Zip Files" click="amfphp()"/>
        </mx:ControlBar>
    </mx:Panel>

    <mx:TextArea id="textArea"
            verticalScrollPolicy="on"
            width="366.5"
            height="{panel.height}"  x="261.5" y="177"/>

</mx:Application>
</pre>
<p>I&#8217;ll have to admit that this code needs to be cleaned up.. just ran out of time at the moment.</p>
]]></content:encoded>
			<wfw:commentRss>http://manewc.com/2008/12/22/downloading-multiple-files-with-flex-3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>APE &#8211; Collision Within A Circle</title>
		<link>http://manewc.com/2008/12/12/ape-collision-within-a-circle/</link>
		<comments>http://manewc.com/2008/12/12/ape-collision-within-a-circle/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 18:18:50 +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=248</guid>
		<description><![CDATA[A slight modification that adds a CircleParticle with constant motion inside of the circle.

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_CollisionInsideCircle_849937626"
			class="flashmovie"
			width="700"
			height="700">
	<param name="movie" value="/projects/flash/APECollisionInsideCircle2/CollisionInsideCircle.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/projects/flash/APECollisionInsideCircle2/CollisionInsideCircle.swf"
			name="fm_CollisionInsideCircle_849937626"
			width="700"
			height="700">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
The Main.as Document Class:

package
{
	import flash.display.Sprite;
	import flash.events.Event;
	import org.cove.ape.*;

	public class Main extends Sprite
	{
		private var follow:Ball;

		private var c:Circle;
		private var vr:Number = .4;
		private var _maxpts:Number = 15; // number of drawn points, this is dependent on vr variable.
		private var cos:Number = Math.cos [...]]]></description>
			<content:encoded><![CDATA[<p>A slight modification that adds a CircleParticle with constant motion inside of the circle.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_CollisionInsideCircle_1157339531"
			class="flashmovie"
			width="700"
			height="700">
	<param name="movie" value="/projects/flash/APECollisionInsideCircle2/CollisionInsideCircle.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/projects/flash/APECollisionInsideCircle2/CollisionInsideCircle.swf"
			name="fm_CollisionInsideCircle_1157339531"
			width="700"
			height="700">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>The Main.as Document Class:</p>
<pre name="code" class="c-sharp">
package
{
	import flash.display.Sprite;
	import flash.events.Event;
	import org.cove.ape.*;

	public class Main extends Sprite
	{
		private var follow:Ball;

		private var c:Circle;
		private var vr:Number = .4;
		private var _maxpts:Number = 15; // number of drawn points, this is dependent on vr variable.
		private var cos:Number = Math.cos ( vr );
		private var sin:Number = Math.sin ( vr );

		private var _ct:Number = 0; // counter

		private var _ptarr:Array = new Array();
		private var defaultGroup:Group;
		private var _scarr:Array = new Array();

		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,6));
			APEngine.addMasslessForce(new Vector(0,0));

			defaultGroup = new Group();

			defaultGroup.collideInternal = true;

			APEngine.addGroup(defaultGroup);
			addEventListener(Event.ENTER_FRAME, run);

			follow = new Ball();
			addChild ( follow );
			follow.x = 130;
			follow.y = 130;
			follow.addEventListener ( Event.ENTER_FRAME, drawCircleBounds );
		}

		private function drawCircleBounds (e:Event):void
		{
			var x1:Number = follow.x - stage.stageWidth / 2;
			var y1:Number = follow.y - stage.stageHeight / 2;
			var x2:Number = cos * x1 - sin * y1;
			var y2:Number = cos * y1 + sin * x1;

			follow.x = stage.stageWidth / 2 + x2;
			follow.y = stage.stageHeight / 2 + y2;

			/* CIRCLE PROPERTIES
				x:Number,
				y:Number,
				radius:Number,
				fixed:Boolean = false,
				mass:Number = 1,
				elasticity:Number = 0.3,
				friction:Number = 0
			*/

			/* Points of Circle
			------------------
			*/
			_ptarr[_ct] = new CircleParticle(follow.x, follow.y, 2, true, 1, 0);
           	_ptarr[_ct].setStyle(0, 0, 0, 0xffffff);
			defaultGroup.addParticle(_ptarr[_ct]);

			/* Connectors
			------------------
			*/

			if ( _ct > 0 )
			{
				_scarr[_ct] = new SpringConstraint(_ptarr[_ct-1], _ptarr[_ct], 4, true);
				defaultGroup.addConstraint( _scarr[_ct] );

				if ( _ct >= _maxpts )
				{
					_scarr[_ct+1] = new SpringConstraint(_ptarr[_ct], _ptarr[0], 4, true);
					defaultGroup.addConstraint( _scarr[_ct+1] );

					dropBall();
				}
			}

			/* Update
			------------------
			*/
			_ct++;

			/* Check end
			------------------
			*/
			if ( _ct > _maxpts ) follow.removeEventListener ( Event.ENTER_FRAME, drawCircleBounds );

		}

		private function dropBall():void
		{
			c = new Circle ( stage.stageWidth / 2, stage.stageHeight / 2, 30 );
			APEngine.addGroup(c);
			c.addCollidable ( defaultGroup );

			// make the ball move
			c.cp.velocity = (new Vector(10, 10));
		}

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

	}
}
</pre>
<p>The Circle.as 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;

		/*
		x:Number,
				y:Number,
				radius:Number,
				fixed:Boolean = false,
				mass:Number = 1,
				elasticity:Number = 0.3,
				friction:Number = 0
		*/

		public function Circle(x:uint, y:uint, r:Number=5, c:uint = 0xffffff)
		{
			cp = new CircleParticle(x, y, r, false, 1, 1);
			cp.setStyle(0, 0, 0, c);
			addParticle(cp);
		}
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://manewc.com/2008/12/12/ape-collision-within-a-circle/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>APE &#8211; Animation within Circular Bounds</title>
		<link>http://manewc.com/2008/12/10/ape-animation-within-circular-bounds/</link>
		<comments>http://manewc.com/2008/12/10/ape-animation-within-circular-bounds/#comments</comments>
		<pubDate>Wed, 10 Dec 2008 18:47:43 +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=242</guid>
		<description><![CDATA[Here is a little movie that will generate a circle and then place a dragable circle particle contained within it&#8217;s circular bounds. I unfortunately have run out of time for today to clean up this file, so I will consider this as part 1. Note, if you interact with this movie, the key is to [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a little movie that will generate a circle and then place a dragable circle particle contained within it&#8217;s circular bounds. I unfortunately have run out of time for today to clean up this file, so I will consider this as part 1. Note, if you interact with this movie, the key is to &#8216;gently&#8217; toss the circle against the walls, else the circle will fly off of the screen <img src='http://manewc.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_CollisionInsideCircle_1699341145"
			class="flashmovie"
			width="700"
			height="700">
	<param name="movie" value="/projects/flash/APECollisionInsideCircle/CollisionInsideCircle.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/projects/flash/APECollisionInsideCircle/CollisionInsideCircle.swf"
			name="fm_CollisionInsideCircle_1699341145"
			width="700"
			height="700">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>Here is the Main.as file:</p>
<pre name="code" class="c-sharp">
package
{
	import flash.display.Sprite;
	import flash.events.Event;
	import org.cove.ape.*;

	public class Main extends Sprite
	{
		private var follow:Ball;
		private var db:DragableCircleParticle;
		private var vr:Number = .4;
		private var _maxpts:Number = 15; // number of drawn points, this is dependent on vr variable.
		private var cos:Number = Math.cos ( vr );
		private var sin:Number = Math.sin ( vr );

		private var _ct:Number = 0; // counter

		private var _ptarr:Array = new Array();
		private var defaultGroup:Group;
		private var _scarr:Array = new Array();

		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,6));

			defaultGroup = new Group();

			defaultGroup.collideInternal = true;

			APEngine.addGroup(defaultGroup);
			addEventListener(Event.ENTER_FRAME, run);

			follow = new Ball();
			addChild ( follow );
			follow.x = 130;
			follow.y = 130;
			follow.addEventListener ( Event.ENTER_FRAME, drawCircleBounds );
		}

		private function drawCircleBounds (e:Event):void
		{
			var x1:Number = follow.x - stage.stageWidth / 2;
			var y1:Number = follow.y - stage.stageHeight / 2;
			var x2:Number = cos * x1 - sin * y1;
			var y2:Number = cos * y1 + sin * x1;

			follow.x = stage.stageWidth / 2 + x2;
			follow.y = stage.stageHeight / 2 + y2;

			/* CIRCLE PROPERTIES
				x:Number,
				y:Number,
				radius:Number,
				fixed:Boolean = false,
				mass:Number = 1,
				elasticity:Number = 0.3,
				friction:Number = 0
			*/

			/* Points of Circle
			------------------
			*/
			_ptarr[_ct] = new CircleParticle(follow.x, follow.y, 2, true, 1, 0);
           	_ptarr[_ct].setStyle(0, 0, 0, 0xffffff);
			defaultGroup.addParticle(_ptarr[_ct]);

			/* Connectors
			------------------
			*/

			if ( _ct > 0 )
			{
				_scarr[_ct] = new SpringConstraint(_ptarr[_ct-1], _ptarr[_ct], 4, true);
				defaultGroup.addConstraint( _scarr[_ct] );

				if ( _ct >= _maxpts )
				{
					_scarr[_ct+1] = new SpringConstraint(_ptarr[_ct], _ptarr[0], 4, true);
					defaultGroup.addConstraint( _scarr[_ct+1] );

					dropBall();
				}
			}

			/* Update
			------------------
			*/
			_ct++;

			/* Check end
			------------------
			*/
			if ( _ct > _maxpts ) follow.removeEventListener ( Event.ENTER_FRAME, drawCircleBounds );

		}

		private function dropBall():void
		{
			db = new DragableCircleParticle(160, 150, 30, false, 10, .3);
			db.setStyle(0, 0, 0, 0x993300);
			defaultGroup.addParticle(db);
		}

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

	}
}
</pre>
<p>and the Ball.as file ( this is used as the red ball )</p>
<pre name="code" class="c-sharp">
package {
	import flash.display.Sprite;

	public class Ball extends Sprite {
		public var radius:Number;
		private var color:uint;
		public var xpos:Number = 0;
		public var ypos:Number = 0;
		public var zpos:Number = 0;
		public var vx:Number = 0;
		public var vy:Number = 0;
		public var vz:Number = 0;
		public var mass:Number = 1;

		public function Ball(radius:Number=10, color:uint=0xff0000) {
			this.radius = radius;
			this.color = color;
			init();
		}
		public function init():void {
			graphics.lineStyle(0);
			graphics.beginFill(color);
			graphics.drawCircle(0, 0, radius);
			graphics.endFill();
		}
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://manewc.com/2008/12/10/ape-animation-within-circular-bounds/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Image Gallery &#8211; Part VI &#8211; Active Image</title>
		<link>http://manewc.com/2008/12/09/image-gallery-part-vi-active-image/</link>
		<comments>http://manewc.com/2008/12/09/image-gallery-part-vi-active-image/#comments</comments>
		<pubDate>Tue, 09 Dec 2008 18:20:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Actionscript XML]]></category>
		<category><![CDATA[Image Gallery Project]]></category>

		<guid isPermaLink="false">http://manewc.com/?p=240</guid>
		<description><![CDATA[I updated 2 files: ImageGallery.as and Thumbnail.as to allow for the display of the first large image (or any other image you assign as the CurrentIndex variable) in the xml file and to display an active/inactive state for the thumbnail images:

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_ImageGallery_1380845911"
			class="flashmovie"
			width="700"
			height="750">
	<param name="movie" value="/projects/flash/ImageGallery6/ImageGallery.swf" />
	<param name="allowfullscreen" value="true" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/projects/flash/ImageGallery6/ImageGallery.swf"
			name="fm_ImageGallery_1380845911"
			width="700"
			height="750">
		<param name="allowfullscreen" value="true" />
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
I will be the first to admit that these files [...]]]></description>
			<content:encoded><![CDATA[<p>I updated 2 files: ImageGallery.as and Thumbnail.as to allow for the display of the first large image (or any other image you assign as the CurrentIndex variable) in the xml file and to display an active/inactive state for the thumbnail images:</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_ImageGallery_1734850386"
			class="flashmovie"
			width="700"
			height="750">
	<param name="movie" value="/projects/flash/ImageGallery6/ImageGallery.swf" />
	<param name="allowfullscreen" value="true" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/projects/flash/ImageGallery6/ImageGallery.swf"
			name="fm_ImageGallery_1734850386"
			width="700"
			height="750">
		<param name="allowfullscreen" value="true" />
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p><strong>I will be the first to admit that these files need to be cleaned up and properly coded.. but this will be a good base for a clean future project.</strong></p>
<pre name="code" class="c-sharp">
package
{
	import flash.display.Sprite;
	import flash.display.Shape;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import caurina.transitions.*;

	public class ImageGallery extends Sprite
	{
		private var ThumbArray:Array;
		private var tobj:Array; // thumb object array
		private var thumbMargin:Number = 5;
		private var ThumbNavigation:Sprite; // this is to hold all the thumbnails
		private var incrementArr:Array;
		private var VisibleThumbnails:Number = 4; // this will set the number of thumbnails that will be visible.
		private var MaskWidth:Number;
		private var myMask:Shape;
		private var maskHeight:Number = 100;
		private var nb:Sprite;
		private var bb:Sprite;
		private var nbs:Shape; // next button
		private var bbs:Shape; // back button
		private var CurrentIndex:Number = 0;
		private var ButtonIndex:Number;
		private var ButtonCounter:Number = 0;
		private var beginPoint:Number;
		private var endPoint:Number;
		private var destPoint:Number;
		private var ThumbNavigationOffset:Number;
		private var MainImage:LargeImage;
		private var MainImageMask:Shape;

		public function ImageGallery(iarr:Array)
		{
			// the array of the thumbnail images
			ThumbArray = new Array();

			for ( var g:uint = 0; g < iarr.length; g++ )
			{
				ThumbArray[g] = new Array ( iarr[g][0], iarr[g][1] );
			}

			addEventListener ( Event.ADDED_TO_STAGE, init );

			ButtonIndex = VisibleThumbnails;
		}

		private function init(e:Event):void
		{
			// the holder movie to hold all the thumbnail images
			ThumbNavigation = new Sprite();
			addChild ( ThumbNavigation );
			// put it off the stage
			ThumbNavigation.y = stage.stageHeight + maskHeight;

			// create the thumbnails
			tobj = new Array;

			for ( var c:uint = 0; c < ThumbArray.length; c++ )
			{
				// create a thumbnail image
				tobj.push ( new Thumbnail( ThumbArray[c][0], c ) );
			}

			// set the event to make sure all images are loaded
			addEventListener ( Event.ENTER_FRAME, checkLoadedThumb );

			// THIS IS WHERE WE WILL SET THE DEFAULT LARGE IMAGE
			DisplayLargeImage ( CurrentIndex ); // display the large image
		}

		private function checkLoadedThumb ( e:Event ):void
		{
			var loadCounter:Number = 0;

			for ( var d:uint = 0; d < ThumbArray.length; d++ )
			{
				if ( tobj[d].myWidth > 0 )
				{
					loadCounter++;
				}
			}

			if ( loadCounter == ThumbArray.length )
			{
				removeEventListener ( Event.ENTER_FRAME, checkLoadedThumb );

				// position the thumbnails
				positionThumbs();
			}
		}

		private function positionThumbs():void
		{
			var totalWidth:Number = 0;
			incrementArr = new Array();

			for ( var v:uint = 0; v < ThumbArray.length; v++ )
			{
				tobj[v].x = totalWidth;
				tobj[v].alpha = 0;

				// set the increments for each slide position when moving left to right
				incrementArr.push ( totalWidth );

				trace ( incrementArr[v] );
				// check for the width of the mask to go over thumbnail navigation
				if ( v == VisibleThumbnails )
				{
					MaskWidth = totalWidth;

					// create the mask
					CreateThumbnailMask();
				}

				totalWidth += thumbMargin + tobj[v].myWidth;
				// add the thumbnail to the stage
				ThumbNavigation.addChild ( tobj[v] );

				// thumbnail is alpha 0, let's fade it up to 80%
				Tweener.addTween(tobj[v], {alpha: .8, time:.8, transition:"easeOut"});

				// add the mouseevents
				tobj[v].addEventListener ( MouseEvent.MOUSE_OVER, ThumbOver );
				tobj[v].addEventListener ( MouseEvent.MOUSE_DOWN, ThumbDown );
				tobj[v].addEventListener ( MouseEvent.MOUSE_OUT, ThumbOut );
			}

			// show the active state of the thumbnail:
			tobj[CurrentIndex].activeState(); // set the look of the active thumbnail
		}

		private function CreateThumbnailMask():void
		{
			// Center the Menu
			ThumbNavigation.x = (stage.stageWidth / 2) - (MaskWidth / 2);
			ThumbNavigationOffset = ThumbNavigation.x;

			// Create the Mask
			myMask = new Shape();
            myMask.graphics.beginFill(0x000000);
            myMask.graphics.drawRect(ThumbNavigation.x, stage.stageHeight-maskHeight, MaskWidth, maskHeight);
            myMask.graphics.endFill();

			addChild ( myMask );

			// set the mask
			ThumbNavigation.mask = myMask;

			// show the Menu on Y axis
			Tweener.addTween(ThumbNavigation,{y:stage.stageHeight-maskHeight, time:.5, transition:"easeOut"});

			// create the next button
			NextButton();

			// create the back button
			BackButton();

			// setupUI;
			SetupUI();
		}

		private function ThumbOver (m:MouseEvent):void
		{
			if ( !m.currentTarget.getState() )
			{
				Tweener.addTween(m.currentTarget, {alpha: 1, time:.8, transition:"easeOutBack"});
				Tweener.addTween(m.currentTarget, {y: -20, time:2, transition:"easeOut"});
			}
		}

		private function DisplayLargeImage (n:int):void
		{
			if ( MainImage ) removeChild ( MainImage );

			MainImage = new LargeImage ( ThumbArray[n][1] );
			addChildAt ( MainImage, 0 );

			// Create the Main Image Mask
			MainImageMask = new Shape();
            MainImageMask.graphics.beginFill(0x000000);
            MainImageMask.graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight-maskHeight-10);
            MainImageMask.graphics.endFill();
			addChild ( MainImageMask );

			MainImage.mask = MainImageMask;
		}

		private function ThumbDown (m:MouseEvent):void
		{
			if ( !m.currentTarget.getState() )
			{
				// display the default State of the previous selected thumbnail
				tobj[CurrentIndex].defaultState();

				// re initialize the index value
				CurrentIndex = m.currentTarget.myId;

				// display the active state
				m.currentTarget.activeState();

				DisplayLargeImage ( CurrentIndex );
			}
		}

		private function ThumbOut (m:MouseEvent):void
		{
			if ( !m.currentTarget.getState() ) Tweener.addTween(m.currentTarget, {alpha: .8, time:2, transition:"easeOutBack"});

			Tweener.addTween(m.currentTarget, {y: 0, time:2, transition:"easeOut"});
		}

		private function NextButton():void
		{
			nbs = new Shape();
            nbs.graphics.beginFill(0x000000);
            nbs.graphics.drawRect(stage.stageWidth - 20, stage.stageHeight-maskHeight, 20, maskHeight);
            nbs.graphics.endFill();

			nb = new Sprite();
			nb.name = "nextbutton";
			addChild ( nb );

			nb.addChild ( nbs );

			nb.addEventListener( MouseEvent.MOUSE_DOWN, MoveThumbnails );
		}

		private function BackButton():void
		{
			bbs = new Shape();
            bbs.graphics.beginFill(0x000000);
            //myMask.graphics.lineStyle(1, 0x000000);
            bbs.graphics.drawRect(0, stage.stageHeight-maskHeight, 20, maskHeight);
            bbs.graphics.endFill();

			bb = new Sprite();
			addChild ( bb );
			bb.name = "backbutton";
			bb.addChild ( bbs );

			bb.addEventListener( MouseEvent.MOUSE_DOWN, MoveThumbnails );
		}

		private function MoveThumbnails(m:MouseEvent):void
		{
			// check the current index and slide accordingly
			if ( m.currentTarget.name == "nextbutton" &#038;&#038; ButtonIndex < ThumbArray.length )
			{
				nb.removeEventListener( MouseEvent.MOUSE_DOWN, MoveThumbnails );

				ButtonIndex++;

				destPoint = ThumbNavigationOffset - incrementArr[++ButtonCounter];

				Tweener.addTween(ThumbNavigation,{x:destPoint, time:.6, transition:"easeOut", onComplete:EnableButtons("nextbutton")});
			}
			else if ( m.currentTarget.name == "backbutton" &#038;&#038; ButtonIndex > 0 )
			{
				bb.removeEventListener( MouseEvent.MOUSE_DOWN, MoveThumbnails );

				ButtonIndex--;

				destPoint = ThumbNavigationOffset - incrementArr[--ButtonCounter];
				Tweener.addTween(ThumbNavigation,{x:destPoint, time:.5, transition:"easeOut", onComplete:EnableButtons("backbutton")});
			}

			SetupUI();
		}

		private function EnableButtons(btnId:String):void
		{
			if ( btnId == "nextbutton" ) nb.addEventListener( MouseEvent.MOUSE_DOWN, MoveThumbnails );
			if ( btnId == "backbutton" ) bb.addEventListener( MouseEvent.MOUSE_DOWN, MoveThumbnails );
		}

		private function SetupUI():void
		{
			// this function is to control the visibility of the next and back buttons
			trace ( "ButtonIndex: " + ButtonIndex + " " + VisibleThumbnails );
			if ( ButtonIndex > VisibleThumbnails )
			{
				Tweener.addTween(bb, {alpha: 1, time:2, transition:"easeOut"});
				// Tweener.addTween(nb, {alpha: 1, time:2, transition:"easeOut"});
				bb.addEventListener( MouseEvent.MOUSE_DOWN, MoveThumbnails );
			}
			else if ( ButtonIndex == VisibleThumbnails )
			{
				Tweener.addTween(bb, {alpha: 0, time:2, transition:"easeOut"});
				bb.removeEventListener( MouseEvent.MOUSE_DOWN, MoveThumbnails );
			}

			if ( ButtonIndex == ThumbArray.length )
			{
				Tweener.addTween(nb, {alpha: 0, time:2, transition:"easeOut"});
				nb.removeEventListener( MouseEvent.MOUSE_DOWN, MoveThumbnails );
			}
			else
			{
				Tweener.addTween(nb, {alpha: 1, time:2, transition:"easeOut"});
				nb.addEventListener( MouseEvent.MOUSE_DOWN, MoveThumbnails );
			}
		}
	}
}
</pre>
<p>and the Thumbnail.as file</p>
<pre name="code" class="c-sharp">
package
{
	import flash.display.Sprite;
	import flash.events.Event;
	import caurina.transitions.*;

	public class Thumbnail extends Sprite
	{
		private var thumb:LoadImage;
		public var myWidth:Number;
		public var myId:Number;
		public var active:Boolean;

		public function Thumbnail(img:String, id:Number)
		{
			// set this id
			myId = id;

			// load in the image
			thumb = new LoadImage( img );
			addChild ( thumb );

			// check the image load
			addEventListener ( Event.ENTER_FRAME, checkLoad );
		}

		private function checkLoad ( e:Event ):void
		{
			if ( thumb.setComplete() &#038;&#038; thumb.w() > 0)
			{
				// remove the listener
				removeEventListener ( Event.ENTER_FRAME, checkLoad );

				// get the width
				myWidth = thumb.w();
			}
		}

		public function defaultState()
		{
			active = false;
			Tweener.addTween(this, {alpha: 1, time:1, transition:"easeOut"});
		}

		public function activeState()
		{
			active = true;
			Tweener.addTween(this, {alpha: .1, time:3, transition:"easeOut"});
		}

		public function getState()
		{
			return active;
		}
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://manewc.com/2008/12/09/image-gallery-part-vi-active-image/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>APE &#8211; Basketball</title>
		<link>http://manewc.com/2008/12/04/ape-basketball/</link>
		<comments>http://manewc.com/2008/12/04/ape-basketball/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 17:42:30 +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=236</guid>
		<description><![CDATA[To play around a little more from the find of the draggable objects in APE I made a little demo of a basketball game.

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_APEBasketballPost_1379394791"
			class="flashmovie"
			width="700"
			height="700">
	<param name="movie" value="/projects/flash/APEBasketball/APEBasketballPost.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/projects/flash/APEBasketball/APEBasketballPost.swf"
			name="fm_APEBasketballPost_1379394791"
			width="700"
			height="700">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
Here is the code:

package {
    import flash.display.Sprite;
    import flash.events.Event;
	import flash.events.MouseEvent;

    import org.cove.ape.*;

	public class Main extends Sprite {

		private var circle:DragableCircleParticle;
		private [...]]]></description>
			<content:encoded><![CDATA[<p>To play around a little more from the find of the <a href="/2008/12/03/ape-multiple-draggable-particles/">draggable objects in APE</a> I made a little demo of a basketball game.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_APEBasketballPost_2144145075"
			class="flashmovie"
			width="700"
			height="700">
	<param name="movie" value="/projects/flash/APEBasketball/APEBasketballPost.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/projects/flash/APEBasketball/APEBasketballPost.swf"
			name="fm_APEBasketballPost_2144145075"
			width="700"
			height="700">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>Here is the code:</p>
<pre name="code" class="c-sharp">
package {
    import flash.display.Sprite;
    import flash.events.Event;
	import flash.events.MouseEvent;

    import org.cove.ape.*;

	public class Main extends Sprite {

		private var circle:DragableCircleParticle;
		private var circle2:DragableCircleParticle;

		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,5));

			var defaultGroup:Group = new Group();

			defaultGroup.collideInternal = true;

			/* RECTANGLE PROPERTIES
				x:Number,
				y:Number,
				width:Number,
				height:Number,
				rotation:Number = 0,
				fixed:Boolean = false,
				mass:Number = 1,
				elasticity:Number = 0.3,
				friction:Number = 0
			*/
            var floor:RectangleParticle = new RectangleParticle(stage.stageWidth/2, stage.stageHeight + 48, stage.stageWidth, 100, 0, true, 10);
            defaultGroup.addParticle(floor);

			var ceil:RectangleParticle = new RectangleParticle(stage.stageWidth/2, -50, stage.stageWidth, 100, 0, true, 10);
            defaultGroup.addParticle(ceil);

			var left:RectangleParticle = new RectangleParticle(-25, stage.stageHeight/2, 50, stage.stageHeight, 0, true, 10);
            defaultGroup.addParticle(left);

			var right:RectangleParticle = new RectangleParticle(stage.stageWidth+25, stage.stageHeight/2, 50, stage.stageHeight, 0, true, 10);
            defaultGroup.addParticle(right);

			/* CIRCLE PROPERTIES
				x:Number,
				y:Number,
				radius:Number,
				fixed:Boolean = false,
				mass:Number = 1,
				elasticity:Number = 0.3,
				friction:Number = 0
			*/

			/* BASKETBALL
			------------------
			*/
           	circle = new DragableCircleParticle(350, 150, 30, false, 20, .5);
			circle.setStyle(0, 0, 0, 0x993300);
			defaultGroup.addParticle(circle);

			/* HOOP &#038; NET
			------------------
			*/
			var hl:CircleParticle = new CircleParticle( stage.stageWidth - 180, 300, 5, true );
			defaultGroup.addParticle ( hl ); // hoop top left

			var hl2:CircleParticle = new CircleParticle( stage.stageWidth - 170, 350, 5, false );
			defaultGroup.addParticle ( hl2 ); // hoop top left

			var hl3:CircleParticle = new CircleParticle( stage.stageWidth - 145, 430, 5, false );
			defaultGroup.addParticle ( hl3 ); // hoop top left

			var hlConnector:SpringConstraint = new SpringConstraint(hl, hl2, 0.5, true, 8);
			hlConnector.setStyle(0, 0x2c2c2c, 1, 0x2c2c2c);
			defaultGroup.addConstraint(hlConnector);  

			var hl2Connector:SpringConstraint = new SpringConstraint(hl2, hl3, 0.5, true, 8);
			hl2Connector.setStyle(0, 0x2c2c2c, 1, 0x2c2c2c);
			defaultGroup.addConstraint(hl2Connector);  

			var hr:CircleParticle = new CircleParticle( stage.stageWidth - 50, 300, 5, true );
			defaultGroup.addParticle ( hr ); // hoop top right

			var hr2:CircleParticle = new CircleParticle( stage.stageWidth - 60, 350, 5, false );
			defaultGroup.addParticle ( hr2 ); // hoop top left

			var hr3:CircleParticle = new CircleParticle( stage.stageWidth - 85, 430, 5, false );
			defaultGroup.addParticle ( hr3 ); // hoop top left

			var hrConnector:SpringConstraint = new SpringConstraint(hr, hr2, 0.5, true, 8);
			hrConnector.setStyle(0, 0x2c2c2c, 1, 0x2c2c2c);
			defaultGroup.addConstraint(hrConnector);

			var hr2Connector:SpringConstraint = new SpringConstraint(hr2, hr3, 0.5, true, 8);
			hr2Connector.setStyle(0, 0x2c2c2c, 1, 0x2c2c2c);
			defaultGroup.addConstraint(hr2Connector);

			// top of hoop connector
			var thoop:SpringConstraint = new SpringConstraint(hl, hr, 4, false, 8);
			thoop.setStyle(4, 0xffffff, 4, 0xffffff);
			defaultGroup.addConstraint(thoop);

			// bottom of hoop
			var bhoop:SpringConstraint = new SpringConstraint(hl2, hr2, 0.5, false, 8);
			bhoop.setStyle(0, 0x2c2c2c, 1, 0x2c2c2c);
			defaultGroup.addConstraint(bhoop);

			var bhoop2:SpringConstraint = new SpringConstraint(hl3, hr3, 0.5, false, 8);
			bhoop2.setStyle(0, 0x2c2c2c, 1, 0x2c2c2c);
			defaultGroup.addConstraint(bhoop2);

			// backboard
			var bb:RectangleParticle = new RectangleParticle(stage.stageWidth - 20, 220, 5, 200, 0, true, 1,.01);
			defaultGroup.addParticle ( bb ); // backboard

			APEngine.addGroup(defaultGroup);
			addEventListener(Event.ENTER_FRAME, run);
		}

		private function run(e:Event):void
		{
			APEngine.step();
			APEngine.paint();
		}
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://manewc.com/2008/12/04/ape-basketball/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>APE &#8211; Multiple Draggable Particles</title>
		<link>http://manewc.com/2008/12/03/ape-multiple-draggable-particles/</link>
		<comments>http://manewc.com/2008/12/03/ape-multiple-draggable-particles/#comments</comments>
		<pubDate>Wed, 03 Dec 2008 19:05:43 +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=233</guid>
		<description><![CDATA[I was trying to figure out a way to improve my initial movie that stop and starts the APE engine to allow for the user to drag an object. After mucking around with the original APE classes, I found in Google Groups that there are 2 new classes to allow the use to drag either [...]]]></description>
			<content:encoded><![CDATA[<p>I was trying to figure out a way to improve my <a href="http://manewc.com/2008/04/22/dragging-a-particle-with-ape-part-ii/">initial movie</a> that stop and starts the APE engine to allow for the user to drag an object. After mucking around with the original APE classes, I found in Google Groups that there are 2 new classes to allow the use to drag either a CircleParticle or a RectangleParticle.</p>
<p>You can grab the zip file here: <a href="http://ape-general.googlegroups.com/web/dragable_particles.zip">http://ape-general.googlegroups.com/web/dragable_particles.zip</a> and here is what can be produced:</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_APEObjectDrag_1737523188"
			class="flashmovie"
			width="700"
			height="350">
	<param name="movie" value="/projects/flash/APEObjectDragMultiple/APEObjectDrag.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/projects/flash/APEObjectDragMultiple/APEObjectDrag.swf"
			name="fm_APEObjectDrag_1737523188"
			width="700"
			height="350">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<pre name="code" class="c-sharp">
package {
    import flash.display.Sprite;
    import flash.events.Event;
	import flash.events.MouseEvent;

    import org.cove.ape.*;

	public class Main extends Sprite {

		private var circle:DragableCircleParticle;
		private var circle2:DragableCircleParticle;

		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));

			var defaultGroup:Group = new Group();

			defaultGroup.collideInternal = true;

            var rect:RectangleParticle = new RectangleParticle(350, 348, 700, 20, 0, true);
            defaultGroup.addParticle(rect);

           	circle = new DragableCircleParticle(350, 150, 25);
			defaultGroup.addParticle(circle);

			circle2 = new DragableCircleParticle(300, 150, 25);
			defaultGroup.addParticle(circle2);

			APEngine.addGroup(defaultGroup);

			addEventListener(Event.ENTER_FRAME, run);
		}

		private function run(e:Event):void
		{
			APEngine.step();
			APEngine.paint();
		}
	}
}
</pre>
<p>Here is the new class file located in org/cove/ape/DragableCircleParticle.as (relative to my Main.as file)</p>
<pre name="code" class="c-sharp">
package org.cove.ape{
	import flash.events.MouseEvent;
	import org.cove.ape.*;
	public class DragableCircleParticle extends CircleParticle{
		private var mouseIsDown:Boolean;
		public function DragableCircleParticle(
				x:Number,
				y:Number,
				radius:Number,
				fixed:Boolean = false,
				mass:Number = 1,
				elasticity:Number = 0.3,
				friction:Number = 0){
			super(x, y, radius, fixed, mass, elasticity, friction);
			alwaysRepaint = fixed;
			mouseIsDown = false;
			sprite.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
			sprite.stage.addEventListener(MouseEvent.MOUSE_UP,mouseUpHandler);
			sprite.stage.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
		}
		private function mouseDownHandler(evt:MouseEvent):void{
			mouseIsDown = true;					// on mouse down set mouseIsDown to true
			curr.setTo(evt.stageX,evt.stageY);	// set the current position of the particle to the position of the mouse
			prev.setTo(evt.stageX,evt.stageY);	// set the previous position of the particle to the position of the mouse
		}
		private function mouseUpHandler(evt:MouseEvent):void{
			mouseIsDown = false;			// on mouse up set mouseIsDown to false
		}
		private function mouseMoveHandler(evt:MouseEvent):void{
			if(mouseIsDown){				// On mouse move if the mouse is down
				prev.copy(curr);			// set the previous position to the curent position of the particle
				curr.setTo(evt.stageX,evt.stageY);	// set the current position to the position of the mouse
			}
		}
		public override function update(dt2:Number):void {
			if(!mouseIsDown){		// Don't update if the mouse is down
				super.update(dt2);
			}
		}
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://manewc.com/2008/12/03/ape-multiple-draggable-particles/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>TextArea Component</title>
		<link>http://manewc.com/2008/10/02/textarea-component/</link>
		<comments>http://manewc.com/2008/10/02/textarea-component/#comments</comments>
		<pubDate>Thu, 02 Oct 2008 17:16:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Flash Components]]></category>

		<guid isPermaLink="false">http://manewc.com/?p=209</guid>
		<description><![CDATA[So I was in need of using the TextArea Component because it offers the scrollbar attachment ability. Out of the box it works fine, but I wanted to get rid of the border and just display the scrollbar. I found a simple solution to do this with this line of code:

myTextAreaComponent.setStyle("upSkin",Sprite);

This was great, but if [...]]]></description>
			<content:encoded><![CDATA[<p>So I was in need of using the TextArea Component because it offers the scrollbar attachment ability. Out of the box it works fine, but I wanted to get rid of the border and just display the scrollbar. I found a simple solution to do this with this line of code:</p>
<pre name="code" class="c-sharp">
myTextAreaComponent.setStyle("upSkin",Sprite);
</pre>
<p>This was great, but if the user clicked anywhere within the text area, there would be this blue border that appeared.. so to get rid of that, I used this line of code:</p>
<pre name="code" class="c-sharp">
myTextAreaComponent.setStyle("focusRectSkin",Sprite);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://manewc.com/2008/10/02/textarea-component/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mouseEnabled</title>
		<link>http://manewc.com/2008/09/30/mouseenabled/</link>
		<comments>http://manewc.com/2008/09/30/mouseenabled/#comments</comments>
		<pubDate>Tue, 30 Sep 2008 17:56:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>

		<guid isPermaLink="false">http://manewc.com/?p=208</guid>
		<description><![CDATA[So I finally resolved this issue I was experiencing. I had a Textfield that was added within a Sprite, and the text field was to represent a link. The only issue was that I need the cursor to essentially change to a pointer from an arrow when the user hovered over the Textfield. The solution [...]]]></description>
			<content:encoded><![CDATA[<p>So I finally resolved this issue I was experiencing. I had a Textfield that was added within a Sprite, and the text field was to represent a link. The only issue was that I need the cursor to essentially change to a pointer from an arrow when the user hovered over the Textfield. The solution was to toggle the mouseEnabled property of the Textfield to false in addition to setting the Sprite&#8217;s buttonMode = true.</p>
]]></content:encoded>
			<wfw:commentRss>http://manewc.com/2008/09/30/mouseenabled/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Searching Array Indexes with indexOf and lastIndexOf methods</title>
		<link>http://manewc.com/2008/09/24/searching-array-indexes-with-indexof-and-lastindexof-methods/</link>
		<comments>http://manewc.com/2008/09/24/searching-array-indexes-with-indexof-and-lastindexof-methods/#comments</comments>
		<pubDate>Wed, 24 Sep 2008 18:12:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Arrays]]></category>

		<guid isPermaLink="false">http://manewc.com/?p=203</guid>
		<description><![CDATA[
package
{
	import flash.display.Sprite;

	public class ArrayFind extends Sprite
	{
		private var myArray:Array = new Array("one", "two", "three", "five", "ten", "twenty", "two", "sixty");

		public function ArrayFind()
		{
			// find the location of "five"
			trace ( myArray.indexOf( "five" ) ); // outputs 3

			// find the location of "two" from the beginning
			trace ( myArray.indexOf( "two" ) ); // outputs 1

			// find the location of "two" from [...]]]></description>
			<content:encoded><![CDATA[<pre name="code" class="c-sharp">
package
{
	import flash.display.Sprite;

	public class ArrayFind extends Sprite
	{
		private var myArray:Array = new Array("one", "two", "three", "five", "ten", "twenty", "two", "sixty");

		public function ArrayFind()
		{
			// find the location of "five"
			trace ( myArray.indexOf( "five" ) ); // outputs 3

			// find the location of "two" from the beginning
			trace ( myArray.indexOf( "two" ) ); // outputs 1

			// find the location of "two" from the end
			trace ( myArray.lastIndexOf( "two" ) ); // outputs 6

			// check to see if element is in the array
			trace ( myArray.indexOf( "five hundred" ) ); // outputs -1
		}
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://manewc.com/2008/09/24/searching-array-indexes-with-indexof-and-lastindexof-methods/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Bitmap Data CopyChannel Method</title>
		<link>http://manewc.com/2008/09/23/bitmap-data-copychannel-method/</link>
		<comments>http://manewc.com/2008/09/23/bitmap-data-copychannel-method/#comments</comments>
		<pubDate>Tue, 23 Sep 2008 17:33:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>

		<guid isPermaLink="false">http://manewc.com/?p=202</guid>
		<description><![CDATA[Transfers data from one channel of another BitmapData object or the current    BitmapData object into a channel of the current BitmapData object.

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_CopyChannel_1909872573"
			class="flashmovie"
			width="700"
			height="300">
	<param name="movie" value="/projects/flash/CopyChannel/CopyChannel.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/projects/flash/CopyChannel/CopyChannel.swf"
			name="fm_CopyChannel_1909872573"
			width="700"
			height="300">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>

package
{
	import flash.display.Sprite;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.geom.Rectangle;
	import flash.geom.Point;

	public class CopyChannel extends Sprite
	{
		public function CopyChannel()
		{
			var bmd:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0x336699);
			var rect:Rectangle = new Rectangle(0, 0, 200, 200);
			var pt:Point [...]]]></description>
			<content:encoded><![CDATA[<p>Transfers data from one channel of another BitmapData object or the current    BitmapData object into a channel of the current BitmapData object.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_CopyChannel_136054445"
			class="flashmovie"
			width="700"
			height="300">
	<param name="movie" value="/projects/flash/CopyChannel/CopyChannel.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/projects/flash/CopyChannel/CopyChannel.swf"
			name="fm_CopyChannel_136054445"
			width="700"
			height="300">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<pre name="code" class="c-sharp">
package
{
	import flash.display.Sprite;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.geom.Rectangle;
	import flash.geom.Point;

	public class CopyChannel extends Sprite
	{
		public function CopyChannel()
		{
			var bmd:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0x336699);
			var rect:Rectangle = new Rectangle(0, 0, 200, 200);
			var pt:Point = new Point(10, 10);

			bmd.copyChannel(bmd, rect, pt, 1, 4); // the 1 and 4 represent BitmapDataChannel.RED, BitmapDataChannel.BLUE respectively

			var bm:Bitmap = new Bitmap(bmd);
			this.addChild(bm);
		}
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://manewc.com/2008/09/23/bitmap-data-copychannel-method/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
