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

<channel>
	<title>Labs @ Jam3 - Toronto Web Development Reseach Blog &#187; flash</title>
	<atom:link href="http://labs.jam3.ca/category/flash/feed/" rel="self" type="application/rss+xml" />
	<link>http://labs.jam3.ca</link>
	<description></description>
	<lastBuildDate>Thu, 05 Jan 2012 18:53:35 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Extending Air</title>
		<link>http://labs.jam3.ca/2011/12/extending-air/</link>
		<comments>http://labs.jam3.ca/2011/12/extending-air/#comments</comments>
		<pubDate>Fri, 02 Dec 2011 19:09:10 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[native extension]]></category>

		<guid isPermaLink="false">http://labs.jam3.ca/?p=1122</guid>
		<description><![CDATA[
WHAT IS A NATIVE EXTENSION?
One of the great new features of AIR 3.0 is native extensions. These extensions allow you to build hooks into the native OS that lets you do some things that AIR doesn&#8217;t support on its own. One of the best things about AIR is the fact that it can run on [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://labs.jam3.ca/wp-content/uploads/2011/12/adobe_Air.jpg"><img src="http://labs.jam3.ca/wp-content/uploads/2011/12/adobe_Air.jpg" alt="" title="Extending Adobe Air" width="537" height="296" class="aligncenter size-full wp-image-1163" /></a><br />
<strong>WHAT IS A NATIVE EXTENSION?</strong></p>
<p>One of the great new features of AIR 3.0 is native extensions. These extensions allow you to build hooks into the native OS that lets you do some things that AIR doesn&#8217;t support on its own. One of the best things about AIR is the fact that it can run on so many platforms, E.G. Android, IOS and the Playbook. However, one drawback to this is that AIR must cater to the lowest common denominator and cannot really focus on device specific features. This is where the native extensions come in. They let you write code native to the device that can tap into the cool features that make each device unique. This means, for iOS you would write the extension in Objective C. For Android you could write it in Java. On Android, this could let you push things to the notification drawer and maybe on a Blackberry you could get access to BBM messages and features. You can find a great tutorial for building your own AIR native extensions for Android at <a href="http://www.adobe.com/devnet/air/articles/developing-native-extensions-air.html">Adobe</a>.</p>
<p><span id="more-1122"></span><br />
<strong>NOT ALL SUNSHINE AND LEMONADE:</strong></p>
<p>The work flow for building your own native extensions isn&#8217;t too bad but there are a few caveats. Right now there aren&#8217;t really tools for packaging your extensions so you need to know a little bit about the command line and building bat files. The other half of this is that the packaging errors can be a little cryptic so be prepared to spend a lot of time googling random phrases and hoping someone else had the same error as you before.</p>
<p>For example, one of the issues I had was with signing my extension. ADT was attempting to generate a time stamp but it kept failing giving me this error: &#8220;Could not generate timestamp: handshake alert: unrecognized_name&#8221;. The solution was to include  &#8220;-tsa none&#8221; as a -package option in my package.bat.</p>
<p>A second issue was with adt.bat. This bat file executes \lib\adt.jar however on my computer it was pointing to the wrong path when my package.bat tried to run it. The solution was to hard code the path to the jar file rather than use the aliases.</p>
<p>When you&#8217;re invoking the native code in AIR and there&#8217;s an error, the AIR debugger doesn&#8217;t really know how to deal with that. It can be difficult and downright frustrating to debug something when you&#8217;re not sure where its failing.</p>
<p>Lastly, like I mentioned before, one of the best reasons to use AIR is the fact that its cross platform compatible. By their very nature, native extensions are not. However, there are still use cases where you could build something in AIR but use a native extension if the OS had a better implementation. It was this last case that lead me to create a native extension for accessing the sharing API in Android.</p>
<p><strong>ShareExt:  AN EXTENSION FOR NATIVE ANDROID SHARING</strong></p>
<p>There are several Actionscript libraries out there for building in links to Facebook, Twitter, Flickr etc&#8230; in order to share your content but one of the cool features of Android is that it has a standardized API for this. So if I&#8217;m deploying to Android why not use something that the users will already be familiar with? With this in mind, I built a native extension for accessing the share functionality in Android from AIR.  I won&#8217;t say that its fully featured and functional but it handles sharing most mime types. You can pass it an image, video, audio or other file and it will do its best to share with the right tools. It also supports sharing straight text.  I built a really basic AIR app that you can side load on your Android device to try it out. The app uses the built in AIR API for file browsing to find a file to share but when it launches the list of sharing apps that&#8217;s all Android, baby. Click <a href="http://jam3media.com/blogFiles/ShareApp.apk">here</a> to download.  If you visit the link on your device it should download and let you install it pretty easily.</p>
<p>You can find the source code for the native extension and the example app on <a href="https://github.com/Jam3/AndroidShareANE">github</a> if you&#8217;d like to play around with it. The folder &#8216;extension&#8217; houses the two halves of the extension. The folder &#8217;shareAirExt&#8217; has the code for the Actionscript part of the extension while the &#8217;shareJavaExt&#8217; has the Java portion.  I&#8217;ve also included my .bat file. Its mainly taken from the tutorial I&#8217;ve linked above but it might be useful to have a working reference.</p>
<p>Once you&#8217;ve built the native extension, using it in Actionscript is a breeze. It acts just like any other object from a SWC or library.</p>
<p><code>/*<br />
Instantiate our Native Extension and share our file with the native extension.<br />
           */<br />
           share = new ShareExt();<br />
           share.shareMedia(file.name,file.nativePath, mimeType);</code></p>
<p><strong>WHATS OUT THERE NOW:</strong></p>
<p>Native extensions are the hot new thing right now and developers have only just started to scratch the surface of what can be done.  At <a href="http://www.gotoandlearn.com/play.php?id=148">gotoAndLearn()</a>, Lee Brimelow talks about building a native extension for pushing to the notification drawer on Android.</p>
<p><a href="http://custardbelly.com/blog/2011/09/21/air-native-extension-example-ibattery-for-ios/">This example</a>, from Todd Anderson, shows how you can build a native extension to get battery information on iOS.  </p>
<p>At <a href="http://www.as3nui.com/air-kinect/">as3NUI</a> they have built a native extension for using the Microsoft X-Box Kinect in AIR. This is coolest thing yet and really shows the power of native extensions in AIR. AIR and Actionscript is already a great environment for making games so hopefully, with this great new extension, we can start seeing some Kinect games and installations built in AIR.</p>
<p>Speaking of games <a href="http://www.milkmangames.com">Milkman Games</a> has built a iOS native extension for using <a href="http://www.milkmangames.com/blog/2011/11/20/announcing-native-ios-game-center-for-adobe-air/">Game Center</a> in your AIR apps. This should mean a more unified experience of AIR apps on iOS. </p>
<p>This is only the beginning and I, for one, am excited to see what comes next.</p>
<p><strong>UPDATE ON JAN 5th, 2011:</strong></p>
<p>I committed a packaged version of the ANE file to the github repo. You can find the repo <a href="https://github.com/Jam3/AndroidShareANE">here</a>. Or, if you&#8217;d prefer, you can download the ANE file directly by clicking <a href="http://jam3media.com/blogFiles/ShareANE.ane">here</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://labs.jam3.ca/2011/12/extending-air/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Underused==PixelBender</title>
		<link>http://labs.jam3.ca/2011/11/underusedpixelbender/</link>
		<comments>http://labs.jam3.ca/2011/11/underusedpixelbender/#comments</comments>
		<pubDate>Wed, 02 Nov 2011 20:34:24 +0000</pubDate>
		<dc:creator>Mikko</dc:creator>
				<category><![CDATA[PixelBender]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[flash]]></category>

		<guid isPermaLink="false">http://labs.jam3.ca/?p=722</guid>
		<description><![CDATA[<script type="text/javascript" src="http://labs.jam3.ca/wp-includes/js/jquery/jquery.js"></script><script type="text/javascript" src="http://labs.jam3.ca/wp-content/plugins/pb-embedflash/js/sbadapter/shadowbox-jquery.js"></script><script type="text/javascript" src="http://labs.jam3.ca/wp-content/plugins/pb-embedflash/js/shadowbox.js"></script><script type="text/javascript"><!--
window.onload = function() {var options ={assetURL:'',loadingImage:'http://labs.jam3.ca/wp-content/plugins/pb-embedflash/css/images/loading.gif',flvPlayer:'http://labs.jam3.ca/wp-content/plugins/pb-embedflash/swf/mediaplayer.swf',animate:true,animSequence:'wh',overlayColor:'#000',overlayOpacity:0.85,overlayBgImage:'http://labs.jam3.ca/wp-content/plugins/pb-embedflash/css/images/overlay-85.png',listenOverlay:true,autoplayMovies:true,showMovieControls:true,resizeDuration:0.35,fadeDuration:0.35,displayNav:true,continuous:false,displayCounter:true,counterType:'default',viewportPadding:20,handleLgImages:'resize',initialHeight:160,initialWidth:320,enableKeys:true,keysClose:['c', 'q', 27],keysPrev:['p', 37],keysNext:['n', 39],handleUnsupported:'',text: {cancel:'Cancel',loading: 'loading',close:'<span class="shortcut">C</span>lose',next:'<span class="shortcut">N</span>ext',prev:'<span class="shortcut">P</span>revious',errors:{single: 'You must install the <a href="{0}">{1}</a> browser plugin to view this content.',shared: 'You must install both the <a href="{0}">{1}</a> and <a href="{2}">{3}</a> browser plugins to view this content.',either: 'You must install either the <a href="{0}">{1}</a> or the <a href="{2}">{3}</a> browser plugin to view this content.'}}};Shadowbox.init(options);}
--></script>
When I first heard of PixelBender I was so stoked.
PixelBender is a shader language built for Adobe products. You notice I say Adobe products and not just Flash. Pixel Bender can be used with Photoshop and After Effects also. (probably other products too)
Basically a shader is a &#8220;filter&#8221; that can be run over an image [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://labs.jam3.ca/wp-content/uploads/2011/10/pixel_bender1.jpg"><img src="http://labs.jam3.ca/wp-content/uploads/2011/10/pixel_bender1.jpg" alt="" title="pixel_bender" width="537" height="296" class="alignnone size-full wp-image-1109" /></a></p>
<p>When I first heard of <strong>PixelBender</strong> I was so stoked.</p>
<p>PixelBender is a <strong>shader language</strong> built for Adobe products. You notice I say Adobe products and <strong>not just Flash</strong>. Pixel Bender can be used with Photoshop and After Effects also. (probably other products too)</p>
<p>Basically a shader is a <strong>&#8220;filter&#8221;</strong> that can be run over an image or data. To get started with PixelBender it&#8217;s best to start out with images rather than with data cause it will be easier to get the hang of things.<br />
<span id="more-722"></span><br />
I&#8217;m really surprised we haven&#8217;t seen PixelBender being used more in Flash. You can write some really amazing effects very quickly. Of course you could write the same effects using <strong>BitmapData</strong> however PixelBender will be much <strong>faster</strong>. Most things in Flash currently only run on <strong>one core</strong> of your computer. So when you are doing calculations on BitmapData objects it will run on one core. Most computers have multiple cores today and PixelBender is able to run evenly <strong>across all your cores</strong>. Of course most likely in the very near future PixelBender will be running on the <strong>GPU</strong> instead of the CPU, which is even better.</p>
<p>So what can PixelBender do (click below):<br />
<small>(Please open the article to see the flash file or player.)</small><br />
<!--more--><br />
Here&#8217;s the PixelBender code to get this effect:</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1"><span class="sy0">&lt;</span>languageVersion : <span class="nu0">1.0</span>;<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">kernel CrossHatch</div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">&lt;</span> &nbsp; namespace : <span class="st0">&quot;com.jam3&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; vendor : <span class="st0">&quot;MikkoHaapoja&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">version</span> : <span class="nu0">1</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; input image4 src; <span class="co1">//input image</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; output pixel4 dst; <span class="co1">//output pixel</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//This variable will make sure only pixels that are</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//darker than the cut off will have the hatching</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; parameter float HATCH_CUT_OFF</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sy0">&lt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; minValue: <span class="nu0">0.0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; maxValue: <span class="nu0">1.0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; defaultValue: <span class="nu0">0.3</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sy0">&gt;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//This variable essentially adjusts the amount</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//of hatching</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; parameter float HATCH_BRIGHTNESS</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sy0">&lt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; minValue: <span class="nu0">0.0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; maxValue: <span class="nu0">3.0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; defaultValue: <span class="nu0">1.0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sy0">&gt;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//How much space between the hatching</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; parameter float HATCH_SPACING</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sy0">&lt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; minValue: <span class="nu0">2.0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; maxValue: <span class="nu0">100.0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; defaultValue: <span class="nu0">2.0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sy0">&gt;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//The direction in which the hatch will be going</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; parameter float HATCH_DIRECTION</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sy0">&lt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; minValue: <span class="nu0">-30.0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; maxValue: <span class="nu0">30.0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; defaultValue: <span class="nu0">2.0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sy0">&gt;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//This is just as effect to brighten the</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//un-hatched colours</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; parameter float COLOUR_ADD</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sy0">&lt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; minValue: <span class="nu0">0.0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; maxValue: <span class="nu0">1.0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; defaultValue: <span class="nu0">0.4</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sy0">&gt;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//This is where the magic happens</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">void</span> evaluatePixel<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//The current pixel we are looking at eg x==10 y==23</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; float2 curPos=outCoord<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//The colour of the current pixel</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//We&#39;ll also set this to be the output</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; float4 curCol=sampleNearest<span class="br0">&#40;</span>src, curPos<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//The colour of the current pixel again</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; float4 originalCol=sampleNearest<span class="br0">&#40;</span>src, curPos<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//This will brighten the pixels</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Note- we could have done</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//curCol*=HATCH_BRIGHTNESS;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//but it would have effected the alpha</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//parameter also and we dont want that</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; curCol.<span class="me1">r*</span>=HATCH_BRIGHTNESS;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; curCol.<span class="me1">g*</span>=HATCH_BRIGHTNESS;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; curCol.<span class="me1">b*</span>=HATCH_BRIGHTNESS;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//The grey scale average colour</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; float avg=<span class="br0">&#40;</span>curCol.<span class="me1">r</span>+curCol.<span class="me1">g</span>+curCol.<span class="me1">b</span><span class="br0">&#41;</span><span class="sy0">/</span><span class="nu0">3.0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//This is used to check if we are allowed to put hatching</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//on this pixel</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; float2 posMod=mod<span class="br0">&#40;</span><span class="kw3">floor</span><span class="br0">&#40;</span>curPos+curPos.<span class="me1">y</span><span class="sy0">/</span>HATCH_DIRECTION<span class="br0">&#41;</span>, </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">floor</span><span class="br0">&#40;</span>HATCH_SPACING<span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//We are allowed to put cross hatching</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>posMod.<span class="me1">x</span>==<span class="nu0">0.0</span> <span class="sy0">&amp;&amp;</span> avg<span class="sy0">&lt;</span>HATCH_CUT_OFF<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; curCol.<span class="me1">r</span>=curCol.<span class="me1">g</span>=curCol.<span class="me1">b</span>=<span class="nu0">0.0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//We are not allowed to put cross hatching</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; curCol=originalCol;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; curCol+=COLOUR_ADD;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; curCol.<span class="me1">a</span>-=COLOUR_ADD;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//We set the output pixel</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; dst=curCol;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>It may look a bit scary because it looks nothing like AS3 or JS or another scripting language. But basically how it works is that this code will run over every single pixel of whatever is passed to it. This is performed in the <strong>evaluatePixel</strong> function. With this filter we have one image that&#8217;s passed to it which is called <strong>src</strong>. </p>
<p>You can see <strong>src</strong> defined being defined near the top of the code:</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1">input image4 src;</div>
</li>
</ol>
</div>
<p>So you may have noticed that with all the variables type comes before the variable name. This is because PixelBender is a C-Style language. What we are saying here is that we&#8217;re going to be passing it an image that has four colour components: red, green, blue, and alpha.</p>
<p>In turn right below where we declare the input we define the <strong>&#8220;output&#8221;</strong> which is a pixel with four colour components:</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1">output pixel4 dst;</div>
</li>
</ol>
</div>
<p>Under those two declarations you&#8217;ll see a whole bunch of paramaters. Parameters are important! They are the variables that will be accessible in Flash. So if you check out the SWF example you&#8217;ll see sliders that are effecting these parameters.</p>
<p><strong>Cool things in the PixelBender language:</strong></p>
<ul>
<li>Don&#8217;t have to write a lot to get cool stuff</li>
<li>You can perform calculations on objects with regular data types (float4 col; col+=3.0;)</li>
<li>Very very fast</li>
</ul>
<p><strong>Gotchas:</strong></p>
<ul>
<li>No looping in PixelBender Flash (there is a bit of a hack that I might talk about later)</li>
<li>When using floats/Number data types you always have to use &#8220;.&#8221; so for instance 0==0.0</li>
<li>float4 is the same as Pixel4</li>
<li>Hard to start thinking of evaluating pixels and not &#8220;pushing&#8221; pixels</li>
</ul>
<p><strong>To get started with PixelBender visit this page:</strong><br />
<a href="http://www.adobe.com/devnet/pixelbender.html">http://www.adobe.com/devnet/pixelbender.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://labs.jam3.ca/2011/11/underusedpixelbender/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coding for the 90%</title>
		<link>http://labs.jam3.ca/2011/07/coding-for-the-90/</link>
		<comments>http://labs.jam3.ca/2011/07/coding-for-the-90/#comments</comments>
		<pubDate>Wed, 27 Jul 2011 18:34:42 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Approach]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[beginner]]></category>
		<category><![CDATA[best practices]]></category>
		<category><![CDATA[code review]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[developer]]></category>
		<category><![CDATA[developers]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[interactive developer]]></category>

		<guid isPermaLink="false">http://labs.jam3.ca/?p=861</guid>
		<description><![CDATA[
If there’s one thing I’ve learned during my years as a Flash developer its that we’re lazy. Coders are always trying to find ways to make their work easier and to write less code.  The most interesting thing about coding is that the more experienced you are the less code you probably write on [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://labs.jam3.ca/wp-content/uploads/2011/07/coding_for_90.jpg"><img src="http://labs.jam3.ca/wp-content/uploads/2011/07/coding_for_90.jpg" alt="" title="coding_for_90" width="537" height="296" class="alignnone size-full wp-image-938" /></a><br />
If there’s one thing I’ve learned during my years as a Flash developer its that we’re lazy. Coders are always trying to find ways to make their work easier and to write less code.  The most interesting thing about coding is that the more experienced you are the less code you probably write on a day to day basis. There are a variety of reasons for this. One reason is that the code they write is simply more efficient than the code written by a less experienced coder. Another reason is that senior coders have been around for so long that they’ve simply written it already.  However, the biggest reason I think is having a mindset of always trying to solve the problem with the least amount of work.<br />
<span id="more-861"></span><br />
A lot of coders want to write code that can be used in 100% of cases. Think about it, you write a function once and you every time you want to accomplish that task you just copy and paste. It&#8217;s perfect. This is the holy grail of coding. If you can accomplish this it leaves you to concentrate on only the unique/fun parts of the project.  The problem with this is that it can trap you.  Imagine a scenario where you need a have a large piece of text that needs a scroll bar. Realizing that a scroll bar is something you will use again and again you decide you want to write a scroll bar class that can be used for any kind of configuration of scrolling. Vertical, horizontal, even 45 degree angles. This way you’ll never have to write another again. A noble idea.</p>
<p>However, when you finish writing it you realize that it took you twice as long as it would have if you didn’t worry about horizontal and angled scrolling. Also, now when you use the scroll bar it now takes twice as much set up time just to get a vertical scroll bar. Let&#8217;s say instead of 10 minutes, it now takes 20 minutes.  This isn’t a huge deal most of the time but in aggregate it is. If you use the scroll bar class 10 times in one year you’ve spent an extra hour and forty minutes on it. A better idea would be to code a vertical scroll bar and extend the class when you do need the rare horizontal scroll bar.</p>
<p>This is what i call coding for the 90%. This should be your guiding principle when writing code. Worry about the 90% of cases, and deal with the other 10% when it comes up.</p>
<p>This principle can also help guide API development. When creating an API its important to think about how a person will use your API in the future. Rather than include a million constructor parameters to handle every use case think about whats the most important.  It may not take much to develop that class but if every time someone uses it they need to configure 10 different options, a lot of time is lost.  Like my previous post on writing <a href="http://labs.jam3.ca/2011/03/reduce-reuse-recycle-tips-for-the-beginner/#more-630">reusable code</a>, following the 90% principle can help you pick your battles when it comes to writing reusable code. Not everything has to be resuable, just the things that you use a lot. </p>
]]></content:encoded>
			<wfw:commentRss>http://labs.jam3.ca/2011/07/coding-for-the-90/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Splitificating Copy: Kicking Textfields&#8217; Ass, One Letter at a Time</title>
		<link>http://labs.jam3.ca/2011/06/splitificating-copy-kicking-textfields-ass-one-letter-at-a-time/</link>
		<comments>http://labs.jam3.ca/2011/06/splitificating-copy-kicking-textfields-ass-one-letter-at-a-time/#comments</comments>
		<pubDate>Wed, 29 Jun 2011 20:31:04 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Category==Null]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[beginner]]></category>
		<category><![CDATA[developer]]></category>
		<category><![CDATA[splitify]]></category>
		<category><![CDATA[text]]></category>

		<guid isPermaLink="false">http://labs.jam3.ca/?p=836</guid>
		<description><![CDATA[
Text and typography effects are all the rage right now. This example shows you what you can do when you can manually animate each individual letter. Manually splitting text fields for animations can be pretty annoying though. In this post I’ll show you how to split your text fields for use in animations.

First off, you’ll [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://labs.jam3.ca/wp-content/uploads/2011/06/splitification1.jpg"><img src="http://labs.jam3.ca/wp-content/uploads/2011/06/splitification1.jpg" alt="Title graphic for Splitificating Copy: Kicking Textfields' Ass, One Letter at a Time" title="Splitificating Copy: Kicking Textfields' Ass, One Letter at a Time" width="537" height="296" class="aligncenter size-full wp-image-871" /></a></p>
<p>Text and typography effects are all the rage right now. <a href="http://labs.jam3.ca/wp-content/uploads/2011/06/RandomText.swf"  target="_blank">This example</a> shows you what you can do when you can manually animate each individual letter. Manually splitting text fields for animations can be pretty annoying though. In this post I’ll show you how to split your text fields for use in animations.<br />
<span id="more-836"></span><br />
First off, you’ll need a text field. I prefer to have my TextField in place and added to the displaylist already so that you can replace it later with your individual fields.</p>
<p>To split our fields we’re going to create a class that will split our text up for us, store references to the fields it creates and replace our single TextField with many fields. This class should also provide methods for accessing our newly created fields.</p>
<p><code><br />
package {</p>
<p>   public class SplitText<br />
   {<br />
       private var _fields:Vector.&lt;TextField&gt; = new Vector.&lt;TextField&gt;();<br />
       private var originalField:TextField;<br />
       private var origParent:DisplayObjectContainer;<br />
       private var _numFields:int = 0;</p>
<p>       public function SplitText()<br />
       {<br />
       }</p>
<p>       public function splitify(textField:TextField):void{</p>
<p>       }</p>
<p>        public function get textFields():Vector.&lt;TextField&gt;{<br />
           return _fields;<br />
       }<br />
       public function get numFields():int{<br />
           return _numFields;</p>
<p>      }<br />
  }<br />
}<br />
</code><br />
So now we have our class structure flushed out. As you can see we have a Vector for storing our fields, as well as places to store references to both our original field and its parent.</p>
<p>We would use this new class like this:<br />
<code><br />
var splitText:SplitText = new SplitText();<br />
splitText.splitify(myField);</p>
<p>//do something here to the new fields!<br />
</code></p>
<p>But wait! our split method doesn’t do anything yet! Lets fix that.</p>
<p>Lets build our function:<br />
<code><br />
public function  splitify(textField:TextField):void{</p>
<p>//store a reference to the original field<br />
           originalField = textField;</p>
<p>           //we want to be able to add our new fields in the same place as the old field. In order to do this we need to make sure that our old field has a parent.<br />
           if(originalField.parent ==null) {<br />
               throw new Error("Please add your textfield to the displaylist before attempting to split it. This will replace your feild in place");<br />
           }</p>
<p>           //store the parent<br />
           origParent = originalField.parent;</p>
<p>           //remove our feild from its parent<br />
           origParent.removeChild(textField);</p>
<p>           //store how many letters are in our textField<br />
           var numLetters:int = originalField.length</p>
<p>          //the text format includes all the important properties we’ll need to  duplicate our feild over and over<br />
          var tf:TextFormat = originalField.getTextFormat(); </p>
<p>         //loops through every letter<br />
         for(var i:int = 0;i&lt;numLetters;i++){</p>
<p>         //skips to the next letter if the current one is a space<br />
         if(originalField.text.charAt(i)==" ") continue;</p>
<p>         //creates a new textfield<br />
         var t:TextField = new TextField();</p>
<p>        //since we want our new field to have the same font we’ll have to make sure it will embed it.<br />
        t.embedFonts =true;</p>
<p>        //apply the textformat to the new feild<br />
        t.defaultTextFormat = tf;<br />
        t.setTextFormat(tf);               </p>
<p>       //since our text is going to be only one letter we want to make sure its single line and resizes correctly<br />
       t.multiline = false;<br />
       t.wordWrap = false;</p>
<p>       //this gives us a rectangle for the bounds of the indivual letter. Lets us place the new field in the same spot.<br />
       var rect:Rectangle = originalField.getCharBoundaries(i);          </p>
<p>       //the rect is relative to the text field, but we want our fields to be relative to the  to the original fields parent so we had its own x,y to our new field<br />
       t.x = rect.x+originalField.x<br />
       t.y = rect.y+originalField.y;<br />
       t.width = rect.width;<br />
       t.height = rect.height;</p>
<p>       //put our letter in the field<br />
       t.text = originalField.text.charAt(i);  </p>
<p>       //add  our new next field to the parent of the<br />
       origParent.addChild(t);                </p>
<p>       //store our new field in our vector/array<br />
       _fields.push(t);    </p>
<p>       //we increment our counter like this because using myArray.length() is actually very very slow.<br />
           _numFields++;<br />
       }<br />
}<br />
</code></p>
<p>Done! we now have our fields in place and ready to be animated!<br />
As <a href="http://labs.jam3.ca/wp-content/uploads/2011/06/RandColor.swf" target="_blank">an example</a> of what we can do, this next chunk will change the color of each letter to something random.</p>
<p><code><br />
	for(var i:int = 0; i&lt; splitText.numFields;i++){<br />
			var tf:TextFormat =    splitText.textFields[i].getTextFormat();<br />
			tf.color  =  0xFFFFFF * Math.random();<br />
			splitText.textFields[i].setTextFormat( tf);<br />
	}<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://labs.jam3.ca/2011/06/splitificating-copy-kicking-textfields-ass-one-letter-at-a-time/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Reduce, Reuse, Recycle: Tips for the beginner</title>
		<link>http://labs.jam3.ca/2011/03/reduce-reuse-recycle-tips-for-the-beginner/</link>
		<comments>http://labs.jam3.ca/2011/03/reduce-reuse-recycle-tips-for-the-beginner/#comments</comments>
		<pubDate>Fri, 25 Mar 2011 16:15:38 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[flash]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[beginner]]></category>
		<category><![CDATA[best practices]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[developer]]></category>

		<guid isPermaLink="false">http://labs.jam3.ca/?p=630</guid>
		<description><![CDATA[
One thing that a lot of coders talk about is writing reusable code. You see  it on job ads, tutorials, coding articles, etc&#8230; However, as a junior developer it can be hard to get into the habit of writing things that are portable. Writing things worth saving can also be a challenge for newer [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://labs.jam3.ca/wp-content/uploads/2011/03/recycling_image.jpg"><img class="alignnone size-full wp-image-653" title="recycling_image" src="http://labs.jam3.ca/wp-content/uploads/2011/03/recycling_image.jpg" alt="Reduce, Reuse, Recycle: Tips for the beginner " width="537" height="296" /></a></p>
<p>One thing that a lot of coders talk about is writing reusable code. You see  it on job ads, tutorials, coding articles, etc&#8230; However, as a junior developer it can be hard to get into the habit of writing things that are portable. Writing things worth saving can also be a challenge for newer developers. I think one thing that could help is to simplify.  Don’t worry about making that drop down menu work for every possible configuration, and don’t worry about making SwfAddress integration perfect. Pick out the small things and work it out.</p>
<p><span id="more-630"></span></p>
<p>One thing flash developers do a lot is to make sure that text is on whole pixels, For example:</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">myTextField.<span class="me1">x</span> = <span class="nu0">12</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//instead of</span></div>
</li>
<li class="li1">
<div class="de1">myTextField.<span class="me1">x</span> = <span class="nu0">12.2</span>;</div>
</li>
</ol>
</div>
<p>One way of doing this:</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">myTextField.<span class="me1">x</span> = <span class="kw3">int</span><span class="br0">&#40;</span><span class="nu0">12.2</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>Another way, the reusable way, that doesn’t involve littering your code with int() is to simply create your textfield class.</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">public</span> <span class="kw2">class</span> WholePixelText <span class="kw3">extends</span> <span class="kw3">TextField</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> WholePixelText <span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw3">super</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw3">public</span> override <span class="kw2">function</span> <span class="kw3">set</span> x<span class="br0">&#40;</span>value:<span class="kw3">Number</span><span class="br0">&#41;</span>:<span class="kw3">void</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw3">super</span>.<span class="me1">x</span> = <span class="kw3">int</span><span class="br0">&#40;</span>value<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="kw3">public</span> override <span class="kw2">function</span> <span class="kw3">set</span> y<span class="br0">&#40;</span>value:<span class="kw3">Number</span><span class="br0">&#41;</span>:<span class="kw3">void</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw3">super</span>.<span class="me1">y</span> = <span class="kw3">int</span><span class="br0">&#40;</span>value<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>This way no matter what we set the x and y properties to, they will always be floored to whole numbers. We have just saved ourselves countless seconds and keystrokes from typing int(xVal) over and over again. We’ve now begun our foray into reusing code and saving time. Even though this example is very simple, its a good way to get your mind thinking about other ways you can save code for later use.</p>
<p>Another way to get into the habit is to save important functions. How many times have you needed a random number between two integers?<br />
You could try to remember this:</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> myRand:<span class="kw3">int</span> =<span class="kw3">Math</span>.<span class="kw3">random</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">*</span><span class="br0">&#40;</span>max-<span class="kw3">min</span><span class="br0">&#41;</span>+<span class="kw3">min</span>;</div>
</li>
</ol>
</div>
<p>or you could write this once and then add a static Utils class that contains this:</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">public</span> <span class="kw3">static</span> <span class="kw2">function</span> randomInt<span class="br0">&#40;</span><span class="kw3">min</span>:<span class="kw3">int</span>=<span class="nu0">0</span>,<span class="kw3">max</span>:<span class="kw3">int</span>=<span class="nu0">1</span><span class="br0">&#41;</span>:<span class="kw3">int</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw3">Math</span>.<span class="kw3">random</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">*</span><span class="br0">&#40;</span>max-<span class="kw3">min</span><span class="br0">&#41;</span>+<span class="kw3">min</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//Then the next time you need a random int</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//this is all you need to remember:</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> myRand:<span class="kw3">int</span> = Utils.<span class="me1">randomInt</span><span class="br0">&#40;</span><span class="kw3">min</span>,<span class="kw3">max</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>I’m sure if you look around your code you’ll find all kinds of small snippets that you use over and over again. The more you recognize the small things that can be reused, the easier it will be to understand  what makes even complex code reusable.</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.jam3.ca/2011/03/reduce-reuse-recycle-tips-for-the-beginner/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MoleHill Getting Started</title>
		<link>http://labs.jam3.ca/2011/03/molehill-getting-started/</link>
		<comments>http://labs.jam3.ca/2011/03/molehill-getting-started/#comments</comments>
		<pubDate>Tue, 01 Mar 2011 18:12:47 +0000</pubDate>
		<dc:creator>Mikko</dc:creator>
				<category><![CDATA[MoleHill]]></category>
		<category><![CDATA[flash]]></category>

		<guid isPermaLink="false">http://labs.jam3.ca/?p=551</guid>
		<description><![CDATA[
So for the past two days I&#8217;ve been playing around with Away3D/Molehilll. I really like how easy it&#8217;s to get stuff going in Away3D but I got this feeling that I don&#8217;t like not knowing what&#8217;s going on in the background. So I started looking at the low level stuff for Molehill.
Now&#8230; I&#8217;ve literally had [...]]]></description>
			<content:encoded><![CDATA[<p><img alt="First MoleHill Triangle" src="http://labs.jam3.ca/wp-content/uploads/2011/02/firstMoleHillTriangle.jpg" title="First MoleHill Triangle" class="alignnone" width="500" height="296" /></p>
<p>So for the past two days I&#8217;ve been playing around with Away3D/Molehilll. I really like how easy it&#8217;s to get stuff going in Away3D but I got this feeling that I don&#8217;t like not knowing what&#8217;s going on in the background. So I started looking at the low level stuff for Molehill.</p>
<p>Now&#8230; I&#8217;ve literally had two evenings to look at this stuff and so I&#8217;m sure some of my assumptions are wrong but I still want to write a blog post on this stuff. So&#8230; If I say something completely wrong please correct me gently. <img src='http://labs.jam3.ca/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Before we get going I think there are some terms everyone should know.</p>
<p><strong>Terms:</strong><br />
<strong>Vertex</strong>-One point in a triangle, a 3d point. A vertex will define the &#8220;corner&#8221; of a triangle. A gotcha in Molehill is that a vertex will define the position and colour of that corner.</p>
<p><strong>Matrix-</strong>You use Matrices you modify Vertices. Think of a Matrix as an &#8220;equation&#8221; to rotate, scale, or position of a vertex.</p>
<p><strong>Shader-</strong>A shader is a small program that is used to modify vertices. A shader can use a Matrix to modify the Vertex. (program that runs the equation over all 3d points) My gotcha was that my mind was thinking of Shaders in terms of modifying textures and looks but they also modify positions of things.</p>
<p>So now that we have that out of the way we can start looking at the different parts that make up MoleHill.<br />
<span id="more-551"></span></p>
<p><strong>Basic Parts Of Molehill:</strong><br />
<a href="http://labs.jam3.ca/asdocs/incubatorAsDoc/flash/display/Stage3D.html">Stage3D</a><br />
<a href="http://labs.jam3.ca/asdocs/incubatorAsDoc/flash/display3D/Context3D.html">Context3D</a><br />
<a href="http://labs.jam3.ca/asdocs/incubatorAsDoc/flash/display3D/VertexBuffer3D.html">VertextBuffer3D</a><br />
<a href="http://labs.jam3.ca/asdocs/incubatorAsDoc/flash/display3D/IndexBuffer3D.html">IndexBuffer3D</a><br />
<a href="http://labs.jam3.ca/asdocs/incubatorAsDoc/flash/display3D/Program3D.html">Program3D</a><br />
<a href="http://labs.jam3.ca/asdocs/incubatorAsDoc/flash/display3D/Program3D.html#upload()">AGAL</a><br />
<a href="http://labs.jam3.ca/asdocs/incubatorAsDoc/flash/display3D/Program3D.html#upload()">VertexShader</a><br />
<a href="http://labs.jam3.ca/asdocs/incubatorAsDoc/flash/display3D/Program3D.html#upload()">FragmentShader</a></p>
<p><strong>Explanation Of The Different Parts Of MoleHill:</strong><br />
<strong>Stage3D</strong><br />
Stage3D is the part that sits in-between Flash and all the GPU goodness. Stage3D does not sit in the display list (you cannot do a addChild on a Stage3D object). Stage3D just exists in the same way that stage just exists. Stage3D sits behind all your regular flash content but in front for the new StageVideo.</p>
<p><strong>Context3D</strong><br />
A Stage3D will contain a Context3D. Think of it this way… It&#8217;s almost the same as Bitmap contains BitmapData. You do not draw to Bitmap in the same way as you do not render stuff in Stage3D. All the work is done with BitmapData the same as Context3D.</p>
<p><strong>VertextBuffer3D</strong><br />
Context3D will contain VertexBuffer3D objects. Think of VertexBuffer3D as being &#8220;instructions&#8221; on what to draw and what it should look like. VertexBuffer3D will contain a Vector.&lt;Number&gt; (array of type Number) that will define vertex position and colour for each vertex. (more on that in a bit)</p>
<p><strong>IndexBuffer3D</strong><br />
The IndexBuffer3D just like the VertexBuffer3D will contain a Vector. But instead of a Vector.&lt;Number&gt; it contains a Vector.&lt;uint&gt; which defines triangles in VertexBuffer3D. Think of it this way… VertexBuffer3D will contain a bunch of positions but IndexBuffer3D will determine what order those positions should be drawn. As a real world example VertexBuffer3D defines cities on a map then IndexBuffer3D will define what order to visit those cities.</p>
<p><strong>Program3D</strong><br />
Program3D is a &#8220;program&#8221; that will run through the data in your VertexBuffer3D and &#8220;modify it&#8221;. Program3D contains two shaders (smaller programs) that will modify the position of every vertex and figure out what every pixel within a triangle should look like. The two smaller shaders or &#8220;programs&#8221; are called VertexShader and FragmentShader.</p>
<p><strong>VertexShader</strong><br />
The VertexShader is a small program written in AGAL that will modify the Vertex positions within a triangle. For instance if you wanted to scale, rotate, or move your triangle you would use the VertexShader to do this.</p>
<p><strong>FragmentShader</strong><br />
The FragmentShader is another small program written in AGAL that will modify the pixels in your triangle. For instance if you want to tint your entire triangle red you would write a small FragmentShader to do that.</p>
<p><strong>AGAL</strong><br />
AGAL is a very low level language. It&#8217;s used to write your VertexShaders and FragmentShaders. It&#8217;s the heart of MoleHill.</p>
<p>Quick diagram on how all the parts interrelate:<br />
<a href="http://labs.jam3.ca/wp-content/uploads/2011/02/moleHillDiagram.jpg" target="_blank"><img alt="MoleHill Diagram" src="http://labs.jam3.ca/wp-content/uploads/2011/02/moleHillDiagram.jpg" title="MoleHill Diagram" class="alignnone" width="471" height="129" /></a></p>
<p><strong>When you use Molehill there are really two parts to your program:</strong></p>
<ol>
<li>Setup</li>
<li>Render</li>
</ol>
<p><strong>Things we want to do during Setup:</strong></p>
<ol>
<li>Get a Context3D instance from Stage3D</li>
<li>Setup the Context3D</li>
<li>Create an VertexBuffer</li>
<li>Create an IndexBuffer</li>
<li>Upload Initial Vertex Data to the VertexBuffer</li>
<li>Upload Initial Index Data to the IndexBuffer</li>
<li>&#8220;Compile&#8221; a VertexShader</li>
<li>&#8220;Compile&#8221; a FragmentShader</li>
<li>Create a Program3D which will use the above shaders</li>
<li>Add a ENTER_FRAME loop which will send data to the GPU</li>
</ol>
<p>I know that&#8217;s a lot of stuff just to get this sucker setup but it&#8217;s not as bad as it sounds. Setup is WAY more complicated in my mind then the actual rendering.</p>
<p><strong>Things we want to do during Render (ENTER_FRAME):</strong></p>
<ol>
<li>Clear the Context3D</li>
<li>Set the Program3D that will be using</li>
<li>Send the Vertex Buffer to Context3D</li>
<li>Setup data for you your shaders (variables)</li>
<li>Draw some triangles</li>
<li>Update the screen with your drawn triangles</li>
</ol>
<p>Now let&#8217;s dig into source code. </p>
<p>The setup part described above is done in the function &#8220;onGotContext&#8221;. This is because in order to get the Context3D we have to request it and when it&#8217;s available Flash will send it to us.</p>
<p>The render part happens in the ENTER_FRAME function listener &#8220;onRenderLoop&#8221;.</p>
<p>Enjoy&#8230; I tried to write as many comments as possible in the code so you can follow along. I should note that this source code is based on <a href="http://www.bytearray.org/?p=2555">Thibault Imbert&#8217;s</a> blog post and this <a href="http://2010.max.adobe.com/online/2010/MAX175_1288221804987EOHN">video</a>.</p>
<div class="geshi no actionscript">
<div class="head">package</div>
<ol>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">import</span> com.<span class="me1">adobe</span>.<span class="me1">utils</span>.<span class="me1">AGALMiniAssembler</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">import</span> flash.<span class="me1">display</span>.<span class="me1">Sprite</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">import</span> flash.<span class="me1">display</span>.<span class="me1">Stage3D</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">import</span> flash.<span class="me1">display</span>.<span class="me1">StageAlign</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">import</span> flash.<span class="me1">display</span>.<span class="me1">StageScaleMode</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">import</span> flash.<span class="me1">display3D</span>.<span class="me1">Context3D</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">import</span> flash.<span class="me1">display3D</span>.<span class="me1">Context3DProgramType</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">import</span> flash.<span class="me1">display3D</span>.<span class="me1">Context3DTriangleFace</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">import</span> flash.<span class="me1">display3D</span>.<span class="me1">Context3DVertexBufferFormat</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">import</span> flash.<span class="me1">display3D</span>.<span class="me1">IndexBuffer3D</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">import</span> flash.<span class="me1">display3D</span>.<span class="me1">Program3D</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">import</span> flash.<span class="me1">display3D</span>.<span class="me1">VertexBuffer3D</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">import</span> flash.<span class="me1">events</span>.<span class="me1">Event</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">import</span> flash.<span class="me1">geom</span>.<span class="me1">Matrix3D</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">import</span> flash.<span class="me1">geom</span>.<span class="me1">Rectangle</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#91;</span>SWF<span class="br0">&#40;</span><span class="kw3">width</span>=<span class="st0">&quot;980&quot;</span>, <span class="kw3">height</span>=<span class="st0">&quot;570&quot;</span>, frameRate=<span class="st0">&quot;60&quot;</span><span class="br0">&#41;</span><span class="br0">&#93;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">public</span> <span class="kw2">class</span> MoleHill2 <span class="kw3">extends</span> Sprite</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">//Context3D is where the rendering happens</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">//It&#39;s like BitmapData to Bitmap (Stage3D)</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw3">private</span> <span class="kw2">var</span> context3d:Context3D;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">//This will be where our VertexData will be stored</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw3">private</span> <span class="kw2">var</span> vertexBuffer:VertexBuffer3D;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">//This will define what order Vertices should be drawn</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw3">private</span> <span class="kw2">var</span> indexBuffer:IndexBuffer3D;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">//This program will contain two shaders</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">//that modify vertex data</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw3">private</span> <span class="kw2">var</span> program:Program3D;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">//This is a Matrix that will be used by</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">//our VertexShader to modify the position</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">//of our vertices (don&#39;t worry you&#39;ll get it)</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw3">private</span> <span class="kw2">var</span> model:Matrix3D=<span class="kw2">new</span> Matrix3D<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw3">public</span> <span class="kw2">function</span> MoleHill2<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//standard flash stuff to just tell the stage not to scale and stay in the top left corner</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw3">stage</span>.<span class="kw3">scaleMode</span>=StageScaleMode.<span class="me1">NO_SCALE</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw3">stage</span>.<span class="kw3">align</span>=StageAlign.<span class="me1">TOP_LEFT</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//We want to add an event listener for when flash gives us our Context3D</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//Flash may not be able to give it right away so thats why we do this</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw3">stage</span>.<span class="me1">stage3Ds</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>.<span class="me1">addEventListener</span><span class="br0">&#40;</span>Event.<span class="me1">CONTEXT3D_CREATE</span>, onGotContext<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//Here we are saying &quot;Oh please Flash give us some GPU goodness&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//and Flash will respond to us through the function onGotContext</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw3">stage</span>.<span class="me1">stage3Ds</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>.<span class="me1">requestContext3D</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//Here we are just saying that Flash should render the 3d stuff</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//in a rectangle that is 980px wide and 570px hight at 0,0</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw3">stage</span>.<span class="me1">stage3Ds</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>.<span class="me1">viewPort</span>=<span class="kw2">new</span> Rectangle<span class="br0">&#40;</span><span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">980</span>, <span class="nu0">570</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; protected <span class="kw2">function</span> onGotContext<span class="br0">&#40;</span>ev:Event<span class="br0">&#41;</span>:<span class="kw3">void</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//We get the Stage3D that&#39;s going to give our Context3D</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw2">var</span> stage3d:Stage3D=Stage3D<span class="br0">&#40;</span>ev.<span class="me1">currentTarget</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//We got our Context3D- YES!!!</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;context3d=stage3d.<span class="me1">context3D</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//Or did we get our Context3D???</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//Not sure how this could happen but</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//it seems the standard to check for this</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//If we didn&#39;t get a context we of course</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//dont want to do anything else so we just</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//quit this function</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw1">if</span><span class="br0">&#40;</span>context3d==<span class="kw2">null</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//This will make it so that we get errors if</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//something screws up. When you publish your</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//final export swf you should put this as false</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//because apparently this will increase performance</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;context3d.<span class="me1">enableErrorChecking</span>=<span class="kw2">true</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//Think of this as almost as the same thing as </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//new BitmapData(980, 570)&#8230; We are basically saying</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//we want this much data to render to</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//the 4 is the level of anti-aliasing we want to do</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//possible values for Anti-Aliasing are:</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//0 no antialiasing</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//2 some antialiasing</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//4 high quality antialiasing</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//16 very high antialising</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//but when I put in 16 i got an error so maybe 16 doesnt work</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;context3d.<span class="me1">configureBackBuffer</span><span class="br0">&#40;</span><span class="nu0">980</span>, <span class="nu0">570</span>, <span class="nu0">4</span>, <span class="kw2">true</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//here we are basically saying if a triangle isn&#39;t facing us</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//dont draw it out (culling==I DONT CARE ABOUT YOU)</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;context3d.<span class="me1">setCulling</span><span class="br0">&#40;</span>Context3DTriangleFace.<span class="me1">BACK</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//create the vertex buffer</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//we will have 3 vertices</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//and there will be 6 elements to each vertex x, y, z, r, g, b</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;vertexBuffer=context3d.<span class="me1">createVertexBuffer</span><span class="br0">&#40;</span><span class="nu0">3</span>, <span class="nu0">6</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//create the index buffer for vertices (order which the triangle goes)</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//we have one triangle so there are 3 vertices and so there are 3 indices also</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;indexBuffer=context3d.<span class="me1">createIndexBuffer</span><span class="br0">&#40;</span><span class="nu0">3</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//we want to create our vertex data</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//vertex data will contain the position and colour of each vertex</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//Here&#39;s an explation of the data below</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//Each vertex will have the position first then the colour</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//x==-1 is the &quot;left side of the screen&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//x==1 is the &quot;right side of the screen&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//x==0 is the middle of the screen</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//The same applies for Y</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//Colours are represented as decimals so</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//1, 0, 0 &lt;- full red 255 (r, g, b)</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//0.5, 0, 0 &lt;- half red 128</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//The following will define a triangle where</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//The bottom left corner is red</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//The top middle corner is green</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//The bottom right corner is blue</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw2">var</span> vertexData:Vector.<span class="sy0">&lt;</span>Number<span class="sy0">&gt;</span>=Vector.<span class="sy0">&lt;</span>Number<span class="sy0">&gt;</span><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#91;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="nu0">-1</span>, <span class="nu0">-1</span>, <span class="nu0">0</span>, &nbsp;<span class="nu0">255</span><span class="sy0">/</span><span class="nu0">255</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="co1">//&lt;- 1st vertex x,y,z,r,g,b</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="nu0">0</span>, <span class="nu0">1</span>, <span class="nu0">0</span>, &nbsp;<span class="nu0">0</span>, <span class="nu0">255</span><span class="sy0">/</span><span class="nu0">255</span>, <span class="nu0">0</span>, <span class="co1">//&lt;- 2nd vertex x,y,z,r,g,b</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="nu0">1</span>, <span class="nu0">-1</span>, <span class="nu0">0</span>, &nbsp;<span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">255</span><span class="sy0">/</span><span class="nu0">255</span> <span class="co1">//&lt;- 3rd vertex x,y,z,r,g,b</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#93;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//This is the index data we are saying draw the vertices</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//in this order</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//0==first vertex</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//1==second vertex</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//2==third vertex</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw2">var</span> indexData:Vector.<span class="sy0">&lt;</span>uint<span class="sy0">&gt;</span>=Vector.<span class="sy0">&lt;</span>uint<span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="br0">&#91;</span><span class="nu0">0</span>, <span class="nu0">1</span>, <span class="nu0">2</span><span class="br0">&#93;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//send our vertex data to the the vertex buffer</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;vertexBuffer.<span class="me1">uploadFromVector</span><span class="br0">&#40;</span>vertexData, <span class="nu0">0</span>, <span class="nu0">3</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//send our index data to the index buffer</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;indexBuffer.<span class="me1">uploadFromVector</span><span class="br0">&#40;</span>indexData, <span class="nu0">0</span>, <span class="nu0">3</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//we are going to need to agal &quot;compiler&quot; one for vertex and the other for fragment</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw2">var</span> agalVertex:AGALMiniAssembler=<span class="kw2">new</span> AGALMiniAssembler<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw2">var</span> agalFragment:AGALMiniAssembler=<span class="kw2">new</span> AGALMiniAssembler<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//So lets do some AGAL</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//AGAL is very &quot;basic&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//It&#39;s made up of statements</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//Each statement has at least the following</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//Operation OutPut, Input1</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//Sometimes you could have two inputs</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//Operation OutPut, Input1, Input2</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//So how this works lets say we wanted to do something like</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//I*J==K</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//our agal statement would look something like this</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//mul K, I, J</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//mul==Operation</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//K==Output</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//I==Input1</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//J==Input2</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//Here are some definitions for things you will see below</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//m44==operation to run a Matrix over your data</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//op==output for where the vertex should be on screen</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//va0==x, y, z of a vertex in our triangle</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//vc0==constant that will be defined later (our matrix for changing vertices)</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//v0==a &quot;variable&quot; that will sit between our vertex shader and fragment shader</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//va1==r, g, b of a vertex</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//source for our VertexShader AGAL program</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//Here&#39;s a decription of what the following lines are doing:</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//m44 op, va0, vc0 -&gt; apply a 4&#215;4 matrix on our vertex screen and output it</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//mov v0, va1 -&gt; take our colour at this vertex and send it to the fragment shader</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw2">var</span> agalVertexSource:<span class="kw3">String</span>=<span class="st0">&quot;m44 op, va0, vc0<span class="es0">\n</span>&quot;</span> +</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;mov v0, va1<span class="es0">\n</span>&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//oc==outPut color (colour on screen)</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//v0==Variable that sits between the vertex shader and fragment</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//mov oc, v0 -&gt; take our colour and output it to screen</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw2">var</span> agalFragmentSource:<span class="kw3">String</span>=<span class="st0">&quot;mov oc, v0<span class="es0">\n</span>&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//compile our AGAL source</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//when we compile we&#39;ll get a byteArray that our shaders can use</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;agalVertex.<span class="me1">assemble</span><span class="br0">&#40;</span>Context3DProgramType.<span class="me1">VERTEX</span>, agalVertexSource<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;agalFragment.<span class="me1">assemble</span><span class="br0">&#40;</span>Context3DProgramType.<span class="me1">FRAGMENT</span>, agalFragmentSource<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//Create a program that will use our shaders</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//Remember our program will contain a Vertex Shader and a Fragment Shader</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;program=context3d.<span class="me1">createProgram</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//Send our compiled Shaders to the program to use</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//agalCode==bytearray</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;program.<span class="me1">upload</span><span class="br0">&#40;</span>agalVertex.<span class="me1">agalcode</span>, agalFragment.<span class="me1">agalcode</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//Add our render loop</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;addEventListener<span class="br0">&#40;</span>Event.<span class="me1">ENTER_FRAME</span>, onRenderLoop<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; protected <span class="kw2">function</span> onRenderLoop<span class="br0">&#40;</span>event:Event<span class="br0">&#41;</span>:<span class="kw3">void</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//clear the frame and screen</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;context3d.<span class="kw3">clear</span><span class="br0">&#40;</span><span class="nu0">0.5</span>, <span class="nu0">0.5</span>, <span class="nu0">0.5</span>, <span class="nu0">1</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//set the program that will render to screen</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;context3d.<span class="me1">setProgram</span><span class="br0">&#40;</span>program<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//This is strange??? WHY TWICE?</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//So basically what this will say is in our AGAL code va0 will be our x, y, z</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//and va1 will be our r, g, b</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//0&lt;&#8211; index va0</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//vertexBuffer &lt;&#8211; vertex buffer we will use</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//0&lt;- where to start looking for va0 (0 because x, y, z starts at 0)</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//Context3DVertexBufferFormat.FLOAT_3 &lt;- will have 3 variables to define x, y, z</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//1&lt;&#8211; index va1</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//vertexBuffer &lt;&#8211; vertex buffer we will use</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//3&lt;- where to start looking for va1 (3 because r, g, b starts at 3)</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//Context3DVertexBufferFormat.FLOAT_3 &lt;- will have 3 variables to define r, g, b</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//I think you&#39;d use Context3DVertexBufferFormat.FLOAT_4 if you were using r,g,b,a</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;context3d.<span class="me1">setVertexBufferAt</span><span class="br0">&#40;</span><span class="nu0">0</span>, vertexBuffer, <span class="nu0">0</span>, Context3DVertexBufferFormat.<span class="me1">FLOAT_3</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;context3d.<span class="me1">setVertexBufferAt</span><span class="br0">&#40;</span><span class="nu0">1</span>, vertexBuffer, <span class="nu0">3</span>, Context3DVertexBufferFormat.<span class="me1">FLOAT_3</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//Reset our matrix</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;model.<span class="me1">identity</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//Scale down the triangle by 0.5 on x, y, z</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;model.<span class="me1">appendScale</span><span class="br0">&#40;</span><span class="nu0">0.5</span>, <span class="nu0">0.5</span>, <span class="nu0">0.5</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//Here are saying vc0 will be our model matrix </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//and it will be effecting our vertex data</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;context3d.<span class="me1">setProgramConstantsFromMatrix</span><span class="br0">&#40;</span>Context3DProgramType.<span class="me1">VERTEX</span>, <span class="nu0">0</span>, model<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//draw our triangle to screen</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//0 is what index we should start drawing from</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//1 is how many triangles we want to draw</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;context3d.<span class="me1">drawTriangles</span><span class="br0">&#40;</span>indexBuffer, <span class="nu0">0</span>, <span class="nu0">1</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//Show those triangles on screen</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;context3d.<span class="me1">present</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://labs.jam3.ca/2011/03/molehill-getting-started/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>Great Time To Be a Web Developer In An App Store Economy</title>
		<link>http://labs.jam3.ca/2011/02/great-time-to-be-a-web-developer-in-an-app-store-economy/</link>
		<comments>http://labs.jam3.ca/2011/02/great-time-to-be-a-web-developer-in-an-app-store-economy/#comments</comments>
		<pubDate>Thu, 10 Feb 2011 17:51:57 +0000</pubDate>
		<dc:creator>Mikko</dc:creator>
				<category><![CDATA[Category==Null]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[flash]]></category>

		<guid isPermaLink="false">http://labs.jam3.ca/?p=507</guid>
		<description><![CDATA[
There are two main problems that developers have face:

How to get people to see your app
How to make money off that app

App stores really solve both of these issues. One of the coolest things as a web developer is the fact that there are ways to create &#8220;native&#8221; apps for these app stores using the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://labs.jam3.ca/wp-content/uploads/2011/02/appstores_snapshot.jpg"><img src="http://labs.jam3.ca/wp-content/uploads/2011/02/appstores_snapshot.jpg" alt="" title="appstores_snapshot" width="500"  class="alignnone size-full wp-image-542" /></a><br />
There are two main problems that developers have face:</p>
<ol>
<li><strong>How to get people to see your app</strong></li>
<li><strong>How to make money off that app</strong></li>
</ol>
<p>App stores really solve both of these issues. One of the coolest things as a web developer is the fact that there are ways to create &#8220;native&#8221; apps for these app stores using the standard languages we use: <strong>html</strong>, <strong>js</strong>, <strong>css</strong>, and <strong>AS3</strong>.<br />
<span id="more-507"></span></p>
<p>Here are some platforms web developers can deploy to using the languages noted above: </p>
<style>
.appstoretable{ margin:5px;border:solid 1px #F90; font-size:10px; width:400px;} .appstoretitle { font-weight:bold; background-color:#F90; padding:4px; color:#000; } .appstoretable tr.item { background-color: #333;text-align:center; } .appstoretable tr.item2 { background-color:#000;text-align:center; } .appstoretable th { font-weight:bold; background-color:#F90; padding:8px; color:#000; } .winner {background-color:#0F0;color:#000;} .looser {background-color:#F00;color:#000;}
</style>
<table class="appstoretable">
<tr class="item">
<th>App Store</th>
<th>Platforms</th>
<th>Monetization Methods</th>
<th>Revenue</th>
<th>Payment Cycle</th>
<th>Cost</th>
<th>Minimum App Price</th>
<th>Approval Process</th>
</tr>
<tr class="item2">
<td>iOs App Store</td>
<td>iPod, iPhone, iPad</td>
<td>App Sales, In App Adds, In App Sales, Subscriptions (soon)</td>
<td>70% store 70% For App Sales 60% For Adds</td>
<td class="looser">Monthly when $150 is reached</td>
<td>$99 per year</td>
<td>$0.99</td>
<td>Yes</td>
</tr>
<tr class="item">
<td>Mac App Store</td>
<td class="looser">Apple Computers</td>
<td class="looser">App Sales</td>
<td>70%</td>
<td>Monthly</td>
<td>$99 per year</td>
<td>$0.99</td>
<td>Yes</td>
</tr>
<tr class="item2">
<td>Blackberry App World</td>
<td>Many Blackberry Phones: Blackberry Playbook</td>
<td class="winner">App Sales, In App Sales, In App Adds, Subscriptions</td>
<td>70% For App Sales 60% For Adds</td>
<td>When using Carrier Based Billing- Monthly when $50 earned. Paypal- Monthly when $100 is reached</td>
<td class="looser">$200 per 10 credits. Credits are charged on submitting an app (even if it doesnt pass the Approval process)</td>
<td>$0.99</td>
<td>Yes</td>
</tr>
<tr class="item">
<td>Chrome Web Store</td>
<td>Chrome Browsers and Chrome OS Based Devices</td>
<td>App Sales, Subscription, In App Sales, Adds (of course since its a web app you can use in app adds from AdSense or elsewhere)</td>
<td class="winner">95%-30 cent processing fee</td>
<td class="winner">2 days after a successful sale if the payout is more than $1</td>
<td>$5 one time</td>
<td>$1.99</td>
<td>Yes</td>
</tr>
<tr class="item2">
<td>Android Market</td>
<td>Android Based Devices</td>
<td>App Sales, In App Sales</td>
<td>70%</td>
<td class="winner">Changes based on country and bank but $1 must be reached</td>
<td>$25 one time + $20 to enroll for payment service</td>
<td>$0.99</td>
<td class="winner">No</td>
</tr>
<tr class="item">
<td>Nokia Ovi</td>
<td class="winner">Nokia Devices</td>
<td class="looser">App Sales</td>
<td>70%</td>
<td>Monthly when 100 euros is reached</td>
<td class="winner">1 euro one time</td>
<td>1 euro</td>
<td>Yes</td>
</tr>
</table>
<p><strong>Conclusions:</strong><br />
If you are a developer and want to start developing with minimal overhead and with <strong>huge reach</strong> the <a href="http://store.ovi.com/">Nokia Ovi store</a> is the way to go. The Apple iDevices are extremely popular in North America but worldwide Nokia is still a HUGE player with bigger reach.</p>
<p>The <a href="https://chrome.google.com/webstore">Chrome web store</a> is the most <strong>straightforward</strong> option for web developers. The sign up fee is very minimal and there are no other tools you need to learn (or buy) to deploy apps. Out of all the stores the Chrome web store takes the <strong>smallest cut</strong> however it&#8217;s a very new platform and doesn&#8217;t have the same user counts the other platforms can boast. The $1.99 minimum app price point is interesting in that as a developer you will not be competing against $0.99 apps however it being a new platform it could deter users.</p>
<p>Even though neither of the <a href="http://itunes.apple.com/us/genre/ios/">Apple</a> <a href="http://www.apple.com/mac/app-store/">stores</a> won in any of the columns they are obviously still a great option to develop for. They were the first platform to have an app store and so the other app stores are definitely trying to compete against Apple&#8217;s stores and with good reason. The iOs store still <strong>sells the most apps</strong> out of any store.</p>
<p>The <a href="https://market.android.com/">Android market</a> shouldn&#8217;t be forgotten as it is currently the biggest competitor in app sales vs the Apple store. Enrollment fees are quite a bit lower than the Apple store&#8217;s and it&#8217;s nice that they <strong>payout developers quite often</strong>.</p>
<p><a href="http://appworld.blackberry.com/webstore/">Blackberry App World</a> is an interesting underdog. Currently it&#8217;s receiving A LOT of developer support especially from the Flash Platform community because of the <a href="http://us.blackberry.com/playbook-tablet/">Blackberry Playbook</a> and <a href="http://devblog.blackberry.com/2010/10/blackberry-playbook-developer-promotion-information/">this promotion</a>. It&#8217;s very cool that they&#8217;ve been working on app monetization strategies more than anyone else. This gives the most avenues for developers to make money. Cost for being a App World developer is much too high though. (although currently the initial $200 fee is waved) Unlike the other stores where you pay a one time fee or anually in the App World developers pay <strong>$200 to receive 10 credits</strong>. One credit is used per app you submit. You will not receive your credit back if your application fails the QA process. You will also have to use one credit to update your app. This to me is <strong>ridiculous!</strong> In order to maintain quality of applications developers should not be penalized.</p>
<p>Overall the great news is that using the languages you know with some new tools you can target most, if not all of these platforms. (more on these tools in a future post)</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.jam3.ca/2011/02/great-time-to-be-a-web-developer-in-an-app-store-economy/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Get the Most From Your Animator</title>
		<link>http://labs.jam3.ca/2010/10/working-with-animators/</link>
		<comments>http://labs.jam3.ca/2010/10/working-with-animators/#comments</comments>
		<pubDate>Thu, 14 Oct 2010 18:08:07 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[flash]]></category>
		<category><![CDATA[advice]]></category>
		<category><![CDATA[animators]]></category>
		<category><![CDATA[communication]]></category>
		<category><![CDATA[designers]]></category>
		<category><![CDATA[developers]]></category>
		<category><![CDATA[process]]></category>
		<category><![CDATA[producers]]></category>

		<guid isPermaLink="false">http://labs.jam3.ca/?p=438</guid>
		<description><![CDATA[How to get the Biggest Bang for your Buck From Timeline Animators: An assortment of tips and instructions for working with an animator and making sure that a project reaches its full potential.]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://labs.jam3.ca/wp-content/uploads/2010/10/animatorPostThumb.jpg"><img class="size-full wp-image-440 aligncenter" title="Example Animation from Family's Baxter" src="http://labs.jam3.ca/wp-content/uploads/2010/10/animatorPostThumb.jpg" alt="Showing the graphic in both Flash and within the game" width="432" height="332" /></a></p>
<p>Time line Animators are very good at what they do. They can make a  site come to life. Many of our projects here at Jam3 would not be  possible with out an animator. <a title="http://www.family.ca/baxter" rel="nofollow" href="http://www.family.ca/baxter">Family’s Baxter</a> is a great example of how an animator can help to put a project over  the top. The paint splatters might seem simple but they would have been  very difficult to produce only using code; the animations for the games  (I.E. Jackal or the zombie walking) would have been downright  impossible. However animators are not typically versed in Flash/web  development. Therefore it is important that communication occurs before  the project begins in order to make sure that the developers and  animators are on the same page. The following is an assortment of tips  and instructions for working with an animator.</p>
<p>Firstly, if the animator is animating something for actual use in  a site, you make sure that they limit the amount extra animations.  If  the animator is making an animation guide then they are free to incorporate all parts of the site for proofing. However,  normally the animator is trying to provide the developers with a  specific effect for a specific graphic.</p>
<p>It’s important that the animator organize the .fla properly. This  means they should try to limit the amount of clip nesting. The animator  should be instructed to only nest clips when absolutely necessary. This  makes it easy for the developer to control animations (e.g. the speed  of the animation or start timings) and to remove parts that may no  longer be needed. Also, there should be a discussion with the animator  about how things should be named in the library.</p>
<p>Next, it’s very important that the animator is consistent with  registration point placement. Ideally the placement will be dictated by  the developer but if that’s not possible it’s important that the  animator chooses one placement and sticks with it. Top-left or centered  is fine as long as its consistent throughout the file.</p>
<p>Another useful tool an animator/producer/developer can use to  help organise animations are frame labels. They are very useful in  identifying  frames and states such as “up”, “over”, “animate in”,  etc&#8230; Since these are case sensitive it is important that they are  consistent. Either all uppercase, or all lowercase. camelCasing or  Proper Casing are possibilities as well, assuming their use is  consistent.</p>
<p>The biggest takeaway when working with an animator is that they  understand how important it is to be consistent. The developer shouldn&#8217;t  have to constantly check how a clip is placed or what case a frame  label is in. It cannot be assumed that the animator understands why this  is necessary and, frankly, it is not their responsibility to know these  kinds of things without being told. It is up to you (i.e.  developers/producers/designers) to make sure that the animator knows how  you want the clip.</p>
<p>If animators are given proper instructions, development time can  be saved or put to better use. There is nothing more frustrating than to  have to redo something because proper communication wasn&#8217;t present at  the beginning of the project.</p>
<p>When everybody is on the same page,  it is a magical time when projects take that extra leap from good to great.</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.jam3.ca/2010/10/working-with-animators/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Quick Little Experiment</title>
		<link>http://labs.jam3.ca/2010/07/quick-little-experiment/</link>
		<comments>http://labs.jam3.ca/2010/07/quick-little-experiment/#comments</comments>
		<pubDate>Sat, 24 Jul 2010 13:11:30 +0000</pubDate>
		<dc:creator>Mikko</dc:creator>
				<category><![CDATA[flash]]></category>

		<guid isPermaLink="false">http://labs.jam3.ca/?p=431</guid>
		<description><![CDATA[I had a quick idea for an experiment. Started writing it on the train going home from work and finished it went I got home.
Maybe it will become more or maybe not.
(sorry for the frame rate drop from when I was recording, first time recording in HD)

]]></description>
			<content:encoded><![CDATA[<p>I had a quick idea for an experiment. Started writing it on the train going home from work and finished it went I got home.</p>
<p>Maybe it will become more or maybe not.</p>
<p>(sorry for the frame rate drop from when I was recording, first time recording in HD)<br />
<object width="540" height="304"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=13577786&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=f40044&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=13577786&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=f40044&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="540" height="304"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://labs.jam3.ca/2010/07/quick-little-experiment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

