<?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; Drawing API</title>
	<atom:link href="http://manewc.com/category/drawing-api/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>APE Project &#8211; Step 4 &#8211; Adding a Car</title>
		<link>http://manewc.com/2008/08/08/ape-project-step-4-adding-a-car/</link>
		<comments>http://manewc.com/2008/08/08/ape-project-step-4-adding-a-car/#comments</comments>
		<pubDate>Fri, 08 Aug 2008 17:14:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[APE - Actionscript Physics Engine]]></category>
		<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Audio]]></category>
		<category><![CDATA[Drawing API]]></category>

		<guid isPermaLink="false">http://manewc.com/?p=168</guid>
		<description><![CDATA[So I pulled a Car class from an older project of mine and decided to integrate it into my project here&#8230;. gotta love the ease of integration of classes with Actionscript 3! I also added in some walls to the left and right side to prevent the car and balls to move outside of the [...]]]></description>
			<content:encoded><![CDATA[<p>So I pulled a Car class from an <a href="http://manewc.com/2008/03/28/as-3-as-physics-engine-ape-car-demo/">older project of mine</a> and decided to integrate it into my project here&#8230;. gotta love the ease of integration of classes with Actionscript 3! I also added in some walls to the left and right side to prevent the car and balls to move outside of the viewable area of the movie.</p>
<p>For those who have not followed along this project, you can drag your mouse across the screen to create colidable rectangle particles for the balls and car to bounce off of.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_APEProject_1875130024"
			class="flashmovie"
			width="700"
			height="700">
	<param name="movie" value="/projects/flash/APEProject4/APEProject.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/projects/flash/APEProject4/APEProject.swf"
			name="fm_APEProject_1875130024"
			width="700"
			height="700">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>The Main Document class:</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 circle:CircleParticle;
		private var circleGroup:Group;
        private var defaultGroup:Group;

		private var car:Car;

		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(MouseEvent.MOUSE_DOWN, beginRectDraw);
			stage.addEventListener(MouseEvent.MOUSE_UP, stopRectDraw);

			// build the UI
			buildUI();
		}

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

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

			// remove the listeners
			stage.addEventListener(MouseEvent.MOUSE_DOWN, beginRectDraw);
			stage.addEventListener(MouseEvent.MOUSE_UP, stopRectDraw);

			// now draw the rectangle
			drawRectangle();
		}

		private function drawRectangle():void
		{
			if ( beginY < 660 &#038;&#038; endY < 660 )
			{
				dynRect = new RectangleParticle(beginX + ( (endX - beginX)/2 ), beginY + ((endY - beginY)/2), endX - beginX, endY - beginY, 0, true);
            	defaultGroup.addParticle(dynRect);
			}
		}

		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
		{
			car = new Car(Math.random() * 0xffffff,Math.random() * 0xffffff);
            APEngine.addGroup(car);
			defaultGroup.addCollidable(car);
			circleGroup.addCollidable(car);

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

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

			var btnAddCar:Button = new Button();
            btnAddCar.width = 65;
            btnAddCar.height = 25;
            btnAddCar.move ( 200, stage.stageHeight - 20 - btnAddCar.height / 2 );
            btnAddCar.label = "Add Car";      

            addChild(btnAddCar);

            btnAddCar.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 original Car class file:</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(colorOne:uint=0xffffff, colorTwo:uint=0xffffff) {

			wheelParticleA = new WheelParticle(140,30,14,false,2);
			wheelParticleA.setStyle(0, colorOne, 1, colorTwo);
			addParticle(wheelParticleA);
			wheelParticleA.sprite.cacheAsBitmap = true;

			var suspA:CircleParticle = new CircleParticle(140,0,7,false,10);
			suspA.mass = 0.001;
			suspA.setStyle(1, colorOne, 1, colorOne);
			addParticle(suspA);

			wheelParticleB = new WheelParticle(200,30,14,false,2);
			wheelParticleB.setStyle(0, colorOne, 1, colorTwo);
			addParticle(wheelParticleB);
			wheelParticleB.sprite.cacheAsBitmap = true;

			var suspB:CircleParticle = new CircleParticle(200,0,7,false,10);
			suspB.mass = 0.001;
			suspB.setStyle(1, colorOne, 1, colorOne);
			addParticle(suspB);

			var wheelAConnector:SpringConstraint = new SpringConstraint(wheelParticleA, suspB, .7, false, 8);
			wheelAConnector.setStyle(0, colorOne, 1, colorTwo);
			addConstraint(wheelAConnector);

			var shockAConnector:SpringConstraint = new SpringConstraint(wheelParticleA, suspA, .6, false, 8);
			shockAConnector.setStyle(0, colorOne, 1, colorTwo);
			addConstraint(shockAConnector);

			var wheelBConnector:SpringConstraint = new SpringConstraint(wheelParticleB, suspA, 0.5, false, 8);
			wheelBConnector.setStyle(0, colorOne, 1, colorTwo);
			addConstraint(wheelBConnector);

			var bodyConnector:SpringConstraint = new SpringConstraint(suspA, suspB, 0.2, true, 8);
			bodyConnector.setStyle(0, colorOne, 1, colorTwo);
			addConstraint(bodyConnector);

			var shockBConnector:SpringConstraint = new SpringConstraint(wheelParticleB, suspB, .6, false, 8);
			shockBConnector.setStyle(0, colorOne, 1, colorTwo);
			addConstraint(shockBConnector);

			var axelConnector:SpringConstraint = new SpringConstraint(wheelParticleA, wheelParticleB, .7, false, 8);
			axelConnector.setStyle(0, colorOne, 1, colorTwo);
			addConstraint(axelConnector);
		}

		public function set speed(s:Number):void {
			wheelParticleA.angularVelocity = s;
			wheelParticleB.angularVelocity = s;
		}
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://manewc.com/2008/08/08/ape-project-step-4-adding-a-car/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating Multiple Objects with Actionscript</title>
		<link>http://manewc.com/2008/06/13/creating-multiple-objects-with-actionscript/</link>
		<comments>http://manewc.com/2008/06/13/creating-multiple-objects-with-actionscript/#comments</comments>
		<pubDate>Fri, 13 Jun 2008 18:31:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Drawing API]]></category>

		<guid isPermaLink="false">http://manewc.com/?p=130</guid>
		<description><![CDATA[So I have recently had a number of requests on how to create multiple objects of a class as well as how to manipulate them. I decided to write this short demo which will just create an object, which is in a file called c.as which happens to be just a circle. If you click [...]]]></description>
			<content:encoded><![CDATA[<p>So I have recently had a number of requests on how to create multiple objects of a class as well as how to manipulate them. I decided to write this short demo which will just create an object, which is in a file called c.as which happens to be just a circle. If you click the stage, the objects will simply just change their x and y positions of the stage.</p>

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

	public class ObjectPlacement extends Sprite
	{
		private var cArr:Array; // an array of all my circle objects

		public function ObjectPlacement()
		{
			init();
		}

		private function init():void
		{
			// let's build 4 circles from our Circle class file -> c.as
			// we will pass in a random radius and a random color
			BuildCircles ( 10 );

			// add a Stage Event Listener for Mouse Down
			stage.addEventListener ( MouseEvent.MOUSE_DOWN, changePositions );
		}

		private function BuildCircles ( i:Number ):void
		{
			cArr = new Array();

			for ( var ct:uint = 0; ct < i; ct++ )
			{
				// note: in the line below 'c' represents the class called 'c' - this class is in the file 'c.as'
				cArr.push ( new c ( Math.random() * 20, Math.random() * 0xffffff ) );

				// add this object to the stage
				addChild ( cArr[ct] );

				// move this object to some point on the stage
				cArr[ct].x = Math.random() * stage.stageWidth;
				cArr[ct].y = Math.random() * stage.stageHeight;
			}
		}

		private function changePositions(m:MouseEvent):void
		{
			for ( var d:uint = 0; d < cArr.length; d++ )
			{
				cArr[d].x = Math.random() * stage.stageWidth;
				cArr[d].y = Math.random() * stage.stageHeight;
			}
		}
	}
}
</pre>
<p>Here is the object class called 'c' and saved as 'c.as':</p>
<pre name="code" class="c-sharp">
package {
	/* this class will simply draw a circle */

	import flash.display.Sprite;

	public class c extends Sprite {
		public var radius:Number;
		private var color:uint;

		public function c(radius:Number=20, color:uint=0xb3d830)
		{
			this.radius = radius;
			this.color = color;
			init();
		}

		public function init():void {
			graphics.beginFill(color);
			graphics.drawCircle(0, 0, radius);
			graphics.endFill();
		}
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://manewc.com/2008/06/13/creating-multiple-objects-with-actionscript/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Round Rectangle with Actionscript</title>
		<link>http://manewc.com/2008/05/07/round-rectangle-with-actionscript/</link>
		<comments>http://manewc.com/2008/05/07/round-rectangle-with-actionscript/#comments</comments>
		<pubDate>Wed, 07 May 2008 17:50:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Drawing API]]></category>

		<guid isPermaLink="false">http://manewc.com/2008/05/07/round-rectangle-with-actionscript/</guid>
		<description><![CDATA[A class to generate a rounded cornered rectangle which I am using in one of my current projects:

package {
    import flash.display.DisplayObject;
    import flash.display.Graphics;
    import flash.display.Shape;
    import flash.display.Sprite;

    public class RoundRectangle extends Sprite {
        [...]]]></description>
			<content:encoded><![CDATA[<p>A class to generate a rounded cornered rectangle which I am using in one of my current projects:</p>
<pre name="code" class="c-sharp">
package {
    import flash.display.DisplayObject;
    import flash.display.Graphics;
    import flash.display.Shape;
    import flash.display.Sprite;

    public class RoundRectangle extends Sprite {
        private var rrX:Number;
		private var rrY:Number;
		private var rrRadius:Number;
		private var rrWidth:Number;
		private var rrHeight:Number;
        private var bgColor:uint;
        private var borderColor:uint;
        private var borderSize:Number;
		private var child:Shape = new Shape();

        public function RoundRectangle(rrX:Number=0,rrY:Number=0,rrWidth:Number=10,rrHeight:Number=10,rrRadius:Number=0,bgColor:uint=0x000000)
		{
            child = new Shape();
            child.graphics.beginFill(bgColor);
           	child.graphics.lineStyle(borderSize, borderColor);
            child.graphics.drawRoundRect(rrX, rrY, rrWidth, rrHeight, rrRadius);

            child.graphics.endFill();
            addChild(child);
        }
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://manewc.com/2008/05/07/round-rectangle-with-actionscript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[AS 3] Drawing Dynamic Line Curves with curveTo Method</title>
		<link>http://manewc.com/2008/03/03/as-3-drawing-dynamic-line-curves-with-curveto-method/</link>
		<comments>http://manewc.com/2008/03/03/as-3-drawing-dynamic-line-curves-with-curveto-method/#comments</comments>
		<pubDate>Mon, 03 Mar 2008 19:13:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Drawing API]]></category>

		<guid isPermaLink="false">http://manewc.com/2008/03/03/as-3-drawing-dynamic-line-curves-with-curveto-method/</guid>
		<description><![CDATA[Demonstration of the curveTo method. Simply roll your mouse over the movie below.

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

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

	public class CurveToExample extends Sprite
	{
		public function CurveToExample()
		{
			stage.addEventListener(MouseEvent.MOUSE_MOVE, drawCurve);
		}

		private function drawCurve(m:MouseEvent):void
		{
			// clear the board on each Mouse Move
			graphics.clear();

			// draw the line
			graphics.lineStyle(1);
			graphics.moveTo(0,stage.stageHeight / 2);
			graphics.curveTo(mouseX,mouseY,stage.stageWidth,stage.stageHeight / 2);
		}
	}
}
]]></description>
			<content:encoded><![CDATA[<p>Demonstration of the curveTo method. Simply roll your mouse over the movie below.</p>

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

	public class CurveToExample extends Sprite
	{
		public function CurveToExample()
		{
			stage.addEventListener(MouseEvent.MOUSE_MOVE, drawCurve);
		}

		private function drawCurve(m:MouseEvent):void
		{
			// clear the board on each Mouse Move
			graphics.clear();

			// draw the line
			graphics.lineStyle(1);
			graphics.moveTo(0,stage.stageHeight / 2);
			graphics.curveTo(mouseX,mouseY,stage.stageWidth,stage.stageHeight / 2);
		}
	}
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://manewc.com/2008/03/03/as-3-drawing-dynamic-line-curves-with-curveto-method/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>[AS 3] Recreating the Drawing Tool with Actionscript 3</title>
		<link>http://manewc.com/2008/02/13/as-3-recreating-the-drawing-tool-with-actionscript-3/</link>
		<comments>http://manewc.com/2008/02/13/as-3-recreating-the-drawing-tool-with-actionscript-3/#comments</comments>
		<pubDate>Wed, 13 Feb 2008 18:03:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Drawing API]]></category>

		<guid isPermaLink="false">http://manewc.com/2008/02/13/as-3-recreating-the-drawing-tool-with-actionscript-3/</guid>
		<description><![CDATA[Simply press and drag your mouse around the flash movie below.

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

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

	public class DrawingTool extends Sprite
	{
		private var drawing:Boolean;

		public function DrawingTool()
		{
			graphics.lineStyle(1,0xffffff);
			graphics.moveTo(mouseX,mouseY);

			stage.addEventListener(MouseEvent.MOUSE_DOWN, MouseDown);
			stage.addEventListener(MouseEvent.MOUSE_UP, MouseUp);

			addEventListener(Event.ENTER_FRAME, Drawing);
		}

		private function MouseDown(m:MouseEvent):void
		{
			graphics.lineStyle(1,Math.random() * 0xffffff);
			drawing = true;
		}

		private function MouseUp(m:MouseEvent):void
		{
			drawing = false;
		}

		private function Drawing(e:Event):void
		{
			if (drawing)
			{
				this.graphics.lineTo(mouseX, mouseY);
			}
			else
			{
				this.graphics.moveTo(mouseX, mouseY);
			}
		}
	}
}
]]></description>
			<content:encoded><![CDATA[<p>Simply press and drag your mouse around the flash movie below.</p>

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

	public class DrawingTool extends Sprite
	{
		private var drawing:Boolean;

		public function DrawingTool()
		{
			graphics.lineStyle(1,0xffffff);
			graphics.moveTo(mouseX,mouseY);

			stage.addEventListener(MouseEvent.MOUSE_DOWN, MouseDown);
			stage.addEventListener(MouseEvent.MOUSE_UP, MouseUp);

			addEventListener(Event.ENTER_FRAME, Drawing);
		}

		private function MouseDown(m:MouseEvent):void
		{
			graphics.lineStyle(1,Math.random() * 0xffffff);
			drawing = true;
		}

		private function MouseUp(m:MouseEvent):void
		{
			drawing = false;
		}

		private function Drawing(e:Event):void
		{
			if (drawing)
			{
				this.graphics.lineTo(mouseX, mouseY);
			}
			else
			{
				this.graphics.moveTo(mouseX, mouseY);
			}
		}
	}
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://manewc.com/2008/02/13/as-3-recreating-the-drawing-tool-with-actionscript-3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>[AS 3] Creating a Radial Gradient with the Matrix Class</title>
		<link>http://manewc.com/2008/02/12/as-3-creating-a-radial-gradient-with-the-matrix-class/</link>
		<comments>http://manewc.com/2008/02/12/as-3-creating-a-radial-gradient-with-the-matrix-class/#comments</comments>
		<pubDate>Tue, 12 Feb 2008 18:02:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Drawing API]]></category>

		<guid isPermaLink="false">http://manewc.com/2008/02/12/as-3-creating-a-radial-gradient-with-the-matrix-class/</guid>
		<description><![CDATA[Here is an example of the ability to create a gradient fill within a bounding area utilizing the Matrix class. I used the Matrix class because this is the class that will allow one to capture properties of the gradient. The Matrix class is a grid that includes the combination of scale (&#8217;a&#8217; and &#8216;d&#8217;), [...]]]></description>
			<content:encoded><![CDATA[<p>Here is an example of the ability to create a gradient fill within a bounding area utilizing the Matrix class. I used the Matrix class because this is the class that will allow one to capture properties of the gradient. The Matrix class is a grid that includes the combination of scale (&#8217;a&#8217; and &#8216;d&#8217;), skewing aka shearing (&#8217;b&#8217; and &#8216;c&#8217;) and location (&#8217;tx&#8217; and &#8216;ty&#8217;) &#8211; the combination of a, b, c, and d affect the rotation. The variables &#8216;u&#8217;, &#8216;v&#8217;, and &#8216;w&#8217; are not utilized by the Flash player. Here is the Matrix grid:</p>
<pre>
[ a, b, tx
  c, d, ty
  u, v, w ]</pre>
<p>Here is the demo of the code below.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_RadialGradient_921084500"
			class="flashmovie"
			width="550"
			height="400">
	<param name="movie" value="/projects/flash/RadialGradient/RadialGradient.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/projects/flash/RadialGradient/RadialGradient.swf"
			name="fm_RadialGradient_921084500"
			width="550"
			height="400">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>Here is the document class:</p>
<pre name="code" class="c-sharp">
package
{
	import flash.display.Sprite;
	import flash.display.GradientType;
	import flash.geom.Matrix;

	public class RadialGradient extends Sprite
	{
		private var gType:String;
		private var matrix:Matrix;

		private var bound:Sprite;

		public function RadialGradient()
		{
			var gType:String = GradientType.RADIAL;

			var matrix:Matrix = new Matrix();
			matrix.createGradientBox(550,400,0,0,0);

			var gColors:Array = [0x336699, 0xff9900];
			var gAlphas:Array = [1,1];
			var gRatio:Array = [0,255];

			var bound:Sprite = new Sprite();
			bound.graphics.beginGradientFill(gType,gColors,gAlphas,gRatio,matrix);
			bound.graphics.drawRect(0,0,550,400);
			bound.x = bound.y = 0;

			addChild(bound);
		}
	}
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://manewc.com/2008/02/12/as-3-creating-a-radial-gradient-with-the-matrix-class/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>[AS 3] Drawing Lines across the Stage</title>
		<link>http://manewc.com/2008/01/29/as-3-drawing-lines-across-the-stage/</link>
		<comments>http://manewc.com/2008/01/29/as-3-drawing-lines-across-the-stage/#comments</comments>
		<pubDate>Tue, 29 Jan 2008 19:11:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Drawing API]]></category>

		<guid isPermaLink="false">http://manewc.com/2008/01/29/as-3-drawing-lines-across-the-stage/</guid>
		<description><![CDATA[Today I just wanted to display a defined numer of lines with various angles to span across the stage.. nothing too exciting here, but this will be the groundwork for some future projects that I have going on:

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_Landscape_205051554"
			class="flashmovie"
			width="550"
			height="400">
	<param name="movie" value="/projects/flash/Lines/Landscape.swf" />
	<param name="bgcolor" value="#2e2e2e" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/projects/flash/Lines/Landscape.swf"
			name="fm_Landscape_205051554"
			width="550"
			height="400">
		<param name="bgcolor" value="#2e2e2e" />
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
Here is the basic Line.as file:

package {
	import flash.display.Sprite;
	import flash.display.Graphics;
	import flash.geom.Rectangle;

	public class Line [...]]]></description>
			<content:encoded><![CDATA[<p>Today I just wanted to display a defined numer of lines with various angles to span across the stage.. nothing too exciting here, but this will be the groundwork for some future projects that I have going on:</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_Landscape_1696971222"
			class="flashmovie"
			width="550"
			height="400">
	<param name="movie" value="/projects/flash/Lines/Landscape.swf" />
	<param name="bgcolor" value="#2e2e2e" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/projects/flash/Lines/Landscape.swf"
			name="fm_Landscape_1696971222"
			width="550"
			height="400">
		<param name="bgcolor" value="#2e2e2e" />
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>Here is the basic Line.as file:</p>
<pre name="code" class="c-sharp">
package {
	import flash.display.Sprite;
	import flash.display.Graphics;
	import flash.geom.Rectangle;

	public class Line extends Sprite {
		public var moveToX:Number;
		public var moveToY:Number;
		public var lineToX:Number;
		public var lineToY:Number;

		public function Line(moveToX:Number=0,moveToY:Number=0,lineToX:Number=50,lineToY:Number=0) {
			graphics.lineStyle(1);
			graphics.moveTo(moveToX,moveToY);
			graphics.lineTo(lineToX,lineToY);
		}
	}
}</pre>
<p>Here is the document class file Landscape.as</p>
<pre name="code" class="c-sharp">
package
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;

	public class Landscape extends Sprite
	{
		private var ball:Ball;

		private var line:Line;
		private var lines:Array;
		private var numLines:Number = 8;
		private var moveLineX:Number;
		private var moveLineY:Number;
		private var xIteration:Number = stage.stageWidth / numLines;
		private var beginLineX:Number;
		private var beginLineY:Number;

		public function Landscape()
		{
			init();
		}

		private function init():void
		{
			moveLineX = 0;
			moveLineY = Math.random() * stage.stageHeight;

			beginLineX = xIteration;
			beginLineY = Math.random() * stage.stageHeight;

			for (var i:uint = 0; i &lt; numLines; i++)
			{

				line = new Line(moveLineX,moveLineY,beginLineX,beginLineY);
				addChild(line);

				moveLineX = beginLineX;
				moveLineY = beginLineY;

				beginLineX = (i + 2) * xIteration;
				beginLineY = Math.random() * stage.stageHeight;
			}
		}
	}
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://manewc.com/2008/01/29/as-3-drawing-lines-across-the-stage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[AS 3] Drawing Lines to Mouse Point</title>
		<link>http://manewc.com/2008/01/18/as-3-drawing-lines-to-mouse-point/</link>
		<comments>http://manewc.com/2008/01/18/as-3-drawing-lines-to-mouse-point/#comments</comments>
		<pubDate>Fri, 18 Jan 2008 18:35:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Drawing API]]></category>

		<guid isPermaLink="false">http://manewc.com/2008/01/18/as-3-drawing-lines-to-mouse-point/</guid>
		<description><![CDATA[I just decided to build this simple interactive movie that will simply draw lines from the center of the stage to your mouse position and then closes out the drawing to form a triangle. This is just using the simple methods of:

graphics.clear
graphics.moveTo
graphics.lineStyle
graphics.beginFill and graphics.endFill
graphics.lineTo

Full documentation here.
If you hover your mouse over the movie below it [...]]]></description>
			<content:encoded><![CDATA[<p>I just decided to build this simple interactive movie that will simply draw lines from the center of the stage to your mouse position and then closes out the drawing to form a triangle. This is just using the simple methods of:</p>
<ul>
<li>graphics.clear</li>
<li>graphics.moveTo</li>
<li>graphics.lineStyle</li>
<li>graphics.beginFill and graphics.endFill</li>
<li>graphics.lineTo</li>
</ul>
<p><em><a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Graphics.html">Full documentation here.</a></em></p>
<p>If you hover your mouse over the movie below it will demonstrate the code below:</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_DrawToMouse_821882534"
			class="flashmovie"
			width="550"
			height="400">
	<param name="movie" value="/projects/flash/DrawToMouse/DrawToMouse.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/projects/flash/DrawToMouse/DrawToMouse.swf"
			name="fm_DrawToMouse_821882534"
			width="550"
			height="400">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>Here is the Document Class used, with the file named DrawToMouse.as:</p>
<pre name="code" class="c-sharp">
package
{
	import flash.events.Event;
	import flash.display.Sprite;

	public class DrawToMouse extends Sprite
	{

		public function DrawToMouse()
		{
			addEventListener(Event.ENTER_FRAME, drawTriangle);
		}

		private function drawTriangle(e:Event):void
		{
			graphics.clear(); // this will clear out any lines drawn previously
			graphics.lineStyle(10, 0, .5); // params: thickness, color, alpha
			graphics.moveTo(stage.stageWidth / 2, stage.stageHeight / 2); // moves the initial draw point
			graphics.beginFill(0x000000); // begin fill with a black color
			graphics.lineTo(mouseX, mouseY); // moves from init point to mouse x and mouse y point
			graphics.lineTo(mouseX, stage.stageHeight / 2); // now draws line to y position of center of stage
			graphics.endFill(); // closes out to make our triangle
		}
	}
}</pre>
<p style="font-size: smaller; font-style: italic">NOTE: here is a nice plugin for embedding flash movies in your posts for Wordpress/Textpattern publishers:<br />
<a href="http://kimili.com/plugins/kml_flashembed">http://kimili.com/plugins/kml_flashembed</a></p>
]]></content:encoded>
			<wfw:commentRss>http://manewc.com/2008/01/18/as-3-drawing-lines-to-mouse-point/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[AS 3] Drawing a Rectangle</title>
		<link>http://manewc.com/2008/01/16/as-3-drawing-a-rectangle/</link>
		<comments>http://manewc.com/2008/01/16/as-3-drawing-a-rectangle/#comments</comments>
		<pubDate>Wed, 16 Jan 2008 22:56:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Drawing API]]></category>

		<guid isPermaLink="false">http://manewc.com/2008/01/16/as-3-drawing-a-rectangle/</guid>
		<description><![CDATA[A simple class using the drawRect method to draw a rectangle. By default this will render a blue 10&#215;10 (yeah, I know it is a square) and place it at position 0,0 of the stage.

package
{
	import flash.display.Sprite;

	public class DrawRectangle extends Sprite
	{
		private var xPos:Number;
		private var yPos:Number;
		private var rWidth:Number;
		private var rHeight:Number;
		private var color:uint;

		public function DrawRectangle(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();
		}
	}
}
]]></description>
			<content:encoded><![CDATA[<p>A simple class using the drawRect method to draw a rectangle. By default this will render a blue 10&#215;10 (yeah, I know it is a square) and place it at position 0,0 of the stage.</p>
<pre name="code" class="c-sharp">
package
{
	import flash.display.Sprite;

	public class DrawRectangle extends Sprite
	{
		private var xPos:Number;
		private var yPos:Number;
		private var rWidth:Number;
		private var rHeight:Number;
		private var color:uint;

		public function DrawRectangle(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();
		}
	}
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://manewc.com/2008/01/16/as-3-drawing-a-rectangle/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>[AS 3] Drawing a Circle with Actionscript</title>
		<link>http://manewc.com/2008/01/09/as-3-drawing-a-circle-with-actionscript/</link>
		<comments>http://manewc.com/2008/01/09/as-3-drawing-a-circle-with-actionscript/#comments</comments>
		<pubDate>Wed, 09 Jan 2008 14:48:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Drawing API]]></category>

		<guid isPermaLink="false">http://manewc.com/2008/01/09/as-3-drawing-a-circle-with-actionscript/</guid>
		<description><![CDATA[The following code with draw a circle, apply a color fill, and position it in the center of your stage:

package {
	import flash.display.Sprite;

	public class DrawCircle extends Sprite {
		private var radius:Number;
		private var color:uint;

		public function DrawCircle(radius:Number=20, color:uint=0x336699) {
			// center the circle - you can put the x and y positions as
			// parameters of this function.. i just opted [...]]]></description>
			<content:encoded><![CDATA[<p>The following code with draw a circle, apply a color fill, and position it in the center of your stage:</p>
<pre name="code" class="c-sharp">
package {
	import flash.display.Sprite;

	public class DrawCircle extends Sprite {
		private var radius:Number;
		private var color:uint;

		public function DrawCircle(radius:Number=20, color:uint=0x336699) {
			// center the circle - you can put the x and y positions as
			// parameters of this function.. i just opted not to
			this.x = stage.stageWidth/2;
			this.y = stage.stageHeight/2;

			// draw the circle
			graphics.beginFill(color);
			graphics.drawCircle(0, 0, radius);
			graphics.endFill();
		}

	}
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://manewc.com/2008/01/09/as-3-drawing-a-circle-with-actionscript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
