<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Activetuts+</title>
	
	<link>http://active.tutsplus.com</link>
	<description>Flash, Flex &amp; ActionScript Tutorials</description>
	<lastBuildDate>Fri, 20 Nov 2009 12:00:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<image><link>http://active.tutsplus.com</link><url>http://envato.s3.amazonaws.com/rss_images/activetuts.jpg</url><title>Activetuts+</title></image><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/Flashtuts" type="application/rss+xml" /><feedburner:emailServiceId>Flashtuts</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
		<title>Conquer the Universe With ActionScript 3.0 and the Flixel Game Engine: Part 1</title>
		<link>http://feedproxy.google.com/~r/Flashtuts/~3/eZEI_raIlOQ/</link>
		<comments>http://active.tutsplus.com/tutorials/screencasts/conquer-the-universe-with-actionscript-3-0-and-the-flixel-game-engine-part-1/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 12:00:11 +0000</pubDate>
		<dc:creator>Shane Johnson</dc:creator>
				<category><![CDATA[Games]]></category>
		<category><![CDATA[Screencasts]]></category>

		<guid isPermaLink="false">http://active.tutsplus.com/?p=2530</guid>
		<description><![CDATA[<img src="http://activetuts.s3.amazonaws.com/tuts/020_flixel/preview.jpg" alt="">]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://flixel.org" target="_blank">Flixel game engine</a> is an opensource ActionScript 3.0 framework written by <a href="http://www.adamatomic.com/" target="_blank">Adam Atomic</a>. Its aim is to take the donkey work out of building AS3 games, leaving you with all the fun stuff and saving heaps of time!</p>
<p>In this, the first in a series of two screencasts, Shane Johnson takes you through the basics of Flixel, explaining how to build an awesome shoot &#8216;em up game from scratch.</p>
<p><span id="more-2530"></span></p>
<div class="tutorial_image">
<a href="http://activetuts.s3.amazonaws.com/tuts/020_flixel/src_01.zip" target="_blank"><br />
<img src="http://activetuts.s3.amazonaws.com/assets/icons/source.jpg" alt="" style="border:none"></a></p>
<p><a href="http://activetuts.s3.amazonaws.com/tuts/020_flixel/preview.html" target="_blank"><br />
<img src="http://activetuts.s3.amazonaws.com/assets/icons/demo.jpg" alt="" style="border:none"></a>
</div>
<h3>View Screencast: Section One</h3>
<h4>Introduction</h4>
<div class="tutorial_image">
<a href="http://activetuts.s3.amazonaws.com/tuts/020_flixel/Intro.flv" target="_blank"><br />
<img src="http://activetuts.s3.amazonaws.com/assets/icons/screen.jpg" alt="" style="border:none"></a>
</div>
<p>

<div class="tutorial_image">
		<div id="player10"><a href="http://get.adobe.com/flashplayer/">Get the Flash Player</a> to see this player.</div>
		<script type="text/javascript">
		var so = new SWFObject('http://active.tutsplus.com/wp-content/plugins/flash-player/player.swf','player10','600','450','9');
		so.addParam('allowscriptaccess','always');
		so.addParam('allowfullscreen','true');
		so.addParam('flashvars','&file=http://activetuts.s3.amazonaws.com/tuts/020_flixel/Intro.flv&bufferlength=1&skin=http://active.tutsplus.com/wp-content/plugins/flash-player/silver.swf&fullscreen=true');
		so.write('player10');
		</script>
		</div>

</p>
<h3>View Screencast: Section Two</h3>
<h4>Begin Coding</h4>
<div class="tutorial_image">
<a href="http://activetuts.s3.amazonaws.com/tuts/020_flixel/PartOne.flv" target="_blank"><br />
<img src="http://activetuts.s3.amazonaws.com/assets/icons/screen.jpg" alt="" style="border:none"></a>
</div>
<p>

<div class="tutorial_image">
		<div id="player11"><a href="http://get.adobe.com/flashplayer/">Get the Flash Player</a> to see this player.</div>
		<script type="text/javascript">
		var so = new SWFObject('http://active.tutsplus.com/wp-content/plugins/flash-player/player.swf','player11','600','450','9');
		so.addParam('allowscriptaccess','always');
		so.addParam('allowfullscreen','true');
		so.addParam('flashvars','&file=http://activetuts.s3.amazonaws.com/tuts/020_flixel/PartOne.flv&bufferlength=1&skin=http://active.tutsplus.com/wp-content/plugins/flash-player/silver.swf&fullscreen=true');
		so.write('player11');
		</script>
		</div>

</p>
<h3>View Screencast: Section Three</h3>
<h4>Moving on; Sprites and Sounds</h4>
<div class="tutorial_image">
<a href="http://activetuts.s3.amazonaws.com/tuts/020_flixel/PartTwo.flv" target="_blank"><br />
<img src="http://activetuts.s3.amazonaws.com/assets/icons/screen.jpg" alt="" style="border:none"></a>
</div>
<p>

<div class="tutorial_image">
		<div id="player12"><a href="http://get.adobe.com/flashplayer/">Get the Flash Player</a> to see this player.</div>
		<script type="text/javascript">
		var so = new SWFObject('http://active.tutsplus.com/wp-content/plugins/flash-player/player.swf','player12','600','450','9');
		so.addParam('allowscriptaccess','always');
		so.addParam('allowfullscreen','true');
		so.addParam('flashvars','&file=http://activetuts.s3.amazonaws.com/tuts/020_flixel/PartTwo.flv&bufferlength=1&skin=http://active.tutsplus.com/wp-content/plugins/flash-player/silver.swf&fullscreen=true');
		so.write('player12');
		</script>
		</div>

</p>
<h3>View Screencast: Section Four</h3>
<h4>Shooting, Killing and Compiling</h4>
<div class="tutorial_image">
<a href="http://activetuts.s3.amazonaws.com/tuts/020_flixel/PartThree.flv" target="_blank"><br />
<img src="http://activetuts.s3.amazonaws.com/assets/icons/screen.jpg" alt="" style="border:none"></a>
</div>
<p>

<div class="tutorial_image">
		<div id="player13"><a href="http://get.adobe.com/flashplayer/">Get the Flash Player</a> to see this player.</div>
		<script type="text/javascript">
		var so = new SWFObject('http://active.tutsplus.com/wp-content/plugins/flash-player/player.swf','player13','600','450','9');
		so.addParam('allowscriptaccess','always');
		so.addParam('allowfullscreen','true');
		so.addParam('flashvars','&file=http://activetuts.s3.amazonaws.com/tuts/020_flixel/PartThree.flv&bufferlength=1&skin=http://active.tutsplus.com/wp-content/plugins/flash-player/silver.swf&fullscreen=true');
		so.write('player13');
		</script>
		</div>

</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Flashtuts?a=eZEI_raIlOQ:1f0-2MDMI7w:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=eZEI_raIlOQ:1f0-2MDMI7w:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=eZEI_raIlOQ:1f0-2MDMI7w:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=eZEI_raIlOQ:1f0-2MDMI7w:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=eZEI_raIlOQ:1f0-2MDMI7w:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=eZEI_raIlOQ:1f0-2MDMI7w:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=eZEI_raIlOQ:1f0-2MDMI7w:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=eZEI_raIlOQ:1f0-2MDMI7w:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=eZEI_raIlOQ:1f0-2MDMI7w:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=eZEI_raIlOQ:1f0-2MDMI7w:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Flashtuts/~4/eZEI_raIlOQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://active.tutsplus.com/tutorials/screencasts/conquer-the-universe-with-actionscript-3-0-and-the-flixel-game-engine-part-1/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://active.tutsplus.com/tutorials/screencasts/conquer-the-universe-with-actionscript-3-0-and-the-flixel-game-engine-part-1/</feedburner:origLink></item>
		<item>
		<title>Journey to the Next Dimension With PV3D and Funny Glasses: Part 1</title>
		<link>http://feedproxy.google.com/~r/Flashtuts/~3/eW6s9253mY8/</link>
		<comments>http://active.tutsplus.com/tutorials/3d/journey-to-the-next-dimension-with-pv3d-and-funny-glasses-part-1/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 12:01:04 +0000</pubDate>
		<dc:creator>Michael Williams</dc:creator>
				<category><![CDATA[3D]]></category>

		<guid isPermaLink="false">http://active.tutsplus.com/?p=2533</guid>
		<description><![CDATA[<img src="http://activetuts.s3.amazonaws.com/tuts/019_PV3DSpecs/Preview/preview.jpg" alt="">]]></description>
			<content:encoded><![CDATA[<p>To tie in with our <a href="http://bit.ly/2q8xuk">Papervision3D Essentials giveaway</a>, today&#8217;s tutorial also features a PV3D theme.</p>
<p>This two-part tutorial will show you how to get started with the Papervision3D engine, then how to make your creation jump out of the screen using an <a href="http://bit.ly/3wyC8J" target="_blank">anaglyph</a> effect in combination with 3D spectacles.</p>
<p><span id="more-2533"></span></p>
<div class="tutorial_image">
<a href="http://activetuts.s3.amazonaws.com/tuts/019_PV3DSpecs/Source.zip" target="_blank"><br />
<img src="http://activetuts.s3.amazonaws.com/assets/icons/source.jpg" alt="" style="border:none"></a><br />
<a href="http://activetuts.s3.amazonaws.com/tuts/019_PV3DSpecs/Preview/preview.html" target="_blank"><br />
<img src="http://activetuts.s3.amazonaws.com/assets/icons/demo.jpg" alt="" style="border:none"></a>
</div>
<h2>Introduction</h2>
<p>Got a pair of 3D glasses lying around? Here in the UK, Channel 4 is running a special <a href="http://www.channel4.com/programmes/themes/3d-week" target="_blank">3D Week</a> &#8211; seven days of TV programmes broadcast in 3D &#8211; so plenty of people here do. Let&#8217;s put them to use.</p>
<p>This two-part tutorial will show you how to get started with the <a href="http://www.papervision3d.org/">Papervision3D</a> engine, and then how to make your creation jump out of the screen.</p>
<p>In this first part, you&#8217;ll learn the basics of PV3D, ending up with something like this:</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/019_PV3DSpecs/Tutorial/14.jpg" alt="Cube of cubes" /></div>
<p>&#8230;and in the second part, you&#8217;ll learn about the <a href="http://bit.ly/3wyC8J" target="_blank">anaglyph</a> effect for 3D glasses, and apply it to what you&#8217;ve made like so:</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/019_PV3DSpecs/Tutorial/15.jpg" alt="In three of the glorious dees" /></div>
<h2>Step 1: The Setup</h2>
<p>If you&#8217;re using Flash, create a new ActionScript 3.0 Flash file. Set the size of the stage to be whatever you like &#8211; I&#8217;ll stick with the default 550 by 400 pixels.</p>
<p>While you&#8217;re at it, create a new ActionScript file, and save it as <em>Main.as</em> in the same folder as your FLA. We&#8217;re going to use this AS file as the FLA&#8217;s <em>document class</em>, so click a blank space in your FLA file, and enter <em>Main</em> in the &#8220;Document class&#8221; box of the Properties panel.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/019_PV3DSpecs/Tutorial/2.jpg" alt="Document class" /></div>
<p>(If you&#8217;re not using the Flash IDE, just create a new AS3 project.)</p>
<h2>Step 2: Download Papervision3D</h2>
<p>Head over to the <a href="http://code.google.com/p/papervision3d/downloads/list">Papervision Download Page</a>. There are lots of different versions and a few different types of files (zip, swc, mxp). Just grab the latest .zip file (it should say <em>Featured</em> next to it). The one I&#8217;m using is called <em>Papervision3D 2.1.920.zip (for use with &#8220;Papervision3D Essentials&#8221; book)</em>.</p>
<h2>Step 3: Extract the Zip</h2>
<p>Extract the zip file you just downloaded to anywhere on your hard drive. I like to keep all the different engines I use in the same folder, but it&#8217;s up to you.</p>
<h2>Step 4: Set a Classpath</h2>
<p>Flash needs to know where you extracted Papervision before it can use it. We use a <em>classpath</em> for this: click <em>Edit > Preferences</em>, select <em>ActionScript</em>, then click <em>ActionScript 3.0 Settings&#8230;</em>.</p>
<p>In the box that appears, click the little &#8220;crosshair&#8221; icon, then find the folder where you unzipped Papervision and click OK. Click OK to the other boxes until you get back to the FLA.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/019_PV3DSpecs/Tutorial/1.jpg" alt="Classpath" /></div>
<p>If you&#8217;re not using the Flash IDE, you&#8217;ll have to set this in a different way. For example, in <a href="http://www.flashdevelop.org/">FlashDevelop</a>, you should click <em>Tools > Global Classpaths</em>.</p>
<h2>Step 5: Set the Scene in Papervision</h2>
<p>In Papervision, all your 3D objects must be placed inside a <em>scene</em>. It&#8217;s kind of like the Stage in regular ActionScript. So, before we do anything we need to create a <em>Scene3D</em> object that will contain everything else.</p>
<p>Switch to your Main.as file. Let&#8217;s quickly add the base code needed for any document class:</p>
<pre name="code" class="javascript">
package
{
	import flash.display.MovieClip;

	public class Main extends MovieClip
	{
		public function Main()
		{

		}
	}
}
</pre>
<p>The Scene3D object is in <em>org.papervision3d.scenes.Scene3D</em>, so we need to <em>import</em> that, then create a new <em>public var</em> to hold the scene, and finally create the actual scene object: <em>(lines 4, 8 and 12)</em></p>
<pre name="code" class="javascript">
package
{
	import flash.display.MovieClip;
	import org.papervision3d.scenes.Scene3D;

	public class Main extends MovieClip
	{
		public var scene:Scene3D;

		public function Main()
		{
			scene = new Scene3D();
		}
	}
}
</pre>
<h2>Step 6: Add a Cube</h2>
<p>To start with, let&#8217;s just create a big plain cube sitting in our scene.</p>
<p>We&#8217;ll follow the same sort of steps as above to create it, then add it to our scene: <em>(lines 5, 10, 15, 16)</em></p>
<pre name="code" class="javascript">
package
{
	import flash.display.MovieClip;
	import org.papervision3d.scenes.Scene3D;
	import org.papervision3d.objects.primitives.Cube;

	public class Main extends MovieClip
	{
		public var scene:Scene3D;
		public var cube:Cube;

		public function Main()
		{
			scene = new Scene3D();
			cube = new Cube();
			scene.addChild( cube );
		}
	}
}
</pre>
<p>Note that we use &#8220;addChild()&#8221; to add the cube to the scene, just as we do when adding a MovieClip to the Stage.</p>
<h2>Step 7: Color the Cube</h2>
<p>The above code will give you an error if you try to run it. That&#8217;s because we haven&#8217;t told the cube what its face surfaces should look like.</p>
<p>Papervision uses <em>materials</em> to describe how a surface looks. We can make a very simple, single-colored material using a <em>ColorMaterial</em>:</p>
<pre name="code" class="javascript">
var grayMaterial:ColorMaterial = new ColorMaterial( 0xCCCCCC );
</pre>
<p>The &#8220;0xCCCCCC&#8221; represents the color gray; just take the color code of any color and replace the <em>#</em> with <em>0x</em>:</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/019_PV3DSpecs/Tutorial/3.jpg" alt="color code for gray" /></div>
<p>Because a cube has six faces, we need to give it six materials. To do this we put all six in a list:</p>
<pre name="code" class="javascript">
var materialsList:MaterialsList = new MaterialsList();
materialsList.addMaterial( grayMaterial, "front" );
materialsList.addMaterial( grayMaterial, "back" );
materialsList.addMaterial( grayMaterial, "left" );
materialsList.addMaterial( grayMaterial, "right" );
materialsList.addMaterial( grayMaterial, "top" );
materialsList.addMaterial( grayMaterial, "bottom" );
</pre>
<p>&#8230;and then pass that list to the cube when we create it:</p>
<pre name="code" class="javascript">
cube = new Cube( materialsList );
</pre>
<p>So, your whole code should end up looking like this: (don&#8217;t forget the <em>import</em> statements!)</p>
<pre name="code" class="javascript">
package
{
	import flash.display.MovieClip;
	import org.papervision3d.scenes.Scene3D;
	import org.papervision3d.objects.primitives.Cube;
	import org.papervision3d.materials.ColorMaterial;
	import org.papervision3d.materials.utils.MaterialsList;

	public class Main extends MovieClip
	{
		public var scene:Scene3D;
		public var cube:Cube;

		public function Main()
		{
			var grayMaterial:ColorMaterial = new ColorMaterial( 0xCCCCCC );
			var materialsList:MaterialsList = new MaterialsList();
			materialsList.addMaterial( grayMaterial, "front" );
			materialsList.addMaterial( grayMaterial, "back" );
			materialsList.addMaterial( grayMaterial, "left" );
			materialsList.addMaterial( grayMaterial, "right" );
			materialsList.addMaterial( grayMaterial, "top" );
			materialsList.addMaterial( grayMaterial, "bottom" );

			scene = new Scene3D();
			cube = new Cube( materialsList );
			scene.addChild( cube );
		}
	}
}
</pre>
<h2>Step 8: Add a Camera</h2>
<p>So we&#8217;ve got no errors, but in order to see anything, we need to add a <em>camera</em> to the scene. We&#8217;ll see everything through the camera&#8217;s &#8220;lens&#8221;.</p>
<p>Adding a camera is just as simple as adding a cube &#8211; simpler, in fact, as we don&#8217;t have to addChild() it to the scene:</p>
<pre name="code" class="javascript">
import org.papervision3d.cameras.Camera3D;
</pre>
<pre name="code" class="javascript">
public var camera:Camera3D;
</pre>
<pre name="code" class="javascript">
scene = new Scene3D();
cube = new Cube( materialsList );
scene.addChild( cube );
camera = new Camera3D();	//this is the new line in Main()
</pre>
<p>Now a camera&#8217;s on the scene, but it&#8217;s not hooked up to any output, so we still can&#8217;t see the cube!</p>
<h2>Step 9: Add a Viewport and a Renderer</h2>
<p>By default, the cube is placed right smack in the middle of the scene (at x=0, y=0, z=0), and the camera is positioned 500 units back from it (at x=0, y=0, z=-1000).</p>
<p>How can we get the image that the camera sees into the Flash Player window?</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/019_PV3DSpecs/Tutorial/5.jpg" alt="How to link camera to stage?" /></div>
<p>The answer is, we use a <em>viewport</em>. This is a type of DisplayObject, like a MovieClip, so we can addChild() it to the stage. But we can also make Papervision <em>render</em> (i.e. draw) the camera&#8217;s view to this viewport &#8211; it&#8217;s a bit like having an artist draw what he can see through a camera lens, then taking his drawing and sticking it to a TV set. Except faster.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/019_PV3DSpecs/Tutorial/6.jpg" alt="" /></div>
<p>So we need to create a viewport and a renderer:</p>
<pre name="code" class="javascript">
import org.papervision3d.view.Viewport3D;
import org.papervision3d.render.BasicRenderEngine;
</pre>
<pre name="code" class="javascript">
public var viewport:Viewport3D;
public var renderer:BasicRenderEngine;
</pre>
<pre name="code" class="javascript">
//put this at the end of Main()
viewport = new Viewport3D();
viewport.autoScaleToStage = true;	//this will make the viewport as big as the stage
addChild( viewport );
renderer = new BasicRenderEngine();
</pre>
<h2>Step 10: Render the Scene</h2>
<p>Now all we need to do is make the renderer do the actual rendering. For this, it needs to know the scene, the camera, and the viewport:</p>
<pre name="code" class="javascript">
renderer.renderScene( scene, camera, viewport );
</pre>
<p>At last! We can finally test out the SWF. Drum roll, please&#8230;</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/019_PV3DSpecs/Tutorial/7.jpg" alt="The Incredible gray Square, ladies and gentlemen" /></div>
<div class="tutorial_image">
<object width="550" height="400" data="http://activetuts.s3.amazonaws.com/tuts/019_PV3DSpecs/Preview/PapervisionTutorial1.swf" type="application/x-shockwave-flash"><param name="src" value="http://activetuts.s3.amazonaws.com/tuts/019_PV3DSpecs/Preview/PapervisionTutorial1.swf" /></object>
</div>
<p>Incredible! Astounding! OK fine, it&#8217;s actually quite lame. How can we even tell it&#8217;s a cube? It looks like a square.</p>
<h2>Step 11: Rotate the Cube</h2>
<p>If we rotate the cube, we&#8217;ll be able to tell whether it&#8217;s actually a cube or not.</p>
<p>Since the cube is in three dimensions, the word &#8220;rotate&#8221; is a little confusing &#8211; which direction do we mean? We need to specify whether we&#8217;re rotating around the x-axis, y-axis, or z-axis.</p>
<p>The <em>Cube</em> object has three properties we can use to define this, called (unsurprisingly) <em>rotationX</em>, <em>rotationY</em> and <em>rotationZ</em>. Let&#8217;s change a couple of them:</p>
<pre name="code" class="javascript">
scene = new Scene3D();
cube = new Cube( materialsList );
cube.rotationX = 25;	//change rotation
cube.rotationY = 40;	//change rotation
scene.addChild( cube );
camera = new Camera3D();
</pre>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/019_PV3DSpecs/Tutorial/8.jpg" alt="The Incredible gray CUBE, ladies and gentlemen" /></div>
<p>It&#8217;s better, but since all the faces are exactly the same color, they just merge into each other. Let&#8217;s fix that.</p>
<h2>Step 12: Reskin the Cube</h2>
<p>Instead of gray, I&#8217;m going to paint the sides with the <a href="http://active.tutsplus.com/">ActiveTuts+</a> logo.</p>
<p>If you&#8217;re using the Flash IDE, create a new movie clip and draw or paste the image you&#8217;d like to use. I&#8217;ve included the logo in my FLA&#8217;s library inside the zip.</p>
<p>Right-click your movie clip and select Properties. Check &#8220;export for ActionScript&#8221; and give it a Class name.  This will let you access it using code. (If you&#8217;re not using the Flash IDE, the zip also contains a SWC with a MovieClip called ActiveTutsLogo that you can use. Or, you can create a new MovieClip in code and add your image to it. I&#8217;m not going to go into the details of that here, though.)</p>
<p>Instead of a <em>ColorMaterial</em> we&#8217;re going to use a <em>MovieMaterial</em>, and instead of specifying a color, we&#8217;ll specify a movie clip. So replace this:</p>
<pre name="code" class="javascript">
var grayMaterial:ColorMaterial = new ColorMaterial( 0xCCCCCC );
var materialsList:MaterialsList = new MaterialsList();
materialsList.addMaterial( grayMaterial, "front" );
materialsList.addMaterial( grayMaterial, "back" );
materialsList.addMaterial( grayMaterial, "left" );
materialsList.addMaterial( grayMaterial, "right" );
materialsList.addMaterial( grayMaterial, "top" );
materialsList.addMaterial( grayMaterial, "bottom" );
</pre>
<p>&#8230;with this:</p>
<pre name="code" class="javascript">
var logoMaterial:MovieMaterial = new MovieMaterial( new ActiveTutsLogo() );
//replace "ActiveTutsLogo" above with the Class name of your movie clip
var materialsList:MaterialsList = new MaterialsList();
materialsList.addMaterial( logoMaterial, "front" );
materialsList.addMaterial( logoMaterial, "back" );
materialsList.addMaterial( logoMaterial, "left" );
materialsList.addMaterial( logoMaterial, "right" );
materialsList.addMaterial( logoMaterial, "top" );
materialsList.addMaterial( logoMaterial, "bottom" );
</pre>
<p>You&#8217;ll also need to import the MovieMaterial:</p>
<pre name="code" class="javascript">
import org.papervision3d.materials.MovieMaterial;
</pre>
<p>Test it again:</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/019_PV3DSpecs/Tutorial/9.jpg" alt="Dented cube" /></div>
<p>Well, it works, but it looks a little dented.</p>
<h2>Step 13 (Optional): Remove the Dents</h2>
<p>The &#8220;dented&#8221; look is because Papervision is set by default to draw things quickly rather than accurately. I want to make sure this tutorial will run on slower computers, so I&#8217;m going to leave it at that, but here&#8217;s how you can improve it:</p>
<p>When you create the cube, you can pass it parameters to define how many <em>segments</em> each face is split up in to. The more segments you choose, the more accurate the cube looks &#8211; but the slower it gets rendered.</p>
<p>I&#8217;ve found that 10 is a good number of segments to use in each direction. Here&#8217;s how code for that looks:</p>
<pre name="code" class="javascript">
cube = new Cube( materialsList, 500, 500, 500, 10, 10, 10 );
</pre>
<p>The fifth, sixth and seventh parameters define the number of segments used in each direction. To set them, though, we have to specify all the parameters <em>before</em> the fifth as well.</p>
<p>We&#8217;re already specifying the first parameter &#8211; that&#8217;s the material list. The second, third and fourth parameters define the width, depth and height of the cube. These are set to 500 by default, so I&#8217;ve kept them the same here.</p>
<p>If you use the above line of code, your cube will look like this:</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/019_PV3DSpecs/Tutorial/16.jpg" alt="Smart cube" /></div>
<p>Much neater!</p>
<h2>Step 14: Make the Cube Spin</h2>
<p>We can make a regular MovieClip spin around by increasing its <em>rotation</em> property every frame &#8211; and of course, we can do the same with the cube and its rotationX/Y/Z values.</p>
<p>Create an ENTER_FRAME event listener, which will run every frame:</p>
<pre name="code" class="javascript">
import flash.events.Event;
</pre>
<pre name="code" class="javascript">
//at the bottom of Main()
addEventListener( Event.ENTER_FRAME, onEnterFrame );
</pre>
<pre name="code" class="javascript">
//as a new function
//inside the Main class but outside the Main() function
public function onEnterFrame( evt:Event ):void
{
	cube.rotationX = cube.rotationX + 5;
	cube.rotationY = cube.rotationY + 5;
}
</pre>
<p>This will make the cube turn a little bit more each frame. So if you test the SWF out now&#8230; the cube will stay completely still. Huh?</p>
<h2>Step 15: Re-render the Scene Every Frame</h2>
<p>Think back to the painter. We&#8217;re still looking at his old picture &#8211; we need him to draw us a new one every frame, or we won&#8217;t see any changes!</p>
<p>So, modify the onEnterFrame() function:</p>
<pre name="code" class="javascript">
public function onEnterFrame( evt:Event ):void
{
	cube.rotationX = cube.rotationX + 5;
	cube.rotationY = cube.rotationY + 5;
	renderer.renderScene( scene, camera, viewport );
}
</pre>
<p>Check it out now:</p>
<div class="tutorial_image">
<object width="550" height="400" data="http://activetuts.s3.amazonaws.com/tuts/019_PV3DSpecs/Preview/PapervisionTutorial2.swf" type="application/x-shockwave-flash"><param name="src" value="http://activetuts.s3.amazonaws.com/tuts/019_PV3DSpecs/Preview/PapervisionTutorial2.swf" /></object>
</div>
<h2>Step 16: Add More Cubes</h2>
<p>One cube&#8217;s great, but as Roman already showed you <a href="http://active.tutsplus.com/tutorials/3d/creating-and-texturing-a-cube-in-away3d/">how to do that with Away3D</a>, let&#8217;s take things a bit further.</p>
<p>Let&#8217;s add a few more, to form a horizontal line of cubes. We can use a simple <em>for</em> loop to do that; just replace this code:</p>
<pre name="code" class="javascript">
cube = new Cube( materialsList );
cube.rotationX = 25;	//change rotation
cube.rotationY = 40;	//change rotation
scene.addChild( cube );
</pre>
<p>&#8230;with this:</p>
<pre name="code" class="javascript">
for ( var i:int = -1; i <= 1; i++ )
{
	cube = new Cube( materialsList );
	cube.x = i * 350;
	cube.rotationX = 25;	cube.rotationY = 40;	scene.addChild( cube );
}
</pre>
<p>Note that I'm making the x-position of each cube depend on how far we are through the loop. If you run this, you'll get the following:</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/019_PV3DSpecs/Tutorial/10.jpg" alt="Weird" /></div>
<h2>Step 17: Shrink the Cubes</h2>
<p>Whoops, the cubes are too close together. We can shrink them to get around this; just change the <em>scale</em> property of each cube:</p>
<pre name="code" class="javascript">
for ( var i:int = -1; i <= 1; i++ )
{
	cube = new Cube( materialsList );
	cube.x = i * 350;
	cube.scale = 0.40;	//make the cubes 40% of original size
	cube.rotationX = 25;
	cube.rotationY = 40;
	scene.addChild( cube );
}
</pre>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/019_PV3DSpecs/Tutorial/11.jpg" alt="One odd cube" /></div>
<h2>Step 18: Add the Cubes to an Array</h2>
<p>So that fixes the intersection problem, but only one of our cubes is spinning. How come?</p>
<p>It's because the <em>cube</em> variable always refers only to the <em>last</em> cube created - and our onEnterFrame() function only changes the rotations of that one cube.</p>
<p>So to fix this, we'll need an <a href="http://active.tutsplus.com/tutorials/actionscript/as3-101-arrays/" target="_blank">Array</a>. Just as our materials list stored several materials, our Array will store several cubes.</p>
<pre name="code" class="javascript">
public var cubeArray:Array;
</pre>
<pre name="code" class="javascript">
cubeArray = new Array();	//create the new Array
for ( var i:int = -1; i <= 1; i++ )
{
	cube = new Cube( materialsList );
	cube.x = i * 350;
	cube.scale = 0.40;
	cube.rotationX = 25;
	cube.rotationY = 40;
	scene.addChild( cube );
	cubeArray.push( cube );	//add the new cube to the array
}
</pre>
<p>("Push" just means "add to the end of the list".)</p>
<h2>Step 19: Make All the Cubes Spin</h2>
<p>Now that every cube is in the Array, we can loop through the Array each frame and rotate each of them:</p>
<pre name="code" class="javascript">
public function onEnterFrame( evt:Event ):void
{
	for each ( cube in cubeArray )
	{
		cube.rotationX = cube.rotationX + 5;
		cube.rotationY = cube.rotationY + 5;
	}
	renderer.renderScene( scene, camera, viewport );
}
</pre>
<p>The "for each" loop makes the <em>cube</em> variable refer to each cube in turn, one at a time, rather than just to the last cube created as it did before. Here's the result:</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/019_PV3DSpecs/Tutorial/12.jpg" alt="Three cubes in a row" /></div>
<div class="tutorial_image">
<object width="550" height="400" data="http://activetuts.s3.amazonaws.com/tuts/019_PV3DSpecs/Preview/PapervisionTutorial3.swf" type="application/x-shockwave-flash"><param name="src" value="http://activetuts.s3.amazonaws.com/tuts/019_PV3DSpecs/Preview/PapervisionTutorial3.swf" /></object>
</div>
<p>Success!</p>
<h2>Step 20: Make a Square of Cubes</h2>
<p>We've made a line of cubes, so a square isn't going to be difficult. Instead of just making three cubes, we'll make three <em>lines</em> of three cubes.</p>
<p>To do this, we can use a loop-within-a-loop, like so:</p>
<pre name="code" class="javascript">
for ( var i:int = -1; i <= 1; i++ )
{
	for ( var j:int = -1; j <= 1; j++ )	//loop inside a loop
	{
		cube = new Cube( materialsList );
		cube.x = i * 350;
		cube.y = j * 350;	//don't forget to change j!
		cube.scale = 0.40;
		cube.rotationX = 25;
		cube.rotationY = 40;
		scene.addChild( cube );
		cubeArray.push( cube );
	}	//don't forget this closing bracket either
}
</pre>
<p>Test it out:</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/019_PV3DSpecs/Tutorial/13.jpg" alt="Square of cubes" /></div>
<p>Nice. And note that we didn't have to change the code inside onEnterFrame() at all; the loop that runs every frame just rotates every cube inside the Array - and we're still pushing every single cube onto the Array.</p>
<h2>Step 21: Make a Cube of Cubes</h2>
<p>Well, it'd be disappointing to stop at a square, wouldn't it? After all, this is a 3D tutorial.</p>
<p>I expect you can figure out how to do this step on your own. But in case you want to compare:</p>
<pre name="code" class="javascript">
for ( var i:int = -1; i &lt;= 1; i++ )
{
	for ( var j:int = -1; j &lt;= 1; j++ )
	{
		for ( var k:int = 0; k &lt;= 2; k++ )
		{
			cube = new Cube( materialsList );
			cube.x = i * 350;
			cube.y = j * 350;
			cube.z = k * 350;
			cube.scale = 0.40;
			cube.rotationX = 25;
			cube.rotationY = 40;
			scene.addChild( cube );
			cubeArray.push( cube );
		}
	}
}
</pre>
<p>I've been a bit sneaky here. I've started k at 0 instead of at -1, because otherwise the front-most layer of cubes would be too close to the camera. Of course, you can use whichever numbers you like.</p>
<p>Hey, did you notice that the "dented" effect has basically vanished now that we're using smaller cubes?</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/019_PV3DSpecs/Tutorial/14.jpg" alt="Cube of cubes" /></div>
<div class="tutorial_image">
<object width="550" height="400" data="http://activetuts.s3.amazonaws.com/tuts/019_PV3DSpecs/Preview/PapervisionTutorial4.swf" type="application/x-shockwave-flash"><param name="src" value="http://activetuts.s3.amazonaws.com/tuts/019_PV3DSpecs/Preview/PapervisionTutorial4.swf" /></object>
</div>
<p>Awesome!</p>
<h2>Further Ideas to Try</h2>
<p>This is only scratching the surface of what you can do with Papervision3D. Before we move on to 3D glasses, here's a few things you could experiment with:</p>
<ul>
<li>Moving the cubes, instead of rotating them: you can just alter the x, y and z properties of each cube.</li>
<li>Replacing the cubes with spheres: if you import <em>org.papervision3d.objects.primitives.Sphere</em> you can use the Sphere class. Check out the docs on this <a href="http://papervision3d.googlecode.com/svn/trunk/as3/trunk/docs/org/papervision3d/objects/primitives/Sphere.html">here</a>.</li>
<li>Controlling the camera with the mouse: you can get the mouse's x- and y-position at any time with the <em>mouseX</em> and <em>mouseY</em> properties. You can move the camera by changing its x, y and z properties. Why not link the two together?</li>
</ul>
<h2>To Be Continued...</h2>
<p>In the second part, you'll learn how to make your scene work with 3D glasses. So if you have a pair, don't throw them away!</p>
<p>In the meantime, thanks for reading the first part. I hope you found it useful. If you've got any questions, or if anything was confusing, please post a comment below.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Flashtuts?a=eW6s9253mY8:eqB2eQvuVzM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=eW6s9253mY8:eqB2eQvuVzM:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=eW6s9253mY8:eqB2eQvuVzM:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=eW6s9253mY8:eqB2eQvuVzM:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=eW6s9253mY8:eqB2eQvuVzM:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=eW6s9253mY8:eqB2eQvuVzM:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=eW6s9253mY8:eqB2eQvuVzM:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=eW6s9253mY8:eqB2eQvuVzM:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=eW6s9253mY8:eqB2eQvuVzM:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=eW6s9253mY8:eqB2eQvuVzM:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Flashtuts/~4/eW6s9253mY8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://active.tutsplus.com/tutorials/3d/journey-to-the-next-dimension-with-pv3d-and-funny-glasses-part-1/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		<feedburner:origLink>http://active.tutsplus.com/tutorials/3d/journey-to-the-next-dimension-with-pv3d-and-funny-glasses-part-1/</feedburner:origLink></item>
		<item>
		<title>Win an eBook Copy of Papervision3D Essentials!</title>
		<link>http://feedproxy.google.com/~r/Flashtuts/~3/gaMVaIrunOI/</link>
		<comments>http://active.tutsplus.com/articles/competitions-and-giveaways/win-an-ebook-copy-of-papervision3d-essentials/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 08:00:52 +0000</pubDate>
		<dc:creator>Ian Yates</dc:creator>
				<category><![CDATA[Competitions and Giveaways]]></category>

		<guid isPermaLink="false">http://active.tutsplus.com/?p=2516</guid>
		<description><![CDATA[<img src="http://activetuts.s3.amazonaws.com/tuts/018_giveawayPV3D/preview.jpg" alt="Win an eBook Copy of Papervision3D Essentials">]]></description>
			<content:encoded><![CDATA[<p>Packt Publishing is once again generously donating copies of one of their publications, this time to <strong>four</strong> lucky ActiveTuts+ Twitter followers! <a href="http://bit.ly/4nIWso" target="_blank">Papervision3D Essentials</a> is a practical guide for creating 3D in Flash and is a great reference for every Papervision3D user.</p>
<p>To win one of four <a href="http://bit.ly/4nIWso" target="_blank">Papervision3D Essentials</a> eBooks, all you need to do is ask! Read on to find out more..</p>
<p><span id="more-2516"></span></p>
<h3>What Do I Have To Do?</h3>
<p><!--
<p>I&#8217;m afraid the draw has already taken place! Still, keep following <a href="http://twitter.com/flashtuts" target="_blank">@flashtuts</a> and you&#8217;re bound to hear of more giveaways soon <img src='http://active.tutsplus.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>&#8211;></p>
<ol>
<li>Firstly, you&#8217;ll need to <a href="http://twitter.com/activetuts">follow us on Twitter</a>, assuming you aren&#8217;t already <img src='http://active.tutsplus.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </li>
<li>Then, tweet us with the following message:</li>
</ol>
<p><strong>@activetuts: I&#8217;d like a Papervision3D Essentials eBook! http://tinyurl.com/ykz49lb</strong></p>
<p>That&#8217;s it! Four winners will be selected at random just before the weekend (Friday 20th November) and informed via Twitter.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/018_giveawayPV3D/1847195725.jpg" alt="" /></div>
<blockquote>
<p>Papervision3D is a powerful real-time 3D engine for Flash. Papervision3D can take externally created 3D models and render them as Flash content, without requiring end-users to download or install an additional plug-in. It has an outstanding reputation within the Flash community and its ease of use has even impressed experienced 3D game developers. However, getting started with Papervision3D can be daunting and mastering it can be challenging. This book guides you through the easiest way to tackle challenges that you may normally face with Papervision3D and master them effectively.</p>
<p>The book will show you how to build Papervision3D applications from scratch in the easiest way, providing plenty of examples that make sense even if you&#8217;re not a Flash expert. Papervision3D Essentials serves as a comprehensive guide to getting you started, as well as being an invaluable reference for every Papervision3D user and developer. By the end of this book you will be able to create your own projects with real-time 3D rendering.</p>
</blockquote>
<p>Want to know more? Go and check out <a href="http://bit.ly/4nIWso" target="_blank">Papervision3D Essentials</a> on the Packt Publishing website, read all about it and even <a href="http://activetuts.s3.amazonaws.com/tuts/018_giveawayPV3D/Chapter 8- External Models.pdf" target="_blank">download a sample chapter</a>.</p>
<h2>Thanks, <a href="http://www.packtpub.com/" target="_blank">Packt Publishing!</a></h2>
<blockquote>
<p>Packt is a modern, unique publishing company with a focus on producing cutting-edge books for communities of developers, administrators, and newbies alike. </p>
</blockquote>
<p>Entries are open worldwide and the winning tweet will be chosen through <a href="http://random.org" target="_blank">random.org</a>. This giveaway is open worldwide, but make sure to get your tweet tweeted before midnight this Friday, Pacific Eastern Standard Time.</p>
<p>If your entry is drawn, we&#8217;ll contact you directly, at which point you&#8217;ll have seven days to claim. Failure to respond within that time will result in a re-draw.</p>
<p><em>Please note: Envato staff and people who have written more than two tutorials/articles for a Tuts+ site are not eligible to enter.</em></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Flashtuts?a=gaMVaIrunOI:yM2DxV0k1uQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=gaMVaIrunOI:yM2DxV0k1uQ:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=gaMVaIrunOI:yM2DxV0k1uQ:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=gaMVaIrunOI:yM2DxV0k1uQ:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=gaMVaIrunOI:yM2DxV0k1uQ:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=gaMVaIrunOI:yM2DxV0k1uQ:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=gaMVaIrunOI:yM2DxV0k1uQ:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=gaMVaIrunOI:yM2DxV0k1uQ:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=gaMVaIrunOI:yM2DxV0k1uQ:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=gaMVaIrunOI:yM2DxV0k1uQ:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Flashtuts/~4/gaMVaIrunOI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://active.tutsplus.com/articles/competitions-and-giveaways/win-an-ebook-copy-of-papervision3d-essentials/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
		<feedburner:origLink>http://active.tutsplus.com/articles/competitions-and-giveaways/win-an-ebook-copy-of-papervision3d-essentials/</feedburner:origLink></item>
		<item>
		<title>Treat Your Viewers to a Full Screen HD Video Experience</title>
		<link>http://feedproxy.google.com/~r/Flashtuts/~3/l4sW5S5y5Ck/</link>
		<comments>http://active.tutsplus.com/tutorials/video/treat-your-viewers-to-a-full-screen-hd-video-experience/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 12:00:10 +0000</pubDate>
		<dc:creator>Tom Green</dc:creator>
				<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://active.tutsplus.com/?p=2497</guid>
		<description><![CDATA[<img src="http://activetuts.s3.amazonaws.com/tuts/017_hiDefVideo/Preview/1.jpg" alt="">]]></description>
			<content:encoded><![CDATA[<p>In this beginner to intermediate tutorial I&#8217;m going to show you how to play HD video without the inevitable blurring that occurs when the video is enlarged.</p>
<p>The reason for this is that I&#8217;m getting a bit tired of visiting YouTube or other sites that present HD video with a full screen option only to discover, when I click the Full Screen button, that I suddenly need the prescription for my glasses changed.</p>
<p>The issue is not the video but how the Flash Player handles the process of going full screen. Let&#8217;s find out how to do things <strong>properly</strong>..</p>
<p><span id="more-2497"></span></p>
<div class="tutorial_image">
<a href="http://activetuts.s3.amazonaws.com/tuts/017_hiDefVideo/Exercise.zip" target="_blank"><br />
<img src="http://activetuts.s3.amazonaws.com/assets/icons/exercise.jpg" alt="" style="border:none"></a><br />
<a href="http://activetuts.s3.amazonaws.com/tuts/017_hiDefVideo/Preview/Complete/BigItUp.html" target="_blank"><br />
<img src="http://activetuts.s3.amazonaws.com/assets/icons/demo.jpg" alt="" style="border:none"></a>
</div>
<h2>Introduction</h2>
<p>When you play video in the Flash Player, the video, for all intents and purposes, is laid into the stage. Click the full screen button and the stage gets bigger. When the stage gets bigger it brings the video along with it. Enlarge a 720 by 480 video to 1280 by 720 and is it any wonder that the video gets fuzzy?</p>
<p>Adobe wrestled with this issue when they were introducing the ability to play full HD video through the Flash Player. Their solution, introduced in Flash Player 9.0.115.0 , was extremely elegant. Instead of enlarging the stage, why not &#8220;hover&#8221; the vid in a rectangle &#8220;above&#8221; the stage and have the designer or developer decide whether to enlarge the stage or just a piece of it. This is accomplished through another piece of clever engineering on Adobe’s part: Hardware acceleration and scaling.</p>
<p>Hardware acceleration is applied through the Flash Player. If you right-click (PC) or ctrl-click (Mac) on a swf playing in a web page you&#8217;ll open the Flash Player context menu. Select <em>Settings</em> and you&#8217;ll be presented with the the settings window shown in Image 1. If you select <em><strong>Enable hardware acceleration</strong></em> you are able to view full screen HD video. If you leave it deselected, clicking a full screen button  results in the Player using the Scaling API used when an FLV file is taken out to full screen. The neat thing about this is even though you have selected hardware acceleration, it is only used when needed. Thus, when a Full Screen button is clicked only the rectangle and it contents &#8211; a video in this instance &#8211; are scaled to full screen and hardware acceleration takes over to play the video.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/017_hiDefVideo/Tutorial/2.jpg" alt="" width="420" height="333" /></div>
<p>Having given you the briefing on how we got you reading this tutorial, follow these steps to create a full screen HD video experience:</p>
<h2>Step 1: Download the the <a href="http://activetuts.s3.amazonaws.com/tuts/017_hiDefVideo/Exercise.zip" target="_blank">Exercise files</a></h2>
<p>Included with the download is an .mp4 file- Vultures.mp4. It is a clip from a TV series produced by my College, Humber institute of Technology and Advanced Learning. We&#8217;ll be using this file for the project though mov, f4v and physically large FLV files can also be used.</p>
<p>You may have heard a lot of &#8220;buzz&#8221; around HD video and the .mp4 format over the past couple of years and wondered what the chatter is all about. Here’s a brief &#8220;elevator pitch&#8221;:</p>
<p>The key to the .mp4 format is the AVC/H.264 video standard introduced to the Flash Player in August 2007. The .mp4 standard, to be precise, is known as MPEG-4 which is an international standard developed by the Motion Pictures Expert Group (MPEG) and the format also has ISO recognition.</p>
<p>What makes these files so attractive to Flash designers and developers is that MPEG-4 files aren’t device dependent. They can just as easily be played on an HD TV, iPod or Playstation as they can be played in a browser. Also, thanks to hardware acceleration and multithreading support built into the Flash Player, you can play video at any resolution and bit depth up to, and including  the full HD 1080p resolution you watch on HD TV’s.</p>
<p>The one aspect of the MPEG-4 standard that I find rather intriguing is that, like the XFL format just coming into use throughout the CS4 suite, it is a &#8220;container&#8221; format. What&#8217;s meant by this is .mp4 files can store several types of data on a number of tracks in the file. What it does is synchronize and interleave the data meaning an .mp4 file can also include metadata, artwork, subtitles and so on that can potentially be accessed by Flash. That’s the good news. The bad news is even though the  MPEG-4 container can contain multiple audio and video tracks, the Flash Player currently only plays one of each and ignores the rest. The other bit of bad news is this format does not support transparency meaning, if you want to add an alpha channel, you are back to the FLV format.</p>
<p>Finally, H.264 .mp4 files require heavy duty processing power.  Adobe has been quite clear  in letting us know this content is best viewed on dual core PC’s and Macs. The shift to these processors has been underway for a couple of years but it will still be a couple of years before all computers will be able to manage the processor demands this format requires.</p>
<p>I have barely skimmed the surface of this format. If you want to take a &#8220;deep dive&#8221; into this format, check out <a href="http://www.adobe.com/devnet/flashmediaserver/articles/h264_primer.html">H.264 For The Rest Of Us </a>written by Kush Amerasinghe at Adobe. It&#8217;s a tremendous primer for those of you new to this technology.</p>
<h2>Step 2: Big It Up!</h2>
<p>Open the <em>BigItUp.fla</em> file located in the download. If this is your first time working with an H264 file or going full screen, you may find the Flash stage dimensions &#8211; 1050 by 500 &#8211; to be rather massive. We need the stage space to accommodate the video which has a physical size of 854 x 480 and to leave room for the button in the upper left corner of the stage.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/017_hiDefVideo/Tutorial/3.jpg" width="600" height="304" /></div>
<h2>Step 3: Geometry</h2>
<p>Add the following ActionScript to the actions layer:</p>
<pre name="code" class="javascript">
import flash.geom.*;
import flash.display.Stage;

  var mySound:SoundTransform;
  var myVideo:Video;
  var nc:NetConnection = new NetConnection();
  nc.connect(null);
  var ns:NetStream = new NetStream(nc);
  ns.client = this;

btnBig.buttonMode = true;
</pre>
<p>We start by bringing in the geometry package and the Stage class in order to take the &#8220;hovering&#8221; video to full screen. The next two variables &#8211; mySound and myVideo &#8211; are going to be used to set the volume level of the audio and to create a Video Object.</p>
<p>With that housekeeping out of the way we set up the <em>NetConnection </em>and <em>NetStream</em> objects that will allow the video to play. The final line puts the movieclip used to get the video to full screen into <em>buttonMode</em>.</p>
<h2>Step 4: Functions</h2>
<p>Add the following ActionScript:</p>
<pre name="code" class="javascript">
ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);

function netStatusHandler(evt:NetStatusEvent):void {
  if(evt.info.code == &quot;NetStream.FileStructureInvalid&quot;)
  {
  trace(&quot;The MP4's file structure is invalid.&quot;);
  }
  else if(evt.info.code == &quot;NetStream.NoSupportedTrackFound&quot;)
  {
  trace(&quot;The MP4 doesn't contain any supported tracks&quot;);
  }
  }

function onMetaData(md:Object):void {

  myVideo.width = md.width;
  myVideo.height = md.height;
  }
  </pre>
<p>The first function lets us do some error checking. Not all mp4 files are created alike and if the video doesn’t play it would be nice to know what the problem might be. In this case we are going to listen for a couple of error messages from the NetStream class that are germane to mp4 files. The first one is a check to make sure the file is not corrupt or is a format that is not supported.  Just because a file will play in the Quicktime player does not mean it will play in Flash.</p>
<p>The next one  makes sure the audio and video tracks are supported. For example if the H.264 encoding is not used on the video track or AAC encoding is not applied to the audio track, you&#8217;ll have issues.</p>
<p>The next function goes into the video file’s metadata to obtain the width and height values for the Video Object.</p>
<h2>Step 5: goFullScreen</h2>
<p>Enter the following ActionScript:</p>
<pre name="code" class="javascript">
function goFullScreen(evt:Object):void
  {
  var scalingRect:Rectangle = new Rectangle(myVideo.x, myVideo.y, myVideo.width, myVideo.height);
  stage[&quot;fullScreenSourceRect&quot;] = scalingRect;
  if(stage.displayState == StageDisplayState.NORMAL)
  {
  stage.displayState = StageDisplayState.FULL_SCREEN;
  }
  else
  {
  stage.displayState = StageDisplayState.NORMAL;
  }
};

btnBig.addEventListener(MouseEvent.CLICK, goFullScreen);<
</pre>
<p>This is where the "magic" happens. This function creates the rectangle used to hold the video and its size is set to match those of the Video Object’s dimensions pulled out of the second function in the previous code block. The next line sets the <em>fullScreenSourceRect </em>property of the stage to the dimensions of the rectangle just created. </p>
<p>The conditional statement making up the remainder of the code block checks the current state of the stage size from normal to full screen or vice versa. This is how the video goes full screen. The Video Object is laid into this source rect, not the stage, which means it can expand or contract without the stage doing likewise and "fuzzing" the video.</p>
<p>The last line uses the button on the stage to go full screen.</p>
<h2>Step 6: myVideo</h2>
<p>Enter the following ActionScript:</p>
<pre name="code" class="javascript">
  myVideo = new Video();
  myVideo.x = 185;
  myVideo.y = 5;
  addChild(myVideo);
  myVideo.attachNetStream(ns);
  ns.play(&quot;Vultures.mp4&quot;);

  mySound = ns.soundTransform;
  mySound.volume = .8;
  ns.soundTransform = mySound;
 </pre>
<p>The first code block tells Flash the variable "myVideo" is the name for a Video Object which is located 185 pixels fro the left edge of the enormous stage and is 5 pixels down from the top. The <em>addChild()</em> method puts the Video Object on the stage and the remaining two lines connect the video object to the <em>NetStream</em> and start the video playing.</p>
<p>The final code block looks into the video’s audio track which is being fed into the project through the <em>NetStream</em> and lowers the audio volume to 80%.</p>
<h2>Step 7: Save</h2>
<p>Save the file to the same folder as the video.</p>
<p>Normally, at this stage of the tutorial I would also tell you to test the swf. You can, but the button won’t work. The best you can expect is to see the video play in the swf. The Full Screen feature is driven by the HTML wrapper of your swf, not Flash. Let’s deal with that one.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/017_hiDefVideo/Tutorial/4.jpg" width="600" height="299" /></div>
<h2>Step 8: Publish Settings</h2>
<p>Select File &gt; Publish Settings. When the Publish Settings dialog box opens, select the SWF and HTML options.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/017_hiDefVideo/Tutorial/5.jpg" width="555" height="766" /></div>
<h2>Step 9: Player Version</h2>
<p>Click the Flash tab. Select Flash Player 9 or Flash Player 10 in the Player pop down. Remember HD video can only be played in Flash Player 9 or later.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/017_hiDefVideo/Tutorial/6.jpg" width="547" height="184" /></div>
<h2>Step 10: HTML</h2>
<p>Click the HTML tab. In the Template pop down menu select Flash Only-Allow Full Screen.</p>
<p>Click the Publish button to create the SWF and the HTML file.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/017_hiDefVideo/Tutorial/7.jpg" width="550" height="608" /></div>
<h2>Step 11: Test</h2>
<p>Save the file, quit Flash and open the HTML page in a browser. Go ahead, click the "<em><strong>Big it up!</strong></em>" button.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/017_hiDefVideo/Tutorial/8.jpg" width="600" height="374" /></div>
<h4>What about the Component?</h4>
<p>What about it? Real Flash designers and developers don’t use no "steenking" components. </p>
<p>In December of  2007, Adobe quietly released Update 3 for the Flash Player 9. I use the word "quietly" because mixed in with the usual bug fixes and tweaks, they slipped in an updated version of the FLVPlayback component that allowed it to play HD video. Here’s how:</p>
<h2>Step 12: New Document</h2>
<p>Open a new Flash ActionScript 3.0 document and save it to the same folder as the Vultures video.</p>
<h2>Step 13:  FLVPlayback Component</h2>
<p>Select <em>Window&gt;Components</em> and in the Video components, drag a copy of the <em>FLVPlayback</em> component to the stage.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/017_hiDefVideo/Tutorial/9.jpg" width="553" height="398" /></div>
<h2>Step 14: Component Inspector</h2>
<p>Open the Component Inspector. You need to do two things here. Select the <em>SkinUnderAllNoCaption.swf</em> in the skin area, in the source area navigate to the <em>Vultures.mp4</em> file and add it to the Content Path dialog box. Click the match source dimensions check box and click OK. Flash will go into the video and grab the metadata. When that finishes, the dialog box will close and the component will grow to the dimensions of the video. Close the Component Inspector.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/017_hiDefVideo/Tutorial/10.jpg" alt="" width="600" height="420" /></div>
<h2>Step 15: Modify &gt; Document</h2>
<p>Select Modify &gt; Document and click the <em>Contents </em>button to resize the stage to the size of the component .... sort of. When the stage is set to the size of the component it only resizes to the size of the video. The skin will be left hanging off the bottom of the stage which means it isn’t going to be visible in a web page. Change the height value to 525 pixels to accomodate the skin. Click OK to accept the change.</p>
<p>Of course, now that you have changed the stage dimensions the component is hanging off the stage. Select the component and in the Properties Panel set the X and Y coordinates to 0.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/017_hiDefVideo/Tutorial/11.jpg" width="600" height="366" /></div>
<h2>Step 16: Publish Settings</h2>
<p>Select File &gt;Publish Settings and choose the SWF and HTML file types.</p>
<h2>Step 17: Player Version</h2>
<p>Click the Flash tab and select Flash Player 9.</p>
<h2>Step 18: HTML</h2>
<p>Click the HTML tab and select Flash Only- Allow Full Screen in the Templates pop down.</p>
<h2>Step 19: Publish</h2>
<p>Click the Publish button. When the SWF and the HTML file are published click OK. Save the file and quit Flash.</p>
<h2>Step 20: Test</h2>
<p>Open the HTML file in a browser. Click the Full Screen button to launch into Full Screen mode. </p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/017_hiDefVideo/Tutorial/12.jpg" width="600" height="393" /></div>
<h2>Conclusion</h2>
<p>In this tutorial I've showed you two ways of smoothly going into full screen mode with Flash. The first method used ActionScript to make this possible and the key was creating a rectangle that "hovered" over the stage and was used to hold the video.</p>
<p>The second example showed you how to use the FLVPlayback component to go full screen.</p>
<p>As you've discovered, the key for both projects was not the ActionScript but the HTML wrapper that enabled the full screen playback.</p>
<p>These tutorials always work locallly but I'm sure you're wondering if they would actually work online. I've posted both to prove that "Yes indeed, it can be done."</p>
<p>The code approach in the first example can be <a href="http://www.tomontheweb4.ca/Bomb/">found here</a>. The video is kindly provided by Adobe and Red Bull and is a full 1080p production.</p>
<p>The Vultures appear in an example that uses the component <a href="http://activetuts.s3.amazonaws.com/tuts/017_hiDefVideo/Preview/Complete/Big_Component.html">here</a>.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Flashtuts?a=l4sW5S5y5Ck:wf7bOcGXFMo:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=l4sW5S5y5Ck:wf7bOcGXFMo:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=l4sW5S5y5Ck:wf7bOcGXFMo:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=l4sW5S5y5Ck:wf7bOcGXFMo:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=l4sW5S5y5Ck:wf7bOcGXFMo:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=l4sW5S5y5Ck:wf7bOcGXFMo:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=l4sW5S5y5Ck:wf7bOcGXFMo:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=l4sW5S5y5Ck:wf7bOcGXFMo:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=l4sW5S5y5Ck:wf7bOcGXFMo:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=l4sW5S5y5Ck:wf7bOcGXFMo:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Flashtuts/~4/l4sW5S5y5Ck" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://active.tutsplus.com/tutorials/video/treat-your-viewers-to-a-full-screen-hd-video-experience/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		<feedburner:origLink>http://active.tutsplus.com/tutorials/video/treat-your-viewers-to-a-full-screen-hd-video-experience/</feedburner:origLink></item>
		<item>
		<title>Create a Comment Form with Flash, PHP, XML and MySQL</title>
		<link>http://feedproxy.google.com/~r/Flashtuts/~3/vvIE_8ksKvQ/</link>
		<comments>http://active.tutsplus.com/tutorials/actionscript/create-a-comment-form-with-flash-php-xml-and-mysql/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 12:00:41 +0000</pubDate>
		<dc:creator>Jeremy Green</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Intermediate]]></category>

		<guid isPermaLink="false">http://active.tutsplus.com/?p=2409</guid>
		<description><![CDATA[<img src="http://activetuts.s3.amazonaws.com/tuts/012_phpCommentForm/Preview/preview.jpg" alt="">]]></description>
			<content:encoded><![CDATA[<p>In this tutorial, I&#8217;ll show you how to use Flash, PHP and MySQL together. We&#8217;ll build a simple comment form that takes entries and stores them in a database.  We&#8217;ll use PHP to retrieve the entries and format the comments into XML form. Let&#8217;s get going!</p>
<p><span id="more-2409"></span></p>
<div class="tutorial_image">
<a href="http://activetuts.s3.amazonaws.com/tuts/012_phpCommentForm/Source.zip" target="_blank"><br />
<img src="http://activetuts.s3.amazonaws.com/assets/icons/source.jpg" alt="" style="border:none"></a>
</div>
<h2>Step 1: Create the Flash File</h2>
<p>Start up Flash and create a new Flash file(ActionScript 3.0). Create a new folder and save the file into the folder as &#8220;commentForm.fla&#8221;. Next create a new ActionScript File. Save the file into the same folder as &#8220;commentForm.as&#8221;.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/012_phpCommentForm/Tutorial/1.jpg" alt="" /></div>
<h2>Step 2: Setting the Stage</h2>
<p>Open your newly created Flash document, then in the properties panel, change the size of the stage to 960&#215;400 pixels. Also, in the Document class text box, type in &#8220;commentForm&#8221;. This will link the external ActionScript file with our Flash document.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/012_phpCommentForm/Tutorial/2.jpg" alt="" /></div>
<h2>Step 3: The Background</h2>
<p>Select the Rectangle tool and draw out a retangle with a stroke of any size. Select the whole rectangle and open the Align panel by going to Window &gt; Align. In the Align panel, under &#8220;Match size&#8221;, click the &#8220;Match width and height&#8221; button. This will scale the rectangle to the size of the stage. Still in the Align panel, under &#8220;Align&#8221;, click the &#8220;Align left edge&#8221; and &#8220;Align top edge&#8221; buttons. This will move the rectangle to the top-left of the stage.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/012_phpCommentForm/Tutorial/3.jpg" alt="" /></div>
<p>Next, select the fill portion of the rectangle. In the Color panel, select the linear gradient as the fill color. With the rectangle still selected, select the Gradient Transform tool and rotate the gradient 90 degrees (make sure the black side is facing towards the bottom). Under the gradient color options, give the white portion a color of #F2F2F2. Then, give the black side a color of #D9D9D9. Finally, select the stroke, give it a color of #999999, and in the properties panel, give it a size of 2.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/012_phpCommentForm/Tutorial/4.jpg" alt="" /></div>
<p>Lastly, select the whole rectangle and convert it into a movieclip. Go into the Filters window, click on the plus icon and give the movieclip a Glow. The Glow should have a 10 for Blur X and Blur Y, Strength of 33%, Quality of High, Color of black and make sure to check the Inner glow box. The rectangle movieclip should have a slight inner glow now.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/012_phpCommentForm/Tutorial/5.jpg" alt="" /></div>
<h2>Step 4: Adding the Components</h2>
<p>Select the Text tool. In the properties panel, select Dynamic Text, make sure the color is black, font of &#8220;Arial&#8221;, and font size of 10. On a new layer, draw out a text box that is 41.9px wide and a height of 15.2px. Give the text box an X position of 18 and a Y position of 6.3. Finally, give the text box an instance name of &#8220;nameText&#8221;.</p>
<p>Create another text box on the stage. This text box will have a width of 246.9, a height of 17.4, a X position of 18, a Y position of 22.9, and an instance name of &#8220;nameField&#8221;.</p>
<p>Now create <em>another</em> text box with a width of 41.9, height of 15.2, X of 18, Y of 42.4, and instance name of &#8220;emailText&#8221;.</p>
<p>Make another (nearly there) text box with a width of 246.9, height of 17.4, X of 18, Y of 58.9, and instance name of &#8220;emailField&#8221;.</p>
<p>Once again, create a text box with a width of 55.5, height of 15.2, X of 18, Y of 80.1 and instance name of &#8220;commentText&#8221;.</p>
<p><em>Finally</em>, make one more text box. Give it a width of 466.9, height of 260.9, X of 18, Y of 96.3 an instance name of &#8220;commentField&#8221;, and set the Maximum characters field to 1000. In the text box with the name &#8220;nameText&#8221;, give it a value of &#8220;Name&#8221;. Next, select the &#8220;emailText&#8221;, and give it a value of &#8220;Email&#8221;. Finally, select the &#8220;commentText&#8221; text box, and give it a value of &#8220;Comment&#8221;. We&#8217;ll be changing the text color of these text boxes dynamically.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/012_phpCommentForm/Tutorial/6.jpg" alt="" /></div>
<p>Create another dynamic text box. Give it a width of 421.1, a height of 211.4, X of 521.3, Y of 144.6, and instance name of &#8220;area&#8221;. Select all four empty dynamic text boxes, and in the properties panel, change their font size to 12. Only the label text fields should have a font size of 10. Select the text tool again. In the Properties panel, change the type back to Static, color is black, font is &#8220;Arial&#8221;, and font size is 10. Create a static text box. Give it a width of 5.2, height should default to 15.2, X of 520.5, Y of 11.1 and give it a value of &#8220;Comments&#8221;.</p>
<p><P>Next, navigate to the Components panel. Drag an instance of the List component onto the stage. Give the List component a width of 422.9, height of 100, X of 520, Y of 27.8 and an instance name of &#8220;list&#8221;.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/012_phpCommentForm/Tutorial/7.jpg" alt="" /></div>
<p>Drag a copy of the Checkbox component onto the stage. Give it a width of 100, height of 22, X of 280.3, Y of 57.4, instance name of &#8220;newsletter&#8221;, and, in the Parameters panel, give it a label of &#8220;Newsletter&#8221;. Lastly, create one more dynamic text field. Make sure it has a color of black, font is &#8220;Arial&#8221;,and the font size is 10. Give it a width of 128, height of 15.2, X of 356.9, Y of 367.6 and instance name of &#8220;dyTex&#8221;.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/012_phpCommentForm/Tutorial/8.jpg" alt="" /></div>
<h2>Step 5: Adding the Component Backgrounds</h2>
<p>The next step is create the graphics underneath the text boxes. Create a new layer and move it below the layer with the text fields. Select the Rectangle tool. In the properties panel, give it a stroke of 2. Make sure the stroke&#8217;s color is #CCCCCC. Give the rectangle a fill of white. In the rounded corners box, give it a value of 10.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/012_phpCommentForm/Tutorial/9.jpg" alt="" /></div>
<p>Draw out a rectangle that has a width of 466.9, a height of 260.9. Select the whole rectangle and convert it to a movieclip. With the movieclip selected, go to the Filters tab. Give the rectangle a new Dropshadow filter. The new filter will have a 6 for Blur X and Blur Y, a Strength of 66%, a Quality of High, an Angle of 90, a Distance of 1, a Color of black, and check the box next to Inner shadow. Finally, give the rectangle movieclip a X position of 18 and a Y position of 96.3.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/012_phpCommentForm/Tutorial/10.jpg" alt="" /></div>
<p>Next draw out another rectangle with the same styles applied. This time, give the rectangle a width of 422.6, height of 214. Convert it into a movieclip. Then give the movieclip an X of 520.5 and a Y of 143.3. Apply the same filter as the previous rectangle.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/012_phpCommentForm/Tutorial/11.jpg" alt="" /></div>
<p>Now we&#8217;re going to create another rectangle. This time give the rounded corners a value of 5; leave all the other parameters the same. Draw a rectangle that has a width of 246.9, and a height of 17.4. Turn it into a movieclip and give it an X value of 18 and a Y of 22.8. Next, go to the Filters tab and apply a Dropshadow filter. Give the filter a Blur X and Blur Y value of 4, Strength of 66%, Quality of High, Color of black, Angle of 90, Distance of 1, and check the box next to Inner shadow. Select the movieclip and duplicate it. Give the next movieclip a X of 18, and Y of 58.9.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/012_phpCommentForm/Tutorial/12.jpg" alt="" /></div>
<h2>Step 6: The Final Touches</h2>
<p>Take the Rectangle tool one more time. Make sure that there is still a value of 5 for the rounded corners and draw a rectangle that is 99 wide and has a height of 20.6. Convert this shape into a Button. Enter the edit mode of the button and add a new layer. Grab the Text tool and create a static text box with a value of &#8220;Submit&#8221;. Give the new button a X of 18.3, Y of 367.6, and an instance name of &#8220;button&#8221;.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/012_phpCommentForm/Tutorial/13.jpg" alt="" /></div>
<p>Finally, select the Line tool. Give it a stroke size of 1 and a color of #999999. Draw a line on the stage. Select the line and give it a height of 327, X of 502.4, and Y of 28.2. Duplicate the line and move it over one pixel to the right and give it a color of white. The application is fully designed now.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/012_phpCommentForm/Tutorial/14.jpg" alt="" /></div>
<h2>Step 7: The Document Class Skeleton</h2>
<p>Navigate over to the ActionScript file that was created at the beginning of this tutorial. Paste this code into it.</p>
<pre name="code" class="javascript">
package {

	import flash.display.Sprite;

	public class commentForm extends Sprite
	{

		public function commentForm()
		{

		}
	}
}
</pre>
<h2>Step 8: The Imports</h2>
<p>Here are the import statements that we&#8217;re going to use. Paste them in below the package declaration and above the class declaration. Also, we list out the variables we&#8217;re going to use.</p>
<pre name="code" class="javascript">
package {

	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.FocusEvent;
	import flash.events.IOErrorEvent;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	import flash.external.ExternalInterface;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.URLRequestMethod;
	import flash.net.URLVariables;
	import flash.text.TextField;

	public class commentForm extends Sprite
	{
		private var tf:TextField;
		private static const URL:String = "YOUR_SERVER";

		public function commentForm()
		{

		}
	}
}
</pre>
<h2>Step 9: The Init Function</h2>
<p>Here, we are setting the event listeners and word wrapping for the large text fields. Also we call the onComplete and onInput functions. The onComplete function will load the XML from the database. This way the list component is populated when the application starts. With the onInput function, we set the dyText text field with proper value.</p>
<pre name="code" class="javascript">
		public function commentForm()
		{
			init();
		}
        private function init():void
		{
			commentField.addEventListener(FocusEvent.FOCUS_IN, onFocus);
			emailField.addEventListener(FocusEvent.FOCUS_IN, onFocus);
			nameField.addEventListener(FocusEvent.FOCUS_IN, onFocus);
			commentField.addEventListener(KeyboardEvent.KEY_DOWN, onInput);
			commentField.addEventListener(KeyboardEvent.KEY_UP, onInput);
			button.addEventListener(MouseEvent.CLICK, onClick);
			onComplete(null);
			onInput(null);
			commentField.wordWrap = true;
			area.wordWrap = true;
		}
</pre>
<h2>Step 10: The onInput Function</h2>
<p>The onInput function will update the text field at the bottom of our application. It simply takes the amount of characters entered into the comment form and subtracts the total amount allowed. We use both the &#8220;KEY_UP&#8221; and &#8220;KEY_DOWN&#8221; events because we want the field to update even when someone is holding a certain key down. Also we check to see if the comment text field is full. If it is, we turn the text red.</p>
<pre name="code" class="javascript">
		private function onInput(event:KeyboardEvent):void
		{
			dyText.text = String(commentField.maxChars - commentField.length) + " characters left";
			if(dyText.text == "0 characters left")
			{
				dyText.textColor = 0xff0000;
			}
			else
			{
				dyText.textColor = 0x000000;
			}
		}
</pre>
<h2>Step 11: Handling the Click</h2>
<p>This is the function that will handle the &#8220;CLICK&#8221; event. Here is where we pass the variables over to PHP, and listen for the &#8220;COMPLETE&#8221; event. However, before we send anything over to PHP, we need to check and make sure that the text fields aren&#8217;t empty. If they are, then we change their label text field to red.</p>
<pre name="code" class="javascript">
private function onClick(event:MouseEvent):void
		{
			button.focusRect = false;
			stage.focus = button;
			var name:String = nameField.text;
			var email:String = emailField.text.toLowerCase();
			var comment:String = commentField.text;
			if(validateString(name))
			{
				if(validateEmail(email))
				{
					if(validateString(comment))
					{
						var url:URLLoader = new URLLoader();
						var req:URLRequest = new URLRequest(URL+"/leave.php");
						var vars:URLVariables = new URLVariables();
						req.method = URLRequestMethod.POST;
						vars.submit = true;
						vars.name = name;
						vars.email = email;
						vars.comment = comment;
						if(newsletter.selected)
						{
							vars.newsletter = true;
						}
						else
						{
							vars.newsletter = false;
						}
						req.data = vars;
						url.addEventListener(Event.COMPLETE, onComplete);
						url.addEventListener(IOErrorEvent.IO_ERROR, onError);
						url.load(req);
					}
					else
					{
						commentText.textColor = 0xff0000;
						tf = commentText;
					}
				}
				else
				{
					emailText.textColor = 0xff0000;
					tf = emailText;
				}
			}
			else
			{
				nameText.textColor = 0xff0000;
				tf = nameText;
			}
		}
</pre>
<h2>Step 12: Validate the Text Fields</h2>
<p>Here are the two functions used to validate our text fields. The validateEmail function takes the text field and runs a regular expression on it to verify the email. The validateString function will strip all the HTML tags that might be inserted and makes sure that there is at least text in that field.</p>
<pre name="code" class="javascript">
private function validateEmail(string:String):Boolean
		{
			var pattern:RegExp = /[a-z0-9!#$%&#038;"*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&#038;"*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/g;
			if(pattern.exec(string) != null)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		private function validateString(string:String):Boolean
		{
			var bool:Boolean;
			var pattern:RegExp = /&lt;\/?\w+((\s+(\w|\w[\w-]*\w)(\s*=\s*(?:\".*?\"|".*?"|[^"\">\s]+))?)+\s*|\s*)\/?>/gi;
			string = string.replace(pattern, "");
			var pattern2:RegExp = /[a-zA-Z0-9]/g;
			if(string.search(pattern2) == -1)
			{
				bool = false;
			}
			else
			{
				bool = true;
			}
			return bool;
		}
</pre>
<h2>Step 13: The SQL Code</h2>
<p>Here is the sql code to create the table on your database.</p>
<pre name="code" class="php">
 CREATE TABLE `YOUR_DATABASE`.`comments` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR( 40 ) NOT NULL ,
`email` VARCHAR( 40 ) NOT NULL ,
`comment` VARCHAR( 1200 ) NOT NULL
) ENGINE = MYISAM
</pre>
<h2>Step 14: The Database Connection</h2>
<p>The first part of our PHP is to create our database connection. Copy this code into a new php file. Save the file as &#8220;require.php&#8221;.</p>
<pre name="code" class="php">
&lt;?php
$username = "YOUR_USERNAME";
$password = "YOUR_PASSWORD";
$hostname = "YOUR_HOST"; 

$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");

$selected = mysql_select_db("YOUR_DATABASE",$dbhandle)
or die("Could not select examples");

?>
</pre>
<h2>Step 15: Inserting Comments into the Database</h2>
<p>With the database file saved, we can then access it in our feedback form. The &#8220;require_once&#8221; line will load the database connection file. We have some added security this way. We then check to see if the &#8220;submit&#8221; variable is empty. We sent the &#8220;submit&#8221; from Flash when we clicked the button to send. If the variable isn&#8217;t empty, we populate our variables on the PHP side. After we clean the values, we insert them into the database. Save this file as &#8220;leave.php&#8221; into the same directory as your &#8220;require.php&#8221; file.</p>
<pre name="code" class="javascript">
&lt;?php
require_once("require.php");
if(!empty($_POST["submit"]))
{
	$name = $_POST["name"];
	$email = $_POST["email"];
	$comment = $_POST["comment"];
	$newsletter = $_POST["newsletter"];
	$name = validateString($name);
	$email = validateString($email);
	$email = filter_var($email, FILTER_SANITIZE_EMAIL);
	$comment = validateString($comment);
	if($newsletter)
	{
		if(handleEmail($name, $email))
		{
			echo 1;
		}
		else
		{
			echo 0;
		}
	}
	$query = "INSERT INTO comments VALUES("","$name","$email", "$comment")";
	mysql_query($query) or die(mysql_error());
	echo 1;
	mysql_close($dbhandle);
}
else
{
	echo 0;
}
?&gt;
</pre>
<h2>Step 16: Cleaning the Values</h2>
<p>Here is where we clean the values to insert into our database. We escape any dangerous inputs, then we strip all the html tags out of the value. Then, just in case something made it through, we sanitize the value.</p>
<pre name="code" class="javascript">
function validateString($string)
{
	$string = mysql_real_escape_string($string);
    $string = strip_tags($string);
	$string = filter_var($string, FILTER_SANITIZE_STRING);
	return $string;
}
</pre>
<h2>Step 17: Handling the Email</h2>
<p>This is the function that we use to send the email out. For this example, I&#8221;m using &#8220;PHPMailer&#8221;. You can download the source <a href="http://phpmailer.worxware.com/" target="_blank">here</a>. This is a very simple class to work with. Here we require the class like we did with our database connection. We tell PHPMailer that we&#8217;re sending an HTML email, and pass it to and from values as well as the HTML string. You&#8217;ll notice in the &#8220;AddAddress&#8221; method, we pass the email and name values. The final function is the HTML content. It can be adjusted to say whatever you want. This function is only called if the &#8220;newsletter&#8221; Checkbox is clicked.</p>
<pre name="code" class="javascript">
function handleEmail($name, $email)
{
	require("phpMailer/class.phpmailer.php");
	$mail = new PHPMailer();
	$mail->From = "YOUR_FROM_ADDRESS(mail@example.com)";
	$mail->FromName = "YOUR_FROM NAME(webmaster)";
	$mail->AddReplyTo("YOUR_REPLY_TO_NAME(no-reply@example.com");
	$mail->AddAddress($email, $name);
	$mail->isHTML(true);
	$mail->Subject = "YOUR_SUBJECT";
	$mail->Body = emailContent($name);
	if(!$mail->Send()) {
	  return false;
	} else {
	  return true;
	}
}

function emailContent($name)
{
	$emailString = "&lt;html&gt;\n";
	$emailString .= "&lt;head&gt;\n";
	$emailString .= "&lt;meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /&gt;\n";
	$emailString .= "&lt;title&gt;Test email&lt;/title&gt;\n";
	$emailString .= "&lt;/head&gt;\n";
	$emailString .= "&lt;body&gt;\n";
	$emailString .= "&lt;table width=\"600\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"&gt;\n";
	$emailString .= "&lt;tr&gt;\n";
	$emailString .= "&lt;td width=\"100%\" height=\"30\" bgcolor=\"#003366\" align=\"center\"&gt;&lt;font face=\"Arial\" color=\"#FFFFFF\" style=\"font-size:15px; font-weight:bold;\"&gt;NEWSLETTER HEADER&lt;/font&gt;&lt;/td&gt;\n";
	$emailString .= "&lt;/tr&gt;\n";
	$emailString .= "&lt;tr&gt;\n";
	$emailString .= "&lt;td width=\"90%\" align=\"left\" style=\"padding:15px;\"&gt;&lt;font face=\"Arial\" style=\"font-size:12px;\"&gt;&lt;b&gt;Dear $name&lt;/b&gt;&lt;br /&gt;&lt;b&gt;CONGRATULATIONS!&lt;/b&gt; You have just been added to our email community...but not really.&lt;/font&gt;&lt;/td&gt;\n";
	$emailString .= "&lt;/tr&gt;\n";
	$emailString .= "&lt;tr&gt;\n";
	$emailString .= "&lt;td width=\"100%\" height=\"30\" bgcolor=\"#003366\" align=\"center\"&gt;&lt;font face=\"Arial\" color=\"#FFFFFF\" style=\"font-size:15px; font-weight:bold;\"&gt;NEWSLETTER FOOTER&lt;/font&gt;&lt;/td&gt;\n";
	$emailString .= "&lt;/tr&gt;\n";
	$emailString .= "&lt;/table&gt;\n";
	$emailString .= "&lt;/body&gt;\n";
	$emailString .= "&lt;/html&gt;";
	return $emailString;
}
</pre>
<h2>Step 18: Retrieving the Comments</h2>
<p>Open another blank PHP file. Save this one as &#8220;comments.php&#8221;. Here we use our &#8220;require.php&#8221; file again, then we perform a simple MySQL query. It selects all the values from the database. We take all the values returned and echo out the XML. First we&#8217;ll send the header, then echo out the beginning parts of the XML. After that, we go into a while loop. This will part will echo out all of our comments, email addresses, and names. When the while loop is over, we close the XML. This is what we will be loading back into Flash.</p>
<pre name="code" class="javascript">
&lt;?php
require_once("require.php");
$result = mysql_query("SELECT * FROM `comments`");
if($result)
{
	header ("Content-Type: text/xml");
	echo "&lt;?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
	echo "&lt;comments\n>";
	while ($row = mysql_fetch_array($result))
	{
		echo "&lt;comment\n>";
		echo "&lt;name>" . $row["name"] . "&lt;/name>\n";
		echo "&lt;email>" . $row["email"] . "&lt;/email>\n";
		echo "&lt;description>" . $row["comment"] . "&lt;/description>\n";
		echo "&lt;/comment\n>";
	}
	echo "&lt;/comments>";
}
?>
</pre>
<h2>Step 19: Back in Flash</h2>
<p>Here is the function that loads after the PHP has inserted our comments into the database. We set all the text fields back to their default states. Then we load the XML from the &#8220;comments.php&#8221; file.</p>
<pre name="code" class="javascript">
private function onComplete(event:Event):void
		{
			if(event != null)
			{
				nameField.text = "";
				emailField.text = "";
				commentField.text = "";
				onInput(null);
				newsletter.selected = false;
			}
			var url:URLLoader = new URLLoader();
			url.addEventListener(Event.COMPLETE, xmlLoaded);
			url.addEventListener(IOErrorEvent.IO_ERROR, onError);
			url.load(new URLRequest(URL+"/comments.php"));
		}
</pre>
<h2>Step 20: Parse the XML</h2>
<p>This is the function for when the XML is loaded. We take the XML from the database, sort through it in a loop, then add the objects to the list component. We then set the focus of the list to the last item in the loop, which is the last comment.</p>
<pre name="code" class="javascript">
private function xmlLoaded(event:Event):void
		{
			list.removeAll();
			var xml:XML = new XML(event.target.data);
			var listing:XMLList = xml..comment;
			var len:int = listing.length();
			for(var i:int; i&lt;len; i++)
			{
				var object:Object = listing[i];
				list.addItem({label:object.name, data:object});
			}
			list.addEventListener(Event.CHANGE, onChange);
			list.selectedIndex = len-1;
			area.htmlText = listing[len-1].description;
			list.scrollToIndex(len-1);
		}
</pre>
<h2>Step 21: Finishing up</h2>
<p>Finally, we get to the rest of the functions to make the application work correctly. Just in case there&#8217;s a server error, we listen for the &#8220;IOErrorEvent&#8221;. If the server is down, Flash will call a javascript alert using the &#8220;ExternalInterface&#8221; class. The &#8220;onChange&#8221; function is called everytime the user selects a different list item. It sets the text field below the list to the corresponding comment. The &#8220;onFocus&#8221; function simply turns the text field assigned to the &#8220;tf&#8221; variables back to black.</p>
<pre name="code" class="javascript">
private function onError(event:IOErrorEvent)
		{
			ExternalInterface.call("alert", "Server is unavailable");
		}
		private function onChange(event:Event):void
		{
			var object:Object = event.target.selectedItem.data;
			area.htmlText = object.description;
		}
        private function onFocus(event:FocusEvent):void
		{
			if(tf != null)
			{
				tf.textColor = 0x000000;
			}
		}
</pre>
<h2>Conclusion</h2>
<p>There are many different ways to make Flash, PHP, and MySQL work together. Once you get the hang of it, there&#8217;s no limit to what you can do. The Tuts+ sites have a plethora of useful information out there, so don&#8217;t forget to sign up for every one of their feeds. Thanks!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Flashtuts?a=vvIE_8ksKvQ:S6X_PPGzW2Q:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=vvIE_8ksKvQ:S6X_PPGzW2Q:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=vvIE_8ksKvQ:S6X_PPGzW2Q:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=vvIE_8ksKvQ:S6X_PPGzW2Q:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=vvIE_8ksKvQ:S6X_PPGzW2Q:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=vvIE_8ksKvQ:S6X_PPGzW2Q:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=vvIE_8ksKvQ:S6X_PPGzW2Q:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=vvIE_8ksKvQ:S6X_PPGzW2Q:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=vvIE_8ksKvQ:S6X_PPGzW2Q:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=vvIE_8ksKvQ:S6X_PPGzW2Q:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Flashtuts/~4/vvIE_8ksKvQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://active.tutsplus.com/tutorials/actionscript/create-a-comment-form-with-flash-php-xml-and-mysql/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		<feedburner:origLink>http://active.tutsplus.com/tutorials/actionscript/create-a-comment-form-with-flash-php-xml-and-mysql/</feedburner:origLink></item>
		<item>
		<title>Create an iPhone Inspired Switch CheckBox Using Flash and ActionScript 3.0</title>
		<link>http://feedproxy.google.com/~r/Flashtuts/~3/bloKbt1ejv0/</link>
		<comments>http://active.tutsplus.com/tutorials/actionscript/create-an-iphone-inspired-switch-checkbox-using-flash-and-actionscript-3-0/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 12:00:23 +0000</pubDate>
		<dc:creator>Carlos Yanez</dc:creator>
				<category><![CDATA[ActionScript]]></category>

		<guid isPermaLink="false">http://active.tutsplus.com/?p=2382</guid>
		<description><![CDATA[<img src="http://activetuts.s3.amazonaws.com/tuts/009_switch/Preview/Preview.jpg" alt="">]]></description>
			<content:encoded><![CDATA[<p>A CheckBox  is a graphical user interface element that permits the user to make one or multiple selections from a number of options.</p>
<p>In this tutorial, we&#8217;ll create a Switch checkbox inspired by the iPhone Graphical User Interface. Read on to find out how!</p>
<p><span id="more-2382"></span></p>
<div class="tutorial_image">
<a href="http://activetuts.s3.amazonaws.com/tuts/009_switch/Src.zip" target="_blank"><br />
<img src="http://activetuts.s3.amazonaws.com/assets/icons/source.jpg" alt="" style="border:none"></a><br />
<a href="http://activetuts.s3.amazonaws.com/tuts/009_switch/Src/preview.html" target="_blank"><br />
<img src="http://activetuts.s3.amazonaws.com/assets/icons/demo.jpg" alt="" style="border:none"></a>
</div>
<h2>Step 1: Brief Overview</h2>
<p>Using the Flash drawing tools we&#8217;ll create a vector Switch that will be controled by classes. One class will take care of all the Switch behavior and another class will simply check the value of the Switch. Let&#8217;s go!</p>
<h2>Step 2: Starting</h2>
<p>Open Flash and create a new Flash File (ActionScript 3).</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/009_switch/Tutorial/1.jpg" alt="" /></div>
<p>Set the stage size to  600&#215;300 and set the color to #EFEFF0.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/009_switch/Tutorial/2.jpg" alt=”” /></div>
<p>We&#8217;ll now create the Switch graphics.</p>
<h2>Step 3: Border</h2>
<p>Select the Primitive Rectangle Tool (R) and create a 280&#215;80 px rectangle, filling it with this linear gradient: #505052, #ACADB1.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/009_switch/Tutorial/3.jpg" alt="" /></div>
<p>Use the Gradient Transform Tool to rotate the gradient horizontally and change the corner radius (Properties Panel) to 10.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/009_switch/Tutorial/4.jpg" alt="" /></div>
<h2>Step 4: OFF Background</h2>
<p>We&#8217;ll draw two backgrounds for the Switch, the OFF background and the ON background.</p>
<p>Duplicate the previous shape and change its size to 276&#215;76 px. Change the linear grandient to #9A9A9A, #F4F3F6 and move the last color selector (Color Panel) to halfway along the bar.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/009_switch/Tutorial/5.jpg" alt="" /></div>
<p>Select the Text Tool (T) and create a Static TextField. Write &quot;OFF&quot; and place it at the right side of the background.</p>
<p>I used Helvetica Neue Bold, 48 pt, #8C8C8C.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/009_switch/Tutorial/6.jpg" alt="" /></div>
<h2>Step 5: Draggable Area</h2>
<p>Now we&#8217;ll  add a button that can be dragged to modify the Switch value.</p>
<p>Use the Rectangle Tool to create a 120&#215;80 px rectangle and fill it with #A19FA0, set the corner radius to 10.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/009_switch/Tutorial/7.jpg" alt="" /></div>
<p>Duplicate the shape and resize it to 116&#215;76 px, fill it with #FCFCFE.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/009_switch/Tutorial/8.jpg" alt="" /></div>
<p>To give the final touch to the button, repeat the process and fill the shape with a #D7D7D7, #FCFCFE linear gradient. Use the Gradient Transform Tool to rotate the fill.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/009_switch/Tutorial/9.jpg" alt="" /></div>
<h2>Step 6: ON Background</h2>
<p>Duplicate the border and the OFF background, delete the text and change the border gradient to #0D4372, #6193D2.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/009_switch/Tutorial/10.jpg" alt="" /></div>
<p>Next, change the background gradient to #0C68B5, #479FF9, #6DB0F6.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/009_switch/Tutorial/11.jpg" alt="" /></div>
<p>Place the button border shape in the right side.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/009_switch/Tutorial/12.jpg" alt="" /></div>
<p>Break Apart (Cmd+B) the shapes to cut them.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/009_switch/Tutorial/13.jpg" alt="" /></div>
<p>Use the same Text Format to add the &quot;ON&quot; text to the background.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/009_switch/Tutorial/14.jpg" alt="" /></div>
<h2>Step 7: Setting the MovieClips</h2>
<p>Convert the Draggable Button to MovieClip and name it &quot;area&quot;. As you can imagine this will be the area that will be dragged to change the Switch value.</p>
<p>Make sure the Registration point is positioned like the one in the images.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/009_switch/Tutorial/15.jpg" alt="" /></div>
<p>Select all shapes including the MovieClip and convert them again, name the result &quot;slider&quot;.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/009_switch/Tutorial/16.jpg" alt="" /></div>
<p>Use any of the border shapes to create another MovieClip, this will be the Mask that will hide part of the graphics. Name it &quot;msk&quot;.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/009_switch/Tutorial/17.jpg" alt="" /></div>
<p>Convert everything to MovieClip once again and double-click it.</p>
<p>Create a new Layer then cut and paste the mask clip on it. Right-click the mask layer and select the &quot;Mask&quot; option.</p>
<p>This will finish all the graphics. Now your Switch should look like this (note the Registration point):</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/009_switch/Tutorial/18.jpg" alt="" /></div>
<h2>Step 8: Linkage</h2>
<p>Open the Library and right-click your Switch symbol. Select Properties, mark the &quot;Export for ActionScript&quot; box and write &quot;Switch&quot; as the class name.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/009_switch/Tutorial/19.jpg" alt="" /></div>
<h2>Step 9: Switch.as</h2>
<p>Create a new ActionScript document and save it as &quot;Switch.as&quot;.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/009_switch/Tutorial/20.jpg" alt="" /></div>
<h2>Step 10: Necessary Classes</h2>
<p>Import the required classes. If you need specific help for any of these, please refer to the Flash Help (F1).</p>
<pre name="code" class="javascript">
package
{
	import fl.transitions.Tween;
	import fl.transitions.easing.Strong;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;</pre>
<h2>Step 11: Variables</h2>
<p>These are the variables we&#8217;ll use, explained in the code commentary.</p>
<pre name="code" class="javascript">
public class Switch extends Sprite
{
	private var tween:Tween; //A Tween object for animation
	public var stat:Boolean = false; // This is a Public variable, it's used to know the Switch value outside this class</pre>
<h2>Step 12: Constructor Function</h2>
<p>The Constructor function. This function adds the listeners.</p>
<pre name="code" class="javascript">
public function Switch():void
{
	slider.area.addEventListener(MouseEvent.MOUSE_DOWN, switchDrag);
	slider.area.addEventListener(MouseEvent.MOUSE_UP, checkPosition);
}</pre>
<h2>Step 13: Drag function</h2>
<p>This function handles the button dragging, based on its position.</p>
<pre name="code" class="javascript">
private function switchDrag(e:MouseEvent):void
{
	if (! stat) //If Switch is OFF, we can drag to the right
	{
		e.target.parent.startDrag(true, new Rectangle(0, 0, e.target.parent.parent.msk.width/1.75, 0));
	}
	else
	{
		e.target.parent.startDrag(true, new Rectangle(e.target.parent.parent.msk.width/1.75, 0, -e.target.parent.parent.msk.width/1.75, 0));
	}
}</pre>
<h2>Step 14: Check Function</h2>
<p>This code checks the position of the draggable button. Depending on its value it returns to the original position or stays in the new one.</p>
<pre name="code" class="javascript">
private function checkPosition(e:MouseEvent):void
{
	e.target.parent.stopDrag();

	if (e.target.parent.x >= 140)
	{
		e.target.parent.x = 160;
		stat = true;
	}
	else if (!stat &#038;&#038; e.target.parent.x < 140)
	{
		tween = new Tween(e.target.parent,"x",Strong.easeOut,e.target.parent.x,0,1,true);
		stat = false;
	}

	// OFF to ON

	if (e.target.parent.x <= 20)
	{
		e.target.parent.x = 0;
		stat = false;
	}
	else if (stat &#038;&#038; e.target.parent.x > 20)
	{
		tween = new Tween(e.target.parent,"x",Strong.easeOut,e.target.parent.x,160,1,true);
		stat = true;
	}
}</pre>
<h2>Step 15: Main Class</h2>
<p>This is an example of how to use your new Switch.</p>
<p>Create a new ActionScript document and save it as &quot;Main.as&quot;.</p>
<pre name="code" class="javascript">
package
{
	import Switch; //Import the class
	import flash.display.Sprite;
	import flash.events.MouseEvent;

	public class Main extends Sprite
	{
		public function Main():void
		{
			iSwitch.addEventListener(MouseEvent.MOUSE_UP, checkState);//iSwitch is an instance in the stage of the Switch class
		}

		private function checkState(e:MouseEvent):void
		{
			if(iSwitch.stat)
			{
				trace(&quot;Switch is ON!&quot;);
			}
			else
			{
				trace(&quot;Switch is OFF!&quot;);
			}
		}
	}
}</pre>
<h2>Step 16: Document Class</h2>
<p>Go back to the .Fla file and in the Properties Panel add &quot;Main&quot; in the Class field to make this the Document Class.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/009_switch/Tutorial/21.jpg" alt="" /></div>
<h2>Conclusion</h2>
<p>You have created a fully customizable Switch to use in your applications! Remember that you can create your own skins and add plenty more functionality to the ON and OFF states.</p>
<p>Thanks for reading!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Flashtuts?a=bloKbt1ejv0:-VpKZUN1xOs:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=bloKbt1ejv0:-VpKZUN1xOs:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=bloKbt1ejv0:-VpKZUN1xOs:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=bloKbt1ejv0:-VpKZUN1xOs:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=bloKbt1ejv0:-VpKZUN1xOs:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=bloKbt1ejv0:-VpKZUN1xOs:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=bloKbt1ejv0:-VpKZUN1xOs:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=bloKbt1ejv0:-VpKZUN1xOs:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=bloKbt1ejv0:-VpKZUN1xOs:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=bloKbt1ejv0:-VpKZUN1xOs:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Flashtuts/~4/bloKbt1ejv0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://active.tutsplus.com/tutorials/actionscript/create-an-iphone-inspired-switch-checkbox-using-flash-and-actionscript-3-0/feed/</wfw:commentRss>
		<slash:comments>30</slash:comments>
		<feedburner:origLink>http://active.tutsplus.com/tutorials/actionscript/create-an-iphone-inspired-switch-checkbox-using-flash-and-actionscript-3-0/</feedburner:origLink></item>
		<item>
		<title>Winner announced: Win $50 + $50 by Checking Out ActiveDen</title>
		<link>http://feedproxy.google.com/~r/Flashtuts/~3/0qPywDFiKVE/</link>
		<comments>http://active.tutsplus.com/articles/competitions-and-giveaways/win-50-50-by-checking-out-activeden/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 10:00:00 +0000</pubDate>
		<dc:creator>Skellie</dc:creator>
				<category><![CDATA[Competitions and Giveaways]]></category>

		<guid isPermaLink="false">http://active.tutsplus.com/?p=2370</guid>
		<description><![CDATA[<img src="http://activetuts.s3.amazonaws.com/articles/active_prev.jpg">]]></description>
			<content:encoded><![CDATA[<p>In this week&#8217;s comment to win giveaway you can enter for your chance to win a neat 50-50 prize&#8230; <strong>$50 USD</strong> and <strong>$50 marketplace credit</strong>. And you can do it simply by leaving your <a href="http://activeden.net">ActiveDen</a> username in a comment on this post. One random commenter will be selected to win the prize, so you have just as much chance as anyone else to win. If you don&#8217;t have an account, you can quickly sign-up for free <a href="http://activeden.net/">on the site</a>.</p>
<p><strong>ActiveDen</strong> is a marketplace where Flash and Flex developers of all kinds can set up shop for free and start selling files they&#8217;ve created. It was created by <a href="http://envato.com">Envato</a>, the makers of Activetuts+. Read on to learn more about how you can make passive income on ActiveDen, and to learn more about the giveaway.</p>
<p><span id="more-2370"></span></p>
<h4>Winner announced!</h4>
<p>Congratulations goes to <strong>kesjeff</strong> who wins $50 USD and $50 marketplace credit! If you weren&#8217;t so lucky this time, don&#8217;t worry, there&#8217;ll be plenty of other giveaways across the tuts+ sites very soon.</p>
<h3>Read a Testimonial from an ActiveDen User:</h3>
<p>DigitalScience, a top-seller on <a href="http://activeden.net">ActiveDen</a>, earned his previous full year&#8217;s salary in one month working from home and selling his stock Flash files on the site:</p>
<blockquote><p>&#8220;After uploading a few $20 files then I started making more than 3 times my current salary on ActiveDen and thought, well why do I actually need this day job when I can chill at home and make more on ActiveDen. So around that time, I bought a Golf 5 GTI , handed in my resignation letter and said cheers to the working world and started working as a full time ActiveDen Author from home. Got to a point when I was making my full years salary in one month on ActiveDen which is madness!!&#8221; &#8211; DigitalScience [<a href="http://themeforest.net/forums/thread/envato-testimonials/17640?page=3#162359">Read the full testimonial</a>]</p></blockquote>
<p>Could you achieve the same feat?</p>
<p>Here are some suggestions for ways you could use your account:</p>
<h4>Make Once, Sell Many Times</h4>
<p>You can use your <a href="http://activeden.net">ActiveDen</a> account to sell the Flash files you make. After they go up on the site, they&#8217;ll stay there for years to come. If they&#8217;re good, you&#8217;ll make more sales every month &#8211; meaning <strong>your work keeps earning money even when you&#8217;ve moved on to something else</strong>. You could be gathering money in your account on autopilot &#8211; while you sleep, are watching TV, or driving to work. Some users earn the equivalent to a full-time income selling their files on ActiveDen.</p>
<p>The best thing about it is that rather than hunting for clients and sacrificing some of your freedom to do the work other people want you to do, ActiveDen allows you to earn money making whatever you want and on your own schedule.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/articles/activeden.jpg" alt="Marketplace Logos" /></div>
<p><br/></p>
<h4>Buy Affordable Stock for Your Projects</h4>
<p>Most of the people who buy files from <a href="http://activeden.net">ActiveDen</a> are other web designers and developers like you, looking for a pre-built image gallery or web design that would have taken them hours to make on their own. Using high-quality stock files can greatly speed up your workflow, so even if you don&#8217;t take the opportunity to become an ActiveDen seller, you&#8217;ll be excited to see all the cool Flash files for sale.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/articles/buyactiveden.jpg" alt="ActiveDen Files" /></div>
<p></p>
<p><!--<br />
<h4>How to Win</h4>
<p>If you have an account, just leave a comment on this post with your account name. If you don&#8217;t have an account yet, you can quickly sign-up for a free account <a href="http://activeden.net/">on the site</a>.</p>
<p>Entries are open worldwide and the winning comment will be chosen through <a href="http://random.org">random.org</a>. Make sure you include your correct email address with your comment so that we can contact you. This giveaway is open worldwide, but make sure to get your comment in before <strong>midnight this Friday, Pacific Eastern Standard Time</strong>.</p>
<p>If your comment is drawn, we&#8217;ll email you directly, at which point you&#8217;ll have seven days to claim. Failure to respond within that time will result in a re-draw.</p>
<p><em>
<p>Please note: Envato staff and people who have written more than two tutorials/articles for a Tuts+ site are not eligible to enter.</p>
<p></em>&#8211;></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Flashtuts?a=0qPywDFiKVE:R3in_zZjjes:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=0qPywDFiKVE:R3in_zZjjes:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=0qPywDFiKVE:R3in_zZjjes:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=0qPywDFiKVE:R3in_zZjjes:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=0qPywDFiKVE:R3in_zZjjes:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=0qPywDFiKVE:R3in_zZjjes:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=0qPywDFiKVE:R3in_zZjjes:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=0qPywDFiKVE:R3in_zZjjes:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=0qPywDFiKVE:R3in_zZjjes:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=0qPywDFiKVE:R3in_zZjjes:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Flashtuts/~4/0qPywDFiKVE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://active.tutsplus.com/articles/competitions-and-giveaways/win-50-50-by-checking-out-activeden/feed/</wfw:commentRss>
		<slash:comments>159</slash:comments>
		<feedburner:origLink>http://active.tutsplus.com/articles/competitions-and-giveaways/win-50-50-by-checking-out-activeden/</feedburner:origLink></item>
		<item>
		<title>Introduction to the HYPE ActionScript 3.0 Framework</title>
		<link>http://feedproxy.google.com/~r/Flashtuts/~3/9WGbzTNT6Ho/</link>
		<comments>http://active.tutsplus.com/tutorials/workflow/introduction-to-the-hype-actionscript-3-0-framework/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 12:00:29 +0000</pubDate>
		<dc:creator>Tom Green</dc:creator>
				<category><![CDATA[Workflow]]></category>

		<guid isPermaLink="false">http://active.tutsplus.com/?p=2459</guid>
		<description><![CDATA[<img src="http://activetuts.s3.amazonaws.com/tuts/016_hype/preview.jpg" alt="">]]></description>
			<content:encoded><![CDATA[<p>In this tutorial I&#8217;m going to introduce you to <a href="http://hype.joshuadavis.com/" target="_blank">HYPE</a>, an ActionScript 3 framework released by Joshua Davis and Branden Hall on October 31, 2009.</p>
<p>The purpose of this introduction is not to get into the intricacies of the framework, but to walk you through a rather simple exercise designed to demonstrate some of the possibilities this Open Source project offers you.</p>
<p><span id="more-2459"></span></p>
<div class="tutorial_image">
<a href="http://activetuts.s3.amazonaws.com/tuts/016_hype/src.zip" target="_blank"><br />
<img src="http://activetuts.s3.amazonaws.com/assets/icons/source.jpg" alt="" style="border:none"></a><br />
<a href="http://activetuts.s3.amazonaws.com/tuts/016_hype/HYPETriangles_03.html" target="_blank"><br />
<img src="http://activetuts.s3.amazonaws.com/assets/icons/demo.jpg" alt="" style="border:none"></a>
</div>
<h2>Overview:</h2>
<p>As many of you may have guessed I am not a hard core coder.</p>
<p>The reason, as I will tell anybody who listens, is that &#8220;coding is not hard wired into my genes&#8221;. Give me a blank ActionScript panel in Flash and I&#8217;ll stare at it for hours. What makes this odd is I can read the code when it is given to me. Think of me as being the kind of guy who will sit in a café in France reading a French book but can’t speak the language.</p>
<p>I need to tell you this now because it&#8217;s important you know how I approached the exercise. Also, I want you to clearly understand that even though I have known Josh and Branden for quite a few years, I am not even close to being in their league or part of their &#8220;hype machine&#8221;. I&#8217;m just a guy, like you, who stumbled across something that made my life easier. As a teacher, I&#8217;ve been handed a tool that lets me teach AS3 basics in a manner that gives &#8220;Visual Learners&#8221; immediate feedback.</p>
<p>The thing is, I <em>get</em> that code, like the Flash IDE is a &#8220;creative medium&#8221;. The stuff that happens when artists and designers get hold of code is awesome to behold. Yet talk to people that are coming into Flash or have discovered they need to know AS3 to expand their creative possibilities and you will hear, &#8220;Man, this stuff is hard&#8221;. At that point, frustration takes hold and, as they say, &#8220;Now you know the rest of the story &#8230;&#8221;</p>
<p>This brings me to Josh and Branden. They hear the same story from the people they meet in their travels. The thing is, Josh was once in their shoes and what sets him apart from the rest of the pack is that he mastered the fundamentals of code while, at the same time, bringing his awesome Fine Arts talents to his work. He didn’t do it alone. </p>
<p>Branden and Josh first became deeply involved with each other at FlashForward 2000 when they were both relatively unknown and, since then, a deep and profound professional relationship has developed between them. Over the years, Josh has come up with ideas, Branden has wired them up and then Josh rearranged the wiring to take the work to levels neither expected 10 years ago.</p>
<p>What has always struck me, if you have ever seen them at a conference or presentation, is their infectious sense of &#8220;wonder&#8221; and &#8220;fun&#8221; when it comes to their collaborations or solo efforts. </p>
<p>With the introduction of ActionScript 3, both Josh and Branden quickly realized &#8220;wonder&#8221; and &#8220;fun&#8221; were two words that were  disappearing from the Flash community. Creatives avoided code as a creative medium because the language was perceived, among this group, as too complicated or complex to master. The ability to play what I call &#8220;What if&#8230;&#8221; games became too risky because the odds of breaking the project were almost 100% unless you had a deep understanding of OOP. </p>
<p>In many respects, this explains the rise of the &#8220;Developer&#8221; in the Flash community over the past few years. I am not saying this is a bad thing or &#8220;dissing&#8221; the developers. It is just that because of the complexity of the language the critical balance of the  Designer/Developer partnership became more weighted toward the Developer. Branden and Josh, rather than talk about it, decided to do something about it. </p>
<p>What many people don’t know is the genesis for HYPE was another project, Flow, which essentially tried to make things easier for designers but it fell flat on its face simply because it was too ahead of itself. Rather than give up, Branden retooled Flow and with Josh&#8217;s input it evolved into HYPE.</p>
<p>What has me jacked about the HYPE project is that the words  &#8220;wonder&#8221; and &#8220;fun&#8221; will come back if the creative community gets behind it. As you&#8217;re about to discover, you really don’t need a degree in Rocket Science to get hooked by HYPE. All you need is to be unafraid to to play with numbers and values.</p>
<h2>Step 1 : Download <a href="http://hype.joshuadavis.com/" target="_blank">HYPE.</a></h2>
<p>Be aware that Branden and Josh suggest you have Flash Professional CS4 installed before starting, even though this product will work with CS3.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/016_hype/1.jpg" width="269" height="157"/></div>
<h2>Step 2: Extension Manager</h2>
<p>Unzip the download and double-click the .mxp file to launch the Extension Manager. The Extension Manager will install everything into their ultimate destinations. If you&#8217;re curious, explore the HYPE folder- hype_01 &#8211;  that you have just unzipped. Inside you will find:</p>
<ul>
<li>All the help files inside the <em><strong>doc</strong></em> folder.</li>
<li>Examples of the various HYPE classes, including their corresponding source fla files in the <em><strong>examples</strong></em> folder.</li>
<li>The HYPE classes, found in the <em><strong>src</strong></em> folder.</li>
</ul>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/016_hype/2.jpg" width="529" height="241"/></div>
<h2>Step 3. Launch Flash</h2>
<p>Double-click the <em>Setup Classpath.jsfl</em> to launch Flash. All this step does is let Flash know where everything was placed during the install.</p>
<p>That’s it folks. Now it&#8217;s time to play.</p>
<h2>Getting Caught in the HYPE</h2>
<p>The idea for this exercise actually appeared in a tweet sent by Branden a week or so before the HYPE release. He said Josh was having too much fun playing with the SoundAnalyzer in HYPE and posted <a href="http://hype.joshuadavis.com/02_examples/soundanalyzer/02_soundanalyzer" target="_blank">this link</a>.</p>
<p>The tweet caught my attention because one of the things I love to show is Audio Visualization in Flash. I use it as an example of being fearless around code rather than a full bore ActionScript lesson.. I use myself as the poster child for this and show how, by playing with numbers and changing things I know, the complex can become interesting. I start with a basic visualization and then progress to a full bore light show.</p>
<p>Even though I make it interesting and fun, if I were to get into the nitty-gritty of working with the SoundMixer class and Byte Arrays, I may as well toss a wad of aluminum foil over to the shiny thing the audience is now staring at. They will have dialed out because I&#8217;m going way, way over their heads. When I saw Josh’s example I immediately pawed through the code looking for what wasn’t there; the complexity.</p>
<p>Let’s bring the fun back to playing with audio in Flash:</p>
<h2>Step 4: New Document</h2>
<p>Open a new Flash ActionScript 3.0 document. To get yourself started grab an mp3 audio file. This example uses &#8220;Busted Chump&#8221;, an ActiveDen demo track, but any audio file from your collection will do.</p>
<h2>Step 5: Triangle</h2>
<p>Draw a small filled triangle on the stage and convert it to a movieclip named &#8220;Triangle&#8221;. Once you&#8217;ve drawn the triangle and converted it to a movieclip, delete the movieclip from the stage.</p>
<h2>Step 6: Symbol Properties</h2>
<p>Right-click on the symbol in the Library and open the Symbol Properties. Select Export for Actionscript. Your symbol name will appear as the class. Click OK and disregard the error message that appears.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/016_hype/3.jpg" width="575" height="183"/></div>
<p>As you may have guessed, HYPE is going to pull the symbol out of the Library and allow you to play with it using ActionScript. For those of you recoiling from this, keep in mind that at its heart HYPE is a playground that gives creatives the opportunities to play &#8220;What if &#8230;&#8221; games and see the results with very little effort. In the case of this exercise I am going to play three &#8220;What if &#8230;&#8221; games:</p>
<ol>
<li>What if I put the triangles on a grid?</li>
<li>What if those triangles on the grid pulsated to the music?</li>
<li>What if those pulsating triangles were put into motion?</li>
</ol>
<h2>Step 7: ActionScript</h2>
<p>Enter the following ActionScript:</p>
<pre name="code" class="javascript">
import hype.extended.layout.GridLayout;

var numItems:int = 80;

var gridLayout:GridLayout = new GridLayout(30,30, 70, 50, 10);

  for (var i:uint = 1; i &lt; numItems; ++i) {
  var clip:Triangle = new Triangle();
  gridLayout.applyLayout(clip);
  addChild(clip);
  };
</pre>
<p>The first &#8220;What if &#8221; game involves placing the movieclip in a grid and, to paraphrase Apple, &#8220;there is a class for that&#8221;. In fact, in HYPE there is a class for practically everything you will want to do. If there isn’t, write one because HYPE is Open Source.</p>
<p>The next line tells Flash you want to put 80 triangles on the stage. Having done that, you now determine how they will appear on the grid by adding the parameters into the GridLayout object. In this case I want the grid to start 30 pixels in from the left of the stage and 30 pixels from the top of the stage. Also, there is to be 70 pixels of space between the triangles on the x axis and 50 pixels of space between the rows. The final parameter tells HYPE that I want to see what happens if there are 10 columns of triangles.</p>
<p>The &#8220;for&#8221; loop tells HYPE how to place the 80 triangles on the stage. You grab the movieclip out of the library, give it an instance name, then by using the applyLayout() method of the Gridlayout class, lay the objects into the grid using the parameters of the GridLayout object.</p>
<h2>Step 8: Test</h2>
<p>Save and test the movie.</p>
<p>That was easy and if I want to change up the look all I need to do is to play with the values in the <em>numItem</em> variable and the <em>parameters</em> in the GridLayout object. Don’t like the triangle? Then toss something else &#8211; an image, for example &#8211; into the movieclip or create a completely different movieclip and use that instead.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/016_hype/4.jpg" width="551" height="419"/></div>
<p></p>
<h4>What if the triangles were tied to an audio track?</h4>
<p>The triangles are on a grid and it is now time for our next &#8220;What if &#8230;&#8221; game. In this case : What if the alpha and scale values of the triangles were tied to an audio track? At this point, many creatives would be, as I said earlier, looking at the &#8220;shiny thing&#8221; over there. Just keep in mind the whole purpose of HYPE is to let you play, not become a hard-core coder. Let’s have some fun:</p>
<h2>Step 9: Import Classes</h2>
<p>Click into line 2 of the Script and add the following code:</p>
<pre name="code" class="javascript">
import hype.extended.behavior.FunctionTracker;
import hype.framework.sound.SoundAnalyzer;
</pre>
<p>These two classes work together in HYPE. FunctionTracker, in very simple terms, manages the functions that are running and makes sure they are mapped to the specific properties of the target object. In our case, we are going to play with the alpha and scale properties of the triangle as it reacts to the audio track.</p>
<p>The SoundAnalyzer class is where the magic happens. What it does, again in very simple terms, is to turn an audio file into data which can then be played with. What I absolutely adore about this class is I don’t have to write a ton of very complex code to get immediate results. I just need to know what the parameters do and then start playing.</p>
<h2>Step 10: SoundAnalyzer Object</h2>
<p>Add the following two lines of code after the import statements:</p>
<pre name="code" class="javascript">
var soundAnalyzer:SoundAnalyzer = new SoundAnalyzer();
soundAnalyzer.start();
</pre>
<p>All these two lines do is to create the SoundAnalyzer object and switch it on using the start() method (which is how you turn these classes on and off in HYPE). Think of the start() method as nothing more than a light switch.</p>
<h2>Step 11: Octaves</h2>
<p>Add the following code under the &#8220;applyLayout&#8221; method in the &#8220;for&#8221; loop:</p>
<pre name="code" class="javascript">
  var ranNum:Number = int(Math.random() *7);
  var alphaTracker:FunctionTracker = new FunctionTracker(clip, &quot;alpha&quot;, soundAnalyzer.getOctave, [ranNum, 0.01, 1]);
  var scaleTracker:FunctionTracker = new FunctionTracker(clip, &quot;scale&quot;, soundAnalyzer.getOctave, [ranNum, 0.5, 4]);

  alphaTracker.start();
  scaleTracker.start();
</pre>
<p>The key to the visualization is the first three lines of the code block.</p>
<p>The SoundAnalyzer class uses the audio track’s octaves; the values for octaves range from 0 to 7. The first line, therefore, creates a random number based on the maximum octave value allowed. Keep this in mind when playing with this value. Numbers greater than 7 will be rounded down to 7.</p>
<p>The next two lines use the functionTracker class to play with the triangles in the grid. You target the object, tell FunctionTracker which property of the object you want to play with, which function is to be run (<em><strong>getOctave</strong></em>) and which values to use.</p>
<p>In this case we&#8217;re going to play with the random octave values- <em>ranNum</em> &#8211; and make sure the alpha values range from 1% to 100% alpha based on the &#8220;size&#8221; of the octave in the audio track. Small numbers mean low alpha, big numbers mean full alpha. Also note that these values must be passed as an Array and that the properties being changed are String values.</p>
<p>The final two lines switch on the functions.</p>
<h2>Step 12: Sound</h2>
<p>Add the following ActionScript to the end of the code block:</p>
<pre name="code" class="javascript">
  	var sound:Sound = new Sound();
  	sound.load(new URLRequest(&quot;YourAudioTrackGoesHere.mp3&quot;));
	sound.play();
</pre>
<h2>Step 13: Test</h2>
<p>Save and test the movie.</p>
<div class="tutorial_image">
<a href="http://activetuts.s3.amazonaws.com/tuts/016_hype/HYPETriangles_01.html" target="_blank"><br />
<img src="http://activetuts.s3.amazonaws.com/assets/icons/milestone.jpg" alt="" style="border:none"></a>
</div>
<p></p>
<h4>What if those pulsating triangles were put in motion?</h4>
<p>As you have discovered, this stuff is not hard and, in fact, by simply playing with numbers, you can have a huge amount of fun as you &#8220;tweak up&#8221; how those triangles pulsate and fade. Now that we have that working, let’s play our final &#8220;What if &#8230;&#8221; game and put them in motion. Here’s how:</p>
<h2>Step 14: One More Class</h2>
<p>Click once at the end of the class list and add one more class:</p>
<pre name="code" class="javascript">
import hype.extended.behavior. Oscillator;
</pre>
<p>This class is an absolute blast to play with because it puts an object on an oscillating wave. Here’s the best part: You don’t need a trigonometry background to do it. In fact, there is no math involved. </p>
<h2>Step 15: Define Boundaries</h2>
<p>Add the following ActionScript  below the import statements:</p>
<pre name="code" class="javascript">
  var myWidth = stage.stageWidth;
  var myHeight = stage.stageHeight;
  var freq:int= 20;
</pre>
<p>All this code does is confine the resulting animation to the boundaries of the stage and to set a value for the wave frequency. It is time to play with the grid.</p>
<h2>Step 16: Oscillator Object</h2>
<p>Add the following code after the &#8220;scaleTracker&#8221; variable in the &#8220;for&#8221; loop:</p>
<pre name="code" class="javascript">
  var ypositionOsc:Oscillator = new Oscillator (clip,&quot;y&quot;, Oscillator.sineWave, freq, clip.y, myHeight/3, i/(freq/2));
  var scaleOsc:Oscillator = new Oscillator (clip, &quot;scaleY&quot;, Oscillator.sineWave, freq, 5,50, i/(freq/2));
  var rotateOsc:Oscillator = new Oscillator (clip,&quot;rotation&quot;, Oscillator.sineWave, freq, 0,90, i/(freq/2));

  yOsc.start();
  sOsc.start();
  rOsc.start();
</pre>
<p>Again, the Oscillator object, like the FunctionTracker object, doesn’t require a degree in particle physics. The parameters are really simple: </p>
<ul>
<li>Which object is going to oscillate? </li>
<li>Which property- a string-  of the object is going to be affected?</li>
<li>Which wave is to be applied? Your choices are sineWave, sawWave,squareWave and triangleWave.</li>
<li>What is the wave frequency?</li>
<li>What is the minimum wave value?</li>
<li>What is the maximum wave value?</li>
<li>What wave value do we use to start?</li>
</ul>
<p>In this case we are applying a sineWave to three properties &#8211; y position, yScale and rotation- of the triangle and then using the remaining three parameters to set the look of the wave’s motion.</p>
<p>The remaining three lines switch  the Oscillator on.  The values I used simply popped out of &#8220;I wonder what the animation would look like if I used these numbers?&#8221; Nothing more.</p>
<h2>Step 17: Test</h2>
<p>Save and test the animation.</p>
<div class="tutorial_image">
<a href="http://activetuts.s3.amazonaws.com/tuts/016_hype/HYPETriangles_03.html" target="_blank"><br />
<img src="http://activetuts.s3.amazonaws.com/assets/icons/demo.jpg" alt="" style="border:none"></a>
</div>
<h2>Conclusion:</h2>
<p>This exercise was designed to introduce you to the HYPE framework and give you a chance to kick the tires. I showed you how to install it and then used three &#8220;What if &#8230; &#8221; scenarios that took a simple triangle and heaved it onto a pulsating and waving grid that was driven by an audio track. In regular ActionScript coding those tasks, to many, would be a reason to &#8220;Flee. Screaming. Into the night&#8221;. </p>
<p>Instead, you discovered that HYPE is aimed at dialing down the developer side of the Flash equation while bringing the fun back to the designer side. Having completed this exercise it might not be a bad idea to revisit the code with a different point of view. What would that be? In many respects, using HYPE to work out ideas very much follows the creative process. It doesn’t get you bogged down in code but instead, by playing with numbers and values, you get to do what you do best: play ‘What If &#8230;’ games.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Flashtuts?a=9WGbzTNT6Ho:PequLOHWIF8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=9WGbzTNT6Ho:PequLOHWIF8:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=9WGbzTNT6Ho:PequLOHWIF8:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=9WGbzTNT6Ho:PequLOHWIF8:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=9WGbzTNT6Ho:PequLOHWIF8:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=9WGbzTNT6Ho:PequLOHWIF8:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=9WGbzTNT6Ho:PequLOHWIF8:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=9WGbzTNT6Ho:PequLOHWIF8:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=9WGbzTNT6Ho:PequLOHWIF8:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=9WGbzTNT6Ho:PequLOHWIF8:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Flashtuts/~4/9WGbzTNT6Ho" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://active.tutsplus.com/tutorials/workflow/introduction-to-the-hype-actionscript-3-0-framework/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		<feedburner:origLink>http://active.tutsplus.com/tutorials/workflow/introduction-to-the-hype-actionscript-3-0-framework/</feedburner:origLink></item>
		<item>
		<title>Code a Chaotic Composition Inspired by Joshua Davis</title>
		<link>http://feedproxy.google.com/~r/Flashtuts/~3/IUwFagSMe-4/</link>
		<comments>http://active.tutsplus.com/tutorials/actionscript/code-a-chaotic-composition-inspired-by-joshua-davis/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 10:00:07 +0000</pubDate>
		<dc:creator>Bruno Crociquia</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Design]]></category>

		<guid isPermaLink="false">http://active.tutsplus.com/?p=2392</guid>
		<description><![CDATA[<img src="http://activetuts.s3.amazonaws.com/tuts/011_codedChaos/preview/codedchaos.jpg" alt="">]]></description>
			<content:encoded><![CDATA[<p>Ever wondered how design guru <a href="http://www.joshuadavis.com/" target="_blank">Joshua Davis</a> makes those choatic images? I did. With his art as inspiration I grabbed a cup of coffee and set out to mimic his style.  This tutorial is aimed at designers and flash beginners, and documents my process of achieving something similar to Joshua&#8217;s early compositions.</p>
<p><span id="more-2392"></span></p>
<div class="tutorial_image">
<a href="http://activetuts.s3.amazonaws.com/tuts/011_codedChaos/flasources.zip" target="_blank"><br />
<img src="http://activetuts.s3.amazonaws.com/assets/icons/source.jpg" alt="" style="border:none"></a>
</div>
<h3>Final Result Preview</h3>
<p>Let&#8217;s take a look at the final result we will be working towards:</p>
<div class="tutorial_image">
<object width="550" height="484" data="http://activetuts.s3.amazonaws.com/tuts/011_codedChaos/tutorial/codedchaos.swf" type="application/x-shockwave-flash"><param name="src" value="http://activetuts.s3.amazonaws.com/tuts/011_codedChaos/tutorial/codedchaos.swf" /></object>
</div>
<p>Want to take <em>another</em> look at the final result we will be working towards? Click the flash movie (to make sure it&#8217;s in focus) and press any key to watch chaos at work! </p>
<h2>Step 1: Create the Project</h2>
<p>Create a new ActionScript 3 file.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/011_codedChaos/tutorial/1.jpg" alt="" /></div>
<p>You are quite free to change the settings as you like, I left mine as default and just changed the background color to black.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/011_codedChaos/tutorial/2.jpg" alt="" /></div>
<h2>Step 2: Preparing Your Composition Objects</h2>
<p>Open your library (if it isn&#8217;t displayed you can &quot;crtl+l&quot;) right-click the empty list and select &quot;New Symbol&quot;.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/011_codedChaos/tutorial/3.jpg" alt="" /></div>
<p>We&#8217;re going add a movieclip containing the shapes that we want to appear in the final composition. We&#8217;ll need to be able to instatiate it from the library; we achieve this by saying the symbol we just created is a class of its own that extends a movieclip class.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/011_codedChaos/tutorial/4.jpg" alt="" /></div>
<p>By doing this we can create a new set of objects by simply writing <em>var object = new Objects();</em></p>
<h2>Step 3: Designing the Shapes</h2>
<p>When you create a new symbol using this method Flash will automatically open it on the stage for you to edit. Let your creativity flow and add a bunch of shapes, each in its own keyframe. Here are a few of mine:</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/011_codedChaos/tutorial/5.jpg" alt="" /></div>
<p>Don&#8217;t worry about the colors, we&#8217;ll randomize them through a palette which we&#8217;ll define later on when coding.</p>
<h2>Step 4: Setting up Your Composition</h2>
<p>It&#8217;s now time to set the code.  Go to your main timeline (which should currently be blank with just one empty keyframe) and open up your actions panel (or use F9 as shortcut).</p>
<pre name="code" class="javascript">
//composition settings;
var count:Number = 100 // this is the amount of shapes we will be adding to our composition
var maxscale:Number=10 // this is the maximum scale value that our shapes will be allowed to achieve
var minscale:Number=1 // this is the minimum scale value that our shapes will be allowed to achieve
var maxrotation:Number = 180 // maximum rotation value for our shapes
var offsetX:Number = 100 // the offset is the value that will trigger the discrepancy of your composition
var offsetY:Number = 100 //
var marginX:Number = 100 // this is the margin for the x axis
var marginY:Number = 100 // this is the margin for the y axix
</pre>
<h2>Step 5: Finding a Color Palette</h2>
<p>We still need to add color to our composition. I do this, not by trying to figure out a palette good enough to use, but by using a palette that I <em>know</em> is good enough. I use kuler.</p>
<p>Go to <a href="http://kuler.adobe.com" target="_blank">kuler.adobe.com</a> and download the latest air version of the kuler air application.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/011_codedChaos/tutorial/6.jpg" alt="" /></div>
<p>What this will let you do (besides searching for palettes you like) is copy the hexadecimal colors as separated comma values, by just clicking this button:</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/011_codedChaos/tutorial/7.jpg" alt="" /></div>
<h2>Step 6: Adding Color to Your Composition</h2>
<p>Go back to your Flash file, open your ActionScript panel and add this line of code:</p>
<pre name="code" class="javascript">
var colorPalete:Array = []
</pre>
<p>Inside this array you can add the clipboarded values that you took from kuler&#8217;s air app.</p>
<pre name="code" class="javascript">
var colorPalete:Array = [191919,182828,60702D,AAB232,E6FA87]
</pre>
<p>Don&#8217;t forget to edit them so you end up with real hexadecimal numbers. Your final palette will be an array which should look similar to this:</p>
<pre name="code" class="javascript">
var colorPalete:Array = [0x191919,0x182828,0x60702D,0xAAB232,0xE6FA87]
</pre>
<h2>Step 7: Creating Your Composition</h2>
<p>Our composition is setup with a few rules, so we now need to apply those rules. Let&#8217;s create a function that will generate the composition for us.</p>
<p><strong>Editor&#8217;s note:</strong> I&#8217;m afraid the ActionScript in this step is causing our syntax highlighter to trip Firefox up (this sometimes happens and I&#8217;ve no idea why). For now, it&#8217;s best you <a href="http://activetuts.s3.amazonaws.com/tuts/011_codedChaos/tutorial/step7.as" target="_blank">download it</a> to have a look. Sorry for the inconvenience.</p>
<h2>Step 8: Adding the Background</h2>
<p>You can test the art work as it is, though you&#8217;ll notice that despite looking ok, something is missing. Yes, the gradient background.</p>
<p>To make a gradient background add this little function:</p>
<pre name="code" class="javascript">
//background gradient settings;
var type:String = GradientType.LINEAR;
var colors:Array = [ 0x990000, 0x220000 ];
var alphas:Array = [ 1, 1 ];
var ratios:Array = [ 0, 255 ];
var matr:Matrix = new Matrix();
var sprMethod:String = SpreadMethod.PAD;
var bg:Sprite = new Sprite();
var g:Graphics = bg.graphics;

//Background creation
function createBackground(){
	//starts a gradient box
	matr.createGradientBox(500, 440, 90, 0, 0 ); //make the gradient the size of your stage, set the rotation to 90 degrees
	//begins the fill
	g.beginGradientFill(type, colors, alphas, ratios, matr, sprMethod );
	//draws the rectangle
    g.drawRect( 0, 0, 500, 440 ); //be sure to draw the rectangle the size of your stage
	//adds to stage
	addChild(bg);
}
</pre>
<p>Be sure to add a call to this in the first line of your createComposite() function.</p>
<h2>Step 9: Removing the Composition</h2>
<p>This works by just looping through the stage child objects and removing them.</p>
<pre name="code" class="javascript">
function removeComposite(){
	while(numChildren &gt; 0){
		//eliminates all of the child objects from the main timeline
		removeChildAt(0)
	}
}
</pre>
<h2>Step 10: Randomizing at Runtime</h2>
<p>To create compositions at runtime I&#8217;ll be using the keyboard as a trigger. I&#8217;ll be adding a KEY_DOWN listener to the stage so that everytime a key is pressed the composition will change to a new one.</p>
<pre name="code" class="javascript">
stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyPress)

function onKeyPress(e){
	removeComposite();
	createComposite();
}
</pre>
<h2>Step 11: Saving your Composition</h2>
<p>This is the tricky part. To save your composition you need to print it to a file. I use bullzip pdf printer for that.</p>
<p>Go to <a href="http://www.bullzip.com" target="_blank">bullzip.com</a> and download their printer drivers. Follow the installation instructions.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/011_codedChaos/tutorial/8.jpg" alt="" /></div>
<h2>Step 12: Printing Your Artwork</h2>
<p>Start up your swf, generate compositions by pressing any key until you arrive at one that suits you.</p>
<p>Right-click on the image and select &#8220;print&#8221;.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/011_codedChaos/tutorial/9.jpg" alt="" /></div>
<h2>Step 13: The Bullzip Wizard</h2>
<p>Select the bullzip printer and click print.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/011_codedChaos/tutorial/10.jpg" alt="" /></div>
<p>In &#8220;format&#8221; choose whatever you prefer.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/011_codedChaos/tutorial/11.jpg" alt="" /></div>
<p>However, if you choose PDF you will end up with all the vector shapes, meaning you are free to scale and edit them later on.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/011_codedChaos/tutorial/12.jpg" alt="" /></div>
<h2>Conclusion</h2>
<p>As you can see, this is a rather simple approach to achieve the feel that Joshua brings to his work (which is obviously far more complex than this).</p>
<div class="tutorial_image">
<object width="550" height="484" data="http://activetuts.s3.amazonaws.com/tuts/011_codedChaos/tutorial/codedchaos.swf" type="application/x-shockwave-flash"><param name="src" value="http://activetuts.s3.amazonaws.com/tuts/011_codedChaos/tutorial/codedchaos.swf" /></object>
</div>
<p>I hope you liked this tutorial, feel free to leave comments and questions. Thanks for reading!</p>
<p><strong>Note:</strong> If you are interested in using Joshua&#8217;s code be sure to check out Joshua Davis&#8217; and Branden Hall&#8217;s newly released HYPE framework at <a href="http://hype.joshuadavis.com" target="_blank">hype.joshuadavis.com</a>.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Flashtuts?a=IUwFagSMe-4:EmumxxGhRjY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=IUwFagSMe-4:EmumxxGhRjY:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=IUwFagSMe-4:EmumxxGhRjY:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=IUwFagSMe-4:EmumxxGhRjY:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=IUwFagSMe-4:EmumxxGhRjY:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=IUwFagSMe-4:EmumxxGhRjY:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=IUwFagSMe-4:EmumxxGhRjY:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=IUwFagSMe-4:EmumxxGhRjY:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=IUwFagSMe-4:EmumxxGhRjY:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=IUwFagSMe-4:EmumxxGhRjY:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Flashtuts/~4/IUwFagSMe-4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://active.tutsplus.com/tutorials/actionscript/code-a-chaotic-composition-inspired-by-joshua-davis/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		<feedburner:origLink>http://active.tutsplus.com/tutorials/actionscript/code-a-chaotic-composition-inspired-by-joshua-davis/</feedburner:origLink></item>
		<item>
		<title>Winners Announced: O’Reilly’s ActionScript 3.0 Cookbook – Comment to Win One of Three Copies!</title>
		<link>http://feedproxy.google.com/~r/Flashtuts/~3/2sq4uV1Mqw4/</link>
		<comments>http://active.tutsplus.com/articles/competitions-and-giveaways/oreillys-actionscript-3-0-cookbook-comment-to-win-one-of-three-copies/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 16:01:42 +0000</pubDate>
		<dc:creator>Ian Yates</dc:creator>
				<category><![CDATA[Competitions and Giveaways]]></category>

		<guid isPermaLink="false">http://active.tutsplus.com/?p=2334</guid>
		<description><![CDATA[<img src="http://activetuts.s3.amazonaws.com/tuts/013_giveawayAS3CookBook/cookbook.jpg" alt="">]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s more literary goodness up for grabs on Activetuts+! This week will see copies of (hang on, this is a mouthful) O&#8217;Reilly&#8217;s <a href="http://tinyurl.com/ykskcjg" target="_blank">ActionScript 3.0 Cookbook: Solutions for Flash Platform and Flex Application Developers</a> being given away to three lucky readers!</p>
<p>To enter, all you have to do is leave a comment at the bottom of the post. At the end of the week we&#8217;ll collect up the entries and randomly select the winners.</p>
<p><span id="more-2334"></span></p>
<p>Congratulations to <strong>Andy</strong>, <strong>Jamie Krug</strong> and <strong>Chuck</strong>! For those of you who weren&#8217;t so lucky this time, there&#8217;ll be plenty of Tuts+ giveaways during the coming weeks. Keep your eyes open!</p>
<h3>ActionScript 3.0 Cookbook</h3>
<div class="tutorial_image"><img src="http://activetuts.s3.amazonaws.com/tuts/013_giveawayAS3CookBook/cookbook_l.jpg" alt="ActionScript 3.0 Cookbook" /></div>
<p>
<!--
<p>For the chance to win a copy all you need to do is comment. Make sure you include your correct email address with your comment so that we can contact you. This giveaway is open worldwide, but make sure to get your comment in before midnight this Friday, Pacific Eastern Standard Time.</p>
<p>If your comment is drawn, we&#8217;ll email you directly, at which point you&#8217;ll have seven days to claim. Failure to respond within that time will result in a re-draw.</p>
<p>&#8211;></p>
<h3>Brief Description</h3>
<p>Rather than focus on theory, the ActionScript 3.0 Cookbook concentrates on the practical application of ActionScript, with more than 300 solutions you can use to solve a wide range of common coding dilemmas. You&#8217;ll find recipes that show you how to:</p>
<ul>
<li>Detect the user&#8217;s Flash Player version or their operating system</li>
<li>Build custom classes</li>
<li>Format dates and currency types</li>
<li>Work with strings</li>
<li>Build user interface components</li>
<li>Work with audio and video</li>
<li>Make remote procedure calls using Flash Remoting and web services</li>
<li>Load, send, and search XML data</li>
<li>And much, much more &#8230;</li>
</ul>
<p>More information about ActionScript 3.0 Cookbook is available on <a href="http://tinyurl.com/ykskcjg" target="_blank">amazon.com</a>.</p>
<p><!--<em>
<p>Please note: Envato staff and people who have written more than two tutorials/articles for a Tuts+ site are not eligible to enter.</p>
<p></em>&#8211;></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Flashtuts?a=2sq4uV1Mqw4:TlPnWTe5P9I:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=2sq4uV1Mqw4:TlPnWTe5P9I:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=2sq4uV1Mqw4:TlPnWTe5P9I:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=2sq4uV1Mqw4:TlPnWTe5P9I:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=2sq4uV1Mqw4:TlPnWTe5P9I:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=2sq4uV1Mqw4:TlPnWTe5P9I:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=2sq4uV1Mqw4:TlPnWTe5P9I:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=2sq4uV1Mqw4:TlPnWTe5P9I:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=2sq4uV1Mqw4:TlPnWTe5P9I:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=2sq4uV1Mqw4:TlPnWTe5P9I:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Flashtuts/~4/2sq4uV1Mqw4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://active.tutsplus.com/articles/competitions-and-giveaways/oreillys-actionscript-3-0-cookbook-comment-to-win-one-of-three-copies/feed/</wfw:commentRss>
		<slash:comments>330</slash:comments>
		<feedburner:origLink>http://active.tutsplus.com/articles/competitions-and-giveaways/oreillys-actionscript-3-0-cookbook-comment-to-win-one-of-three-copies/</feedburner:origLink></item>
	</channel>
</rss><!--
This site's performance optimized by W3 Total Cache:

W3 Total Cache improves the user experience of your blog by caching
frequent operations, reducing the weight of various files and providing
transparent content delivery network integration.

Learn more about our WordPress Plugins: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 4/26 queries in 0.024 seconds using memcached

Served from: psdtutsplus.com @ 2009-11-20 14:03:26 -->
