<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0">

<channel>
	<title>Lost In Actionscript - Shane McCartney</title>
	
	<link>http://www.lostinactionscript.com/blog</link>
	<description>Lost In Actionscript</description>
	<lastBuildDate>Tue, 14 Jul 2009 19:30:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/LostInActionscript" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
		<title>Custom blend modes for Flash 10</title>
		<link>http://www.lostinactionscript.com/blog/index.php/2009/05/26/custom-blend-modes-for-flash-10/</link>
		<comments>http://www.lostinactionscript.com/blog/index.php/2009/05/26/custom-blend-modes-for-flash-10/#comments</comments>
		<pubDate>Mon, 25 May 2009 22:58:46 +0000</pubDate>
		<dc:creator>Shane McCartney</dc:creator>
				<category><![CDATA[Interesting]]></category>
		<category><![CDATA[Play]]></category>
		<category><![CDATA[Source]]></category>

		<guid isPermaLink="false">http://www.lostinactionscript.com/blog/?p=256</guid>
		<description><![CDATA[In the last few months I have been working on a collection of blendmodes for Flash 10 which extend the limited set of blendmodes currently and inconsistently supplied by Adobe applications. This can help to achieve all kinds of motion effects which I won't go into detail here but if you know a little about [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-257" title="chameleon" src="http://www.lostinactionscript.com/blog/wp-content/uploads/2009/05/chameleon-300x224.jpg" alt="chameleon" width="300" height="224" />In the last few months I have been working on a collection of blendmodes for Flash 10 which extend the limited set of blendmodes currently and inconsistently supplied by Adobe applications. This can help to achieve all kinds of motion effects which I won't go into detail here but if you know a little about After Effects you will know that some of these are rather exciting.</p>
<p>If you are familiar with the Adobe product line there is inconsistency between Photoshop/Illustrator/Flash/Fireworks/InDesign and support for various subsets of blendmodes which is rather annoying especially for us Flash guys. This project overzealously named the 'Ultimate Blend Mode Collection' is an attempt to standardize this unofficially on Adobes behalf. So marrying up Photoshop designs and Flash layouts with unsupported blendmodes won't be nearly as annoying as has been previously. Further to this, these custom blendmodes allow for control to exaggerate and undo the blendmode effects. What this means is you do not have to double up the blendmode effect by duplicating the DisplayObject instance with the same blendmode you can just multiply the single blendmode effect - simple and quite effecient.</p>
<p>So far I have completed the following custom blend modes :</p>
<ul>
<li>Add</li>
<li>Hard Mix</li>
<li>Hardlight</li>
<li>Glow</li>
<li>Subtract</li>
<li>Stencil Luma</li>
<li>Extrapolate</li>
<li>Difference</li>
<li>Average</li>
<li>Lighter Color</li>
<li>Lighten</li>
<li>Color Dodge</li>
<li>Stencil Alpha</li>
<li>Stamp</li>
<li>Softlight</li>
<li>Silhouette Luma</li>
<li>Silhouette Alpha</li>
<li>Screen</li>
<li>PinLight</li>
<li>Phoenix</li>
<li>Overlay</li>
<li>Negation</li>
<li>Multiply</li>
<li>Linear Light</li>
<li>Linear Dodge</li>
<li>Linear Burn</li>
<li>Darken</li>
<li>Desaturate</li>
<li>Exclusion</li>
<li>Color Burn</li>
<li>Alpha</li>
<li>Darker Color</li>
</ul>
<p>These are working though have issues of dirty-ness on alpha channels (explained below) for blending layers :</p>
<ul>
<li>Reflect</li>
<li>Freeze</li>
<li>Heat</li>
<li>Vivid Light</li>
</ul>
<p>These custom blend modes are currently in development :</p>
<ul>
<li>Color</li>
<li>Hue</li>
<li>Luminosity</li>
<li>Saturation</li>
<li>Dissolve</li>
</ul>
<h3>How to use custom blend modes</h3>
<p>I have only provided a method to use these custom blend modes included with the 'Ultimate Blendmode Collection' for Flex and CS4 users. This is because the PBJ files are compiled into a SWC so you will need to be able to reference SWCs from your FLA or SWF compiler to use the custom blend modes I have mentioned. The syntax to apply a custom blend mode can be achieved via any of the following approaches :</p>
<div class="igBar"><span id="lactionscript-7"><a href="#" onclick="javascript:showPlainTxt('actionscript-7'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-7">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">BlendModeShader</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">myDisplayObject.<span style="color: #006600;">blendShader</span> = BlendModeShader.<span style="color: #006600;">SOFTLIGHT</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>
or</p>
<div class="igBar"><span id="lactionscript-8"><a href="#" onclick="javascript:showPlainTxt('actionscript-8'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-8">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">BlendModeShader</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">shaders</span>.*;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">myDisplayObject.<span style="color: #006600;">blendShader</span> = <span style="color: #000000; font-weight: bold;">new</span> BlendModeSoftlight<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>
or you can manipulate the shader </p>
<div class="igBar"><span id="lactionscript-9"><a href="#" onclick="javascript:showPlainTxt('actionscript-9'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-9">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">BlendModeShader</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">shaders</span>.*;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> customBlendMode: BlendModeSoftlight&nbsp; = <span style="color: #000000; font-weight: bold;">new</span> BlendModeSoftlight<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">customBlendMode.<span style="color: #006600;">multiply</span> = <span style="color: #cc66cc;color:#800000;">2</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">customBlendMode.<span style="color: #006600;">alpha</span> = <span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">5</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">myDisplayObject.<span style="color: #006600;">blendShader</span> = customBlendMode; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h3>Tips for writing your own custom blend modes</h3>
<p>Here are some potentially huge gotchas and lovely time savers for those wanna be pixel shader writers (like myself) :</p>
<ol>
<li>Un-multiply alpha before carrying out your shader algorithm. You might already know that Flash pre-multiplies the alpha channel onto the rgb channels this means that if you want to know what the actual rgb components are you will need to do the following :
<div class="igBar"><span id="lactionscript-10"><a href="#" onclick="javascript:showPlainTxt('actionscript-10'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-10">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">void</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">evaluatePixel<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float2 uv = outCoord<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float4 src1Rgba = sampleLinear<span style="color: #66cc66;">&#40;</span>src1, uv<span style="color: #66cc66;">&#41;</span>; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; float src1Alpha = src1Rgba.<span style="color: #006600;">a</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>src1Alpha&gt;<span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">0</span><span style="color: #66cc66;">&#41;</span> src1Rgba.<span style="color: #006600;">rgb</span> *= <span style="color: #cc66cc;color:#800000;">1</span>.<span style="color: #cc66cc;color:#800000;">0</span>/src1Alpha; <span style="color: #808080; font-style: italic;">//This line un-multiplies the alpha from the rgb channels</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
</li>
<li>When your done manipulating your blending layer against the base layer it's more than likely you will need to composite your new blending layer and base layers together while preserving the alpha components. The following should be useful for this :
<div class="igBar"><span id="lactionscript-11"><a href="#" onclick="javascript:showPlainTxt('actionscript-11'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-11">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">void</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">evaluatePixel<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;......</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600;">interpolateAlpha</span> = src2Rgba.<span style="color: #006600;">a</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; inverseAlpha = <span style="color: #cc66cc;color:#800000;">1</span>.<span style="color: #cc66cc;color:#800000;">0</span>-interpolateAlpha;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; dst.<span style="color: #006600;">rgb</span> = src2Rgba.<span style="color: #006600;">rgb</span>+src1Rgba.<span style="color: #006600;">rgb</span>*inverseAlpha;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; dst.<span style="color: #006600;">a</span> = <span style="color: #0066CC;">min</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">1</span>.<span style="color: #cc66cc;color:#800000;">0</span>, src1Alpha+src2Alpha<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
</li>
<li>Make sure you clamp the components you are altering between 0.0 and 1.0 outside these will give you unusual results between tests made with the Pixel Bender Toolkit and from a published Flash movie. This bit of code ought to fix this :
<div class="igBar"><span id="lactionscript-12"><a href="#" onclick="javascript:showPlainTxt('actionscript-12'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-12">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">void</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">evaluatePixel<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float3 minRgb = float3<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">0</span>, <span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">0</span>, <span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">0</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; float3 maxRgb = float3<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">1</span>.<span style="color: #cc66cc;color:#800000;">0</span>, <span style="color: #cc66cc;color:#800000;">1</span>.<span style="color: #cc66cc;color:#800000;">0</span>, <span style="color: #cc66cc;color:#800000;">1</span>.<span style="color: #cc66cc;color:#800000;">0</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; ......</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600;">dst</span>.<span style="color: #006600;">rgb</span> = clamp<span style="color: #66cc66;">&#40;</span>dst.<span style="color: #006600;">rgb</span>, minRgb, maxRgb<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
</li>
<li>Because Flash premultiplies alpha and I explained earlier about why you may need to un-multiply alpha from the rgb components. It's important to know from this there is a certain degree of losiness and this article by <a href="http://www.quasimondo.com/archives/000665.php#000665">Mario</a> is a great Actionscript explanation (completely unrelated to shaders) of this and is one among many others crying out for help (like me). You may notice in the example below which demonstrates these custom blend modes (or in your own tests) a certain degree of image dirty-ness and this dirty-ness is due to this. I am still working on a way to reduce or get around this - any ideas are certainly welcome - and I've highlighted the shaders above most affected by this.</li>
<li>When applying a shader the input sources for the blending and base layer are automatically set. This is great but doesn't allow for setting any further image4 inputs. From my tests if I do try to do this then the Flash Player crashes every time. This is bug and generally bugging me because I can't complete other custom blendmodes based on random math like the Dissolve blendmode</li>
</ol>
<h3>How to get the custom blend modes</h3>
<p>I have placed my PBJ, PBK and SWC files on a <a href="http://code.google.com/p/blendmodes4flash/">code.google</a> project. I have also put together a brief <a href="http://code.google.com/p/blendmodes4flash/wiki/GettingStarted">getting started</a> page.  If you want to get an idea of what's possible using these custom blend modes the simple example below should help to demonstrate this. Also make sure you try out a few of the various base and blending layers I have set up to see what does what.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_UltimateBlendModeCollection_816495633"
			class="flashmovie"
			width="550"
			height="920">
	<param name="movie" value="http://www.flashdynamix.com/examples/Blendmodes4Flash/SWFLoader.swf?url= http://www.flashdynamix.com/examples/Blendmodes4Flash/UltimateBlendModeCollection.swf" />
	<param name="bgcolor" value="#171313" />
	<param name="allowscriptaccess" value="sameDomain" />
	<param name="allowfullscreen" value="true" />
	<param name="allownetworking" value="all" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.flashdynamix.com/examples/Blendmodes4Flash/SWFLoader.swf?url= http://www.flashdynamix.com/examples/Blendmodes4Flash/UltimateBlendModeCollection.swf"
			name="fm_UltimateBlendModeCollection_816495633"
			width="550"
			height="920">
		<param name="bgcolor" value="#171313" />
		<param name="allowscriptaccess" value="sameDomain" />
		<param name="allowfullscreen" value="true" />
		<param name="allownetworking" value="all" />
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<h3>References</h3>
<p>If you are interested in writing your own blend modes I used quite a few sources in order to collect the algorithms used in the examples seen above - here are the main sources :<br />
<a href="http://www.pegtop.net/delphi/articles/blendmodes/">http://www.pegtop.net/delphi/articles/blendmodes/</a><br />
<a href="http://blog.mouaif.org/?p=94">http://blog.mouaif.org/?p=94</a><br />
<a href="http://www.nathanm.com/photoshop-blending-math/">http://www.nathanm.com/photoshop-blending-math/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lostinactionscript.com/blog/index.php/2009/05/26/custom-blend-modes-for-flash-10/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Export Layers to SWF with JSFL</title>
		<link>http://www.lostinactionscript.com/blog/index.php/2009/04/03/export-layers-to-swf-with-jsfl/</link>
		<comments>http://www.lostinactionscript.com/blog/index.php/2009/04/03/export-layers-to-swf-with-jsfl/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 00:42:19 +0000</pubDate>
		<dc:creator>Shane McCartney</dc:creator>
				<category><![CDATA[Interesting]]></category>
		<category><![CDATA[Source]]></category>

		<guid isPermaLink="false">http://www.lostinactionscript.com/blog/?p=232</guid>
		<description><![CDATA[It's embarrassing but until the other week I hadn't a reason to do anything (beyond tinkering) with JSFL. JSFL can be especially useful for simplifying or automating tasks in the Flash IDE and that isn't breaking news. I think I understand why I haven't been using JSFL too much until recently. The major problem I [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-234" title="jsfl" src="http://www.lostinactionscript.com/blog/wp-content/uploads/2009/04/jsfl-300x300.jpg" alt="jsfl" width="300" height="300" />It's embarrassing but until the other week I hadn't a reason to do anything (beyond tinkering) with JSFL. JSFL can be especially useful for simplifying or automating tasks in the Flash IDE and that isn't breaking news. I think I understand why I haven't been using JSFL too much until recently. The major problem I discovered is the documentation is very poor, if you search JSFL you get exactly <a href="http://help.adobe.com/en_US/Flash/10.0_UsingFlash/search.html?gsa=1&amp;q=JSFL">diddly squat</a> on how to use JSFL. And alas Googling JSFL aint much better with the term "JSFL Reference" the only adobe link is <a href="http://livedocs.adobe.com/flash/mx2004/main_7_2/wwhelp/wwhimpl/js/html/wwhelp.htm?href=Part_JSAPI.html">this one</a>. Considering this help reference is 5 years old doesn't inflate confidence in learning the latest and greatest JSFL has to offer - this is really pathetic Adobe. If someone can find an official decent resource on JSFL it would be appreciated, SURELY that isn't it :) <del datetime="2009-04-08T14:50:43+00:00">So despite not being able to find a great JSFL reference</del> Eventually I was referred to this <a href="http://help.adobe.com/en_US/Flash/10.0_ExtendingFlash/index.html">great JSFL reference</a>. The JSFL script I needed to write was really quite basic and for Actionscript developers writing JSFL it is very familiar territory so I was somehow blindly confident.</p>
<p>So I will describe the usefulness of this JSFL script by first explaining the task or problem at hand it solved for me and hopefully you find it useful also.</p>
<h1>The Problem</h1>
<p>I had a rather complex vector map (12 MB) in a SWF. Embedding the whole map would be obviously be a BAD idea for loading times but fortunately only very small portions of this map had to be used at any time. Though the suker punch to this idea is that the map isn't grouped to these portions - sigh.</p>
<h1>The Solution</h1>
<p>So I started with some unavoidable and rather laborious instance naming grinding which I did within Flash. Once I had completed this I had literally 100's of Movieclips associated to Classes that needed to be published and when I hit this I  realised - JSFL I love you! So I distributed these MovieClips to layers then ran this script and viola all the layers are published as swfs using the layer name as the published SWF name - ba da boom ching :)</p>
<p>The way this script works is that publishes any layer that isn't a folder or a guide on the main timeline. Then sets all the layers to guides, then loops through the layers desired to be outputted to SWF then changes them to a normal layer so that only this layer is the only one in the published SWF. Once the publish loop is completed all layers are then set back to their original states.</p>
<p>Rather simple I thought and a huge time saver for mindless SWF publishing. To run this JSFL simply double click it or drag it onto Flash then you will be prompted to select the output directory. Then sit back, relax or even take the evening off and tell your project manager you're hard at work!</p>
<p>You can <a href="http://code.google.com/p/lostinactionscript/source/browse/trunk/jsfl/Export%20Layers%20As%20SWFs.jsfl">view the source</a> or <a href="http://lostinactionscript.googlecode.com/files/Export%20Layers%20As%20SWFs.zip">download this script here</a> - get it while it's hot!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lostinactionscript.com/blog/index.php/2009/04/03/export-layers-to-swf-with-jsfl/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>FITC Pixel Bender Source Code</title>
		<link>http://www.lostinactionscript.com/blog/index.php/2009/02/26/fitc-pixel-bender-source-code/</link>
		<comments>http://www.lostinactionscript.com/blog/index.php/2009/02/26/fitc-pixel-bender-source-code/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 17:06:46 +0000</pubDate>
		<dc:creator>Shane McCartney</dc:creator>
				<category><![CDATA[Interesting]]></category>

		<guid isPermaLink="false">http://www.lostinactionscript.com/blog/?p=202</guid>
		<description><![CDATA[In my efficiency FITC talk I covered some topics regarding programmatically rendering to the DisplayList - efficiently and practically. This covered some simple examples showing what can be done in PixelBender with Shaders including blendModes, lighting effects and transitions. If you would like the source code for these examples you can get them from my [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.lostinactionscript.com/blog/wp-content/uploads/2009/02/bender-300x291.png" alt="bender" title="bender" width="300" height="291" class="alignnone size-medium wp-image-204" />In my efficiency FITC talk I covered some topics regarding programmatically rendering to the DisplayList - efficiently and practically. This covered some simple examples showing what can be done in PixelBender with Shaders including blendModes, lighting effects and transitions. If you would like the source code for these examples you can get them from my <a href="http://code.google.com/p/lostinactionscript/source/browse/#svn/trunk/shaders">code.google repository</a>. </p>
<p>These shader examples only represent a taste of what's possible using Shaders but I think what's most important is to note these shader examples are really practical unlike a lot of the psychedelic effects you may of seen. For me I especially found that introducing more blend modes has made the process of matching designs in Flash a whole lot easier. I will shortly post a complete list of brand spanking new blend modes for Flash via Shaders with open source code so that everyone can take advantage of these blend modes.</p>
<div class="clear"></div>
]]></content:encoded>
			<wfw:commentRss>http://www.lostinactionscript.com/blog/index.php/2009/02/26/fitc-pixel-bender-source-code/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Compiling Shader SWCs with ANT build-files</title>
		<link>http://www.lostinactionscript.com/blog/index.php/2009/02/25/compiling-shader-swcs-with-ant-build-files/</link>
		<comments>http://www.lostinactionscript.com/blog/index.php/2009/02/25/compiling-shader-swcs-with-ant-build-files/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 23:14:19 +0000</pubDate>
		<dc:creator>Shane McCartney</dc:creator>
				<category><![CDATA[Interesting]]></category>
		<category><![CDATA[Source]]></category>

		<guid isPermaLink="false">http://www.lostinactionscript.com/blog/?p=182</guid>
		<description><![CDATA[In my talk I briefly introduced the concept of using Flex to compile to a SWC containing Shaders. If you've used Shaders it's rather annoying you have to load in an exported Shader .pbj file at runtime before you can use a Shader. I really like the idea of having my shaders in a SWC [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.lostinactionscript.com/blog/wp-content/uploads/2009/02/ant-activities-5-300x220.jpg" alt="Cool Ant" title="Cool Ant" width="300" height="220" class="alignnone size-medium wp-image-193" />In my talk I briefly introduced the concept of using Flex to compile to a SWC containing Shaders. If you've used Shaders it's rather annoying you have to load in an exported Shader .pbj file at runtime before you can use a Shader. I really like the idea of having my shaders in a SWC to get around this problem. But this is also useful as a means to distribute your Shaders especially for the Shaders I use often like custom blendModes and some filter effects.</p>
<p>I usually compile SWCs via an ANT buildfile in Eclipse and I will provide this handy script to you as open source code. I like using ANT because it makes it very easy for me to automate the task of creating SWCs then even carrying out other tasks like FTPing. </p>
<p>As well as compiling SWCs and SWFs using ANT I also often publish documentation using these build-files and as my FITC talk briefly covered Javadoc in regard to 'coding conventions' I will also include the source code for how to convert your <a href="http://java.sun.com/j2se/javadoc/writingdoccomments/">Javadoc notation</a> to HTML documentation using Flex with asdoc via an ANT build-file.</p>
<p>But before you use these ANT build-files it's important to mention you will need to setup up the appropriate .prefs file to match particular variables to your system.</p>
<p>Here is an example which demonstrates the .prefs file for the SWC ANT build-file</p>
<div class="igBar"><span id="lcode-15"><a href="#" onclick="javascript:showPlainTxt('code-15'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-15">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">compc &nbsp; &nbsp; =/Applications/Flex SDK <span style="color:#800000;color:#800000;">4</span>/bin/compc</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">src&nbsp; &nbsp; &nbsp;&nbsp;=/classes</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">outputFile &nbsp;=/swc/TheSWC.<span style="">swc</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Here is the code you may like to use as a reference to compiling your Shader files into a swc</p>
<div class="igBar"><span id="lcode-16"><a href="#" onclick="javascript:showPlainTxt('code-16'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-16">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">package <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; import flash.<span style="">display</span>.<span style="">Shader</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; import flash.<span style="">utils</span>.<span style="">ByteArray</span>;&nbsp; &nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; public class Shaders <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>Embed<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"RippleTransition.pbj"</span>, mimeType=<span style="color:#CC0000;">"application/octet-stream"</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; private static var RippleTransitionData : Class;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>Embed<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"Bloom.pbj"</span>, mimeType=<span style="color:#CC0000;">"application/octet-stream"</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; private static var BloomData : Class;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>Embed<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"BlendModeSoftlight.pbj"</span>, mimeType=<span style="color:#CC0000;">"application/octet-stream"</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; private static var SoftLightBlendModeData : Class;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// Transitions</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; public static var rippleTransition : Shader;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//Lighting</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; public static var bloom : Shader;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//BlendModes</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; public static var softLightBlendMode : Shader;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; protected static var inited : Boolean = init<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; private static function init<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> : Boolean <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rippleTransition = new Shader<span style="color:#006600; font-weight:bold;">&#40;</span>new RippleTransitionData<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> as ByteArray<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bloom = new Shader<span style="color:#006600; font-weight:bold;">&#40;</span>new BloomData<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> as ByteArray<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; softLightBlendMode = new Shader<span style="color:#006600; font-weight:bold;">&#40;</span>new SoftLightBlendModeData<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> as ByteArray<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return true;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Download the <a href="http://www.flashdynamix.com/downloads/Ant_SWC_AsDoc.zip">handy ANT buildfiles here</a></p>
<p>If you are interested in writing your own ANT build files read up about this <a href="http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.platform.doc.user/gettingStarted/qs-81_basics.htm">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lostinactionscript.com/blog/index.php/2009/02/25/compiling-shader-swcs-with-ant-build-files/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>FITC Amsterdam Presentation</title>
		<link>http://www.lostinactionscript.com/blog/index.php/2009/02/25/fitc-amsterdam-presentation/</link>
		<comments>http://www.lostinactionscript.com/blog/index.php/2009/02/25/fitc-amsterdam-presentation/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 13:08:17 +0000</pubDate>
		<dc:creator>Shane McCartney</dc:creator>
				<category><![CDATA[Interesting]]></category>

		<guid isPermaLink="false">http://www.lostinactionscript.com/blog/?p=176</guid>
		<description><![CDATA[Thanks for all those who attended my FITC talk 'Efficient Programming Practices for AS3'. I had nightmares hardly anyone would show up but instead the venue was packed with a special mention to the support from the lads at Agency Republic crew - much appreciated! 
Despite some early nerves (which I thank you for baring [...]]]></description>
			<content:encoded><![CDATA[<p>Thanks for all those who attended my FITC talk 'Efficient Programming Practices for AS3'. I had nightmares hardly anyone would show up but instead the venue was packed with a special mention to the support from the lads at Agency Republic crew - much appreciated! </p>
<p>Despite some early nerves (which I thank you for baring with) the talk covered a lot of practical information regarding efficiency and Actionscript. It's actually the first time I've attended an exclusively Flash conference and 'god damn' I talked at it - pretty cool or terrifying. </p>
<p>If you would like to ask me questions regarding my presentation feel free to do so by email. You can also find out more about my presentation <a href="http://www.lostinactionscript.com/talks/">here</a> including references and source code examples.</p>
<p>Lastly I would like to thank Shawn Pucknell the organizer of the FITC. I think everyone who attended would agree that him and his crew have done a fantastic job. He even had time to give me some presentation pointers just before I went up - so thanks mate for going an extra mile. Maybe next time I won't drop the microphone ;)</p>
<p><iframe src='http://docs.google.com/EmbedSlideshow?docid=d4jrvds_0hjb794hr' frameborder='0' width='410' height='342'></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lostinactionscript.com/blog/index.php/2009/02/25/fitc-amsterdam-presentation/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Tweensy goes public</title>
		<link>http://www.lostinactionscript.com/blog/index.php/2009/01/05/tweensy-goes-public/</link>
		<comments>http://www.lostinactionscript.com/blog/index.php/2009/01/05/tweensy-goes-public/#comments</comments>
		<pubDate>Sun, 04 Jan 2009 23:20:34 +0000</pubDate>
		<dc:creator>Shane McCartney</dc:creator>
				<category><![CDATA[Interesting]]></category>
		<category><![CDATA[Source]]></category>

		<guid isPermaLink="false">http://www.lostinactionscript.com/blog/?p=125</guid>
		<description><![CDATA[I know it's late but better late than never, Tweensy just turned 0.2 and is now available as a public beta. In this release Tweensy has been split into the 2 flavors Zero and Original and has an expansion FX package.
I've been spending quite a while tightening all the bolts in Tweensy and to get [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.flashdynamix.com/blog/wp-content/uploads/2008/08/tweensy.jpg" alt="" />I know it's late but better late than never, Tweensy just turned 0.2 and is now available as a public beta. In this release Tweensy has been split into the 2 flavors Zero and Original and has an expansion FX package.</p>
<p>I've been spending quite a while tightening all the bolts in Tweensy and to get it as efficient and feature packed as possible and its paid off. I've managed to get Tweensy to run <a href="http://www.flashdynamix.com/examples/Tweensy/0.2/SuperRenderTweenTest.html">much faster</a> than the previous fastest AS3 Tween engine which was TweenLite/TweenMax - wowzas! </p>
<p>Tweensy gets this performance boost compared to other tween engines because #1 it's type safe, has an option to use <a href="http://www.lostinactionscript.com/blog/index.php/2008/10/30/object-pooling-in-as3/">Object Pooling</a> and utilizes a <a href="http://en.wikipedia.org/wiki/Linked_list">DoubleLinked list</a> rather than a Dictionary or Array. The final method you can use for speed improvement in Tweensy is by rendering through a BitmapLayer using TweensyFX which circumnavigates the DisplayList and this most often provides a higher frame rate at the penalty of using more RAM - but I think that's acceptable. </p>
<p>Tweensy is type safe due to a collection of tween plugins which allow for targetting  commonly tweened Objects such as MovieClip, DisplayObjects, ColorTransforms etc. This means creating new plugins for example Papervision's DisplayObject3D very easy,  so DisplayObject3D could benefit from the performance of Tweensy property tweening as well. But regardless of this a fallback plugin allows for Tweensy to tween any public property for any Object.</p>
<p>But don't think Tweensy is just an efficient tween engine it's also feature packed to rival (or beat in my opinion) any other AS3 tween engine available today. And anything it doesn't fulfill feel free to <a href="http://code.google.com/p/tweensy/issues/list">feature request it</a>. I've taken some time to write up a wiki page to help users <a href="http://code.google.com/p/tweensy/wiki/GettingStarted">get started</a>. As well every method and class is commented so you should be able to use the <a href="http://docs.flashdynamix.com/tweensy/fx/">documentation</a> files to find out exactly what's contained within Tweensy library very easily. But if you're new to using a tween library I recommend you to read the getting started wiki page.</p>
<p>Not only is Tweensy feature packed and more efficient than other tween engines, TweensyZero weighs in at about 2.9KB making it an ideal product to use in banners - where every KB counts.</p>
<p>Tweensy also allows for tweening along <a href="http://code.google.com/p/tweensy/wiki/MotionGuides">complicated motion guides</a> otherwise known as bezier curves. One thing that particularly annoyed me while using other tween engines is that the algorithim used for tweening a bezier curve resulted in the DisplayObject accelerating and decelerating as the curve distance  increased and decreased. All completely regardless of the ease equation used! You'll get no such problem with Tweensy which gives precise control over tweening on a bezier curve. Other motion guides included in Tweensy include direction and orbit which are cool also but I won't go into any detail as the link above has more information on motion guides with Tweensy.</p>
<p>The Tweensy syntax is very similar to other tween engines and like the great AS2 tween engine FuseKit, Tweensy offers a series of methods which makes tweening otherwise complicated Objects easy. These methods include matrixTo, colorTransformTo, filterTo, functionTo, brightnessTo and contrastTo to name a few. Regardless of these methods the built-in to, from and fromTo methods provide the functionality of these functions - they are there purely for coding convenience. For example using Tweensy for tweening Matrices, ColorTransforms and SoundTransforms then applying them onto other Objects is quite easy. </p>
<div class="igBar"><span id="lactionscript-19"><a href="#" onclick="javascript:showPlainTxt('actionscript-19'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-19">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">import</span> com.<span style="color: #006600;">flashdynamix</span>.<span style="color: #006600;">motion</span>.<span style="color: #006600;">Tweensy</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">geom</span>.<span style="color: #006600;">Matrix</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> mtx:Matrix = myInstance.<span style="color: #006600;">transform</span>.<span style="color: #006600;">matrix</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mtx.<span style="color: #006600;">tx</span> = <span style="color: #cc66cc;color:#800000;">200</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mtx.<span style="color: #006600;">ty</span> = <span style="color: #cc66cc;color:#800000;">200</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Tweensy.<span style="color: #006600;">to</span><span style="color: #66cc66;">&#40;</span>myInstance.<span style="color: #006600;">transform</span>.<span style="color: #006600;">matrix</span>, mtx, <span style="color: #cc66cc;color:#800000;">2</span>.<span style="color: #cc66cc;color:#800000;">0</span>, <span style="color: #000000; font-weight: bold;">null</span>, <span style="color: #cc66cc;color:#800000;">0</span>, myInstance<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Further to this I will quickly introduce the method functionTo, it is particularly useful if tweening the width and height of a component of some type which requires this to be done via a setSize method. </p>
<div class="igBar"><span id="lactionscript-20"><a href="#" onclick="javascript:showPlainTxt('actionscript-20'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-20">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">import</span> com.<span style="color: #006600;">flashdynamix</span>.<span style="color: #006600;">motion</span>.<span style="color: #006600;">TweensyGroup</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> tween:TweensyGroup = <span style="color: #000000; font-weight: bold;">new</span> TweensyGroup<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">onUpdate</span>:<span style="color: #000000; font-weight: bold;">Function</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>current:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; pane.<span style="color: #006600;">setSize</span><span style="color: #66cc66;">&#40;</span>current.<span style="color: #0066CC;">width</span>, current.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">tween.<span style="color: #006600;">functionTo</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">width</span>:pane.<span style="color: #006600;">paneWidth</span>, <span style="color: #0066CC;">height</span>:pane.<span style="color: #006600;">paneHeight</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">width</span>:<span style="color: #cc66cc;color:#800000;">200</span>, <span style="color: #0066CC;">height</span>:<span style="color: #cc66cc;color:#800000;">200</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #0066CC;">onUpdate</span>, <span style="color: #cc66cc;color:#800000;">1</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Further to these cool features Tweensy offers an <a href="http://code.google.com/p/tweensy/wiki/AdvancedTween">extras package</a> containing classes to assist with matrix math for Transformations and ColorMatrixFilters. The MatrixTransform class allows for tweening transformations of skewX,skewY around a defined registration X and Y. While the ColorMatrix class allows for applying color transform effects such as brightness, contrast, threshold, colorize etc.</p>
<p>Though I hadn't mentioned it much above, TweensyFX hasn't gone without a few improvements these effects include <a href="http://www.flashdynamix.com/examples/Tweensy/0.2/bumpMapFX.html">Bump Mapping</a>, <a href="http://www.flashdynamix.com/examples/Tweensy/0.2/bulgeFX.html">Bulge(dent/indent)</a>, <a href="http://www.flashdynamix.com/examples/Tweensy/0.2/pixelateFX.html">pixelation</a>, rgb channel splitting, scan lines and reflection. These FX are mostly low hanging fruit so more exciting effects are to come. In case I hadn't mentioned it somewhere TweensyFX also allows the efficient drawing to a vector layer. As well tweening complicated vector elements such as curves, lines and gradients. This combined with the effects which can be applied onto a BitmapLayer in TweensyFX can result in some really nice results.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_lineFX_1221927987"
			class="flashmovie"
			width="550"
			height="400">
	<param name="movie" value="http://www.flashdynamix.com/examples/Tweensy/0.2/lineFX.swf" />
	<param name="bgcolor" value="#171313" />
	<param name="allowscriptaccess" value="sameDomain" />
	<param name="allowfullscreen" value="true" />
	<param name="allownetworking" value="all" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.flashdynamix.com/examples/Tweensy/0.2/lineFX.swf"
			name="fm_lineFX_1221927987"
			width="550"
			height="400">
		<param name="bgcolor" value="#171313" />
		<param name="allowscriptaccess" value="sameDomain" />
		<param name="allowfullscreen" value="true" />
		<param name="allownetworking" value="all" />
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>I hope you enjoy Tweensy, I and everyone I have introduced it to are, as well those involved in the private beta who have provided great feedback - thankyou. TweensyFX is now the product I will focus on now I consider the Tweensy Original product is maturing nicely. Which is a great stage for this project and for me because this is work I find more  exciting.</p>
<p>As well as this update to Tweensy, I have been hard at work (in my limited spare time) on a AIR product code named 'Mr Sprite' which will support TweensyFX with sprite map animations. Mr Sprite can import or create a sprite sheet from a sprite sequence. Then allows for you to define animations sequences on the sprite sheet which can then easily be imported into Flash as a ByteArray at run-time or author-time. With Mr Sprite it will allow you to apply pre-rendered effects with dynamically generated ones at ease in an extremely optimized and efficient manner. I will try to get some examples and a private beta setup for this project soon.</p>
<p>Get Tweensy before it takes over the world at its new home on <a href="http://code.google.com/p/tweensy/">code.google</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lostinactionscript.com/blog/index.php/2009/01/05/tweensy-goes-public/feed/</wfw:commentRss>
		<slash:comments>37</slash:comments>
		</item>
		<item>
		<title>Tips on how to write efficient AS3 – part 2</title>
		<link>http://www.lostinactionscript.com/blog/index.php/2008/11/01/tips-on-how-to-write-efficient-as3-part-2/</link>
		<comments>http://www.lostinactionscript.com/blog/index.php/2008/11/01/tips-on-how-to-write-efficient-as3-part-2/#comments</comments>
		<pubDate>Sat, 01 Nov 2008 10:02:00 +0000</pubDate>
		<dc:creator>Shane McCartney</dc:creator>
				<category><![CDATA[Interesting]]></category>

		<guid isPermaLink="false">http://www.lostinactionscript.com/blog/?p=81</guid>
		<description><![CDATA[As a continuation from my last post regarding AS3 and performance here are some more tips I found interesting.
Array push vs. Array index
Don't use the push function on an Array instead use the Array length property and set on the Array like so list[list.length] = data; Or if that's not enough for the best performance [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.lostinactionscript.com/blog/wp-content/uploads/2009/02/robot-calculator.jpg" alt="robot-calculator" title="robot-calculator" width="234" height="240" class="alignnone size-full wp-image-197" />As a continuation from my <a href="http://www.lostinactionscript.com/blog/index.php/2008/09/28/tips-on-how-to-write-efficient-as3/">last post</a> regarding AS3 and performance here are some more tips I found interesting.</p>
<h4>Array push vs. Array index</h4>
<p>Don't use the push function on an Array instead use the Array length property and set on the Array like so <code>list[list.length] = data;</code> Or if that's not enough for the best performance (about 600% faster) than using push don't use the Array length property at all. To do this keep the Array length as an external variable and increment/decrement it as you add and remove items from the Array.</p>
<h4>Array emptying - length 0 vs. A new Array</h4>
<p>If you need to empty an Array there is a handy option to do this via setting the Arrays property length to 0. You would think this would be the better option as you are avoiding creating a new Array and ultimately saving memory. Though it's interesting to know as a trade off using length to clear an Array is not faster in performance (in most cases). Using length is more efficient when you might need to clear more than 510 Arrays in a single execution, otherwise creating a new Array via [] is the faster option again.</p>
<h4>Var declarations on multiple lines vs. Var declarations on a single line</h4>
<p>If you need to declare a few variables it's slightly more efficient to do so on a single line i.e.<br />
<code>var a:int=0, b:int=0, c:int=0; </code><br />
vs.<br />
<code>var a:int=0;<br />
var b:int=0;<br />
var c:int=0;</code></p>
<h4>Using Xor to swap variables</h4>
<p>Using Xor is very handy if you want to swap variables but don't want to create a third variable i.e.<br />
<code><br />
a = a^b;<br />
b = a^b;<br />
a = a^b;</code><br />
Like most people I thought this would be more efficient but it's not compared to creating a third variable and then doing the swap. In fact it's about 300% more efficient to do the swap this way. Though honestly I still have a soft spot for the Xor method.<br />
<code><br />
var oldB:int = b;<br />
b = a;<br />
a = oldB;<br />
</code></p>
<h4>Multiplication vs. Division</h4>
<p>When working with Math in Actionscript multiplications seem to always run faster than divisions so instead of <code>5000/1000</code> use <code>5000*0.001</code> it's about 130% faster.</p>
<h4>Type casting comparison</h4>
<p>When type casting the keyword <code>as</code> is 250% more efficient than casting by <code>Type(item);</code> Though surprisingly not using either is about 1400% more efficient.</p>
<h4>Long vs Short variable names</h4>
<p>Though this one is debatable because it results in illegible code. Shortened variable names do give a millisecond or so improvement if iterating many 1,000's of times in a single loop. Though I think this is a last resort in code optimization as the differences are really marginal.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lostinactionscript.com/blog/index.php/2008/11/01/tips-on-how-to-write-efficient-as3-part-2/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>Object Pooling in AS3</title>
		<link>http://www.lostinactionscript.com/blog/index.php/2008/10/30/object-pooling-in-as3/</link>
		<comments>http://www.lostinactionscript.com/blog/index.php/2008/10/30/object-pooling-in-as3/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 01:15:13 +0000</pubDate>
		<dc:creator>Shane McCartney</dc:creator>
				<category><![CDATA[Interesting]]></category>

		<guid isPermaLink="false">http://www.lostinactionscript.com/blog/?p=83</guid>
		<description><![CDATA[If you're looking to save memory overhead and increase performance in your Flash creations then implementing the design pattern of Object Pooling is a great place to start. Object Pooling is most beneficial when the cost of construction is high or the frequency of construction is high.
Though it has to be known Object Pooling is [...]]]></description>
			<content:encoded><![CDATA[<p>If you're looking to save memory overhead and increase performance in your Flash creations then implementing the design pattern of Object Pooling is a great place to start. Object Pooling is most beneficial when the cost of construction is high or the frequency of construction is high.</p>
<p>Though it has to be known Object Pooling is not a silver bullet. There are definitely pitfalls to Object Pooling this most of all includes cleaning the Object for reuse. I'll get back to this in just a moment but first I have to talk about Object Pools generally.</p>
<p>In short an Object Pool allows you to retrieve an instance of a particular type of Object by checking it in and out of a resource pool. The concept of checking in and out resources is very consistent when using an Object Pool. Though handling the situation when a pool is empty is not.</p>
<h5>There are three approaches I will talk about when handling an empty pool :</h5>
<h4>1) The Unbounded Pool</h4>
<p> The pool has a boundless size and Objects are added as required to the resource pool on check out. This ensures that an Object will always be returned on check out.</p>
<h4>2) The Capped Pool</h4>
<p> The pool has a constant size and the resource pool is populated during the construction of the pool. This allows you to have all the memory overhead in the pool construction and not during check out. Though when check outs occur to an empty pool it won't return an Object.</p>
<h4>3) The Queue Pool</h4>
<p> The pool has a minimum size and the resource pool is populated during construction like option 1 it has the benefit of a maximum size - allowing the pool to grow. Unlike option 2 when the pool's maximum size or flood limit is reached and a check out occurs on an empty pool then this request is queued. Requests in the queue will be eventually dropped if not fulfilled within a defined timeout or alternatively resolved once an Object is checked in. This doesn't guarantee that the check out will be fulfilled by the Object Pool but does ensure that pools don't grow uncontrollably and when they reach flood limits that the next fulfilled check out should be the last.</p>
<p>Each of these approaches to controlling the resource pool size have unique benefits and the option you choose depends on how size matters :). Lets say in one scenario that Object memory allocation  is inexpensive and having 1,000's to even 10,000's of Objects is no big deal then option 1 is a good choice. Especially considering it's simple and reliable. Though in another scenario where the same number of Objects are checked in as out and as a safe guard when a checkout occurs on an empty pool it can be suppressed then option 2 is a good choice. And doubly so considering a lot of the memory overhead of Object construction is on the Object Pool constructor and the pool will never grow out of your control. Though lastly if you can't suppress check outs on empty pools and the next Object checkout should be the last one and you need to limit your pool size due to the Objects being expensive then option 3 is more than likely the best approach for you.</p>
<p>Now I'll get back to Object cleaning, this sets an Object to the state it was in after construction which is important because check out is a replacement for constructing anew. The scenario when dirty Objects are added into the resource pool is often known as a cesspool and is considered an anti-pattern but honestly it's up to you to wether this worries you or not. Though in regard to Object cleaning it's also important to note this is where a clear pitfall emerges. If the process of cleaning is more expensive than construction then you should really consider not using an Object Pool.</p>
<p>If Object cleaning is important to you it gets interesting when consider the time and place to do this in your Object Pool class. It would seem logical to clean the Object within the check in method to ensure a cesspool never occurs. Though this could limit the Object Pool to containing a specific type of Object. This is because cleaning an Object is almost always subjective to type i.e. cleaning a DisplayObject is different to cleaning a BitmapData. Then thinking about this problem further the solution is "be kind rewind" - so the checkinee must clean before checkin. Problem solved.</p>
<p>And with every problem tackled there is another to solve. Creating an Object is also subjective to type due to parameters it may require in construction :( Unfortunately there isn't as ideal way to construct a Class with a dynamic number of parameters in Actionscript like function.apply offers for Functions. The simplest and most effective solution to this is once again the create process is external also. Another problem solved  - hopefully that's all :)</p>
<p>So now that's enough talk on Object Pool's and hopefully it's given you some points to consider when creating your own Object Pool class. There's an example below demonstrating the Object Pool concepts I've used and discussed above and has a small performance victory. What this example demonstrates is the performance cost in reinitializing the particle effect constantly. As you will see there is quite a noticeable difference between pooling or not but when you compare one pool concept over another there's not much difference other than size handling features they offer which could save you performance.</p>
<p>If you would like to download the source code used in this example you can do so <a href="http://code.google.com/p/lostinactionscript/source/browse/#svn/trunk/library/com/lia/utils">here</a></p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_Object Pool_415901875"
			class="flashmovie"
			width="550"
			height="400">
	<param name="movie" value="http://www.flashdynamix.com/blog/wp-content/swf/ClickToPlay.swf?url=http://www.flashdynamix.com/blog/wp-content/swf/Object Pool.swf" />
	<param name="bgcolor" value="#171313" />
	<param name="allowscriptaccess" value="sameDomain" />
	<param name="allowfullscreen" value="true" />
	<param name="allownetworking" value="all" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.flashdynamix.com/blog/wp-content/swf/ClickToPlay.swf?url=http://www.flashdynamix.com/blog/wp-content/swf/Object Pool.swf"
			name="fm_Object Pool_415901875"
			width="550"
			height="400">
		<param name="bgcolor" value="#171313" />
		<param name="allowscriptaccess" value="sameDomain" />
		<param name="allowfullscreen" value="true" />
		<param name="allownetworking" value="all" />
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
]]></content:encoded>
			<wfw:commentRss>http://www.lostinactionscript.com/blog/index.php/2008/10/30/object-pooling-in-as3/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Simple rotation problem</title>
		<link>http://www.lostinactionscript.com/blog/index.php/2008/10/20/simple-rotation-problem/</link>
		<comments>http://www.lostinactionscript.com/blog/index.php/2008/10/20/simple-rotation-problem/#comments</comments>
		<pubDate>Sun, 19 Oct 2008 14:34:02 +0000</pubDate>
		<dc:creator>Shane McCartney</dc:creator>
				<category><![CDATA[Interesting]]></category>

		<guid isPermaLink="false">http://www.lostinactionscript.com/blog/?p=82</guid>
		<description><![CDATA[It's been odd though this week I've been asked about this rotation problem a few times, so it's likely this may help others. This problem occurs when tweening rotation and the visual bug is that it's not using the smallest rotation direction.
To reproduce this rotation problem or visual glitch it seems to only occur when [...]]]></description>
			<content:encoded><![CDATA[<p>It's been odd though this week I've been asked about this rotation problem a few times, so it's likely this may help others. This problem occurs when tweening rotation and the visual bug is that it's not using the smallest rotation direction.</p>
<p>To reproduce this rotation problem or visual glitch it seems to only occur when the target angle is after PI and the current angle is before (and vice versa). To fix this is quite simple and it's also interesting to see other peoples different mathematical approaches to solving this common problem, I've seen a few and a fix is a fix but here's mine.</p>
<p>Below is an broken down version of the equation I've used to solve this problem where cA is your current radians and tA is your desired radians.</p>
<div class="igBar"><span id="lactionscript-25"><a href="#" onclick="javascript:showPlainTxt('actionscript-25'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-25">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> diff:<span style="color: #0066CC;">Number</span> = tA-cA;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">pi</span>:<span style="color: #0066CC;">Number</span> = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> pi2:<span style="color: #0066CC;">Number</span> = <span style="color: #0066CC;">pi</span>*<span style="color: #cc66cc;color:#800000;">2</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">tA += <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">abs</span><span style="color: #66cc66;">&#40;</span>diff<span style="color: #66cc66;">&#41;</span> &lt;pi<span style="color: #66cc66;">&#41;</span> ? <span style="color: #cc66cc;color:#800000;">0</span> : <span style="color: #66cc66;">&#40;</span>diff&gt;<span style="color: #cc66cc;color:#800000;">0</span><span style="color: #66cc66;">&#41;</span> ? -pi2 : pi2; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Though this equation can easily be done in a single line which is my preference.</p>
<div class="igBar"><span id="lactionscript-26"><a href="#" onclick="javascript:showPlainTxt('actionscript-26'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-26">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">tA += <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">abs</span><span style="color: #66cc66;">&#40;</span>tA-cA<span style="color: #66cc66;">&#41;</span> &lt;Math.<span style="color: #0066CC;">PI</span><span style="color: #66cc66;">&#41;</span> ? <span style="color: #cc66cc;color:#800000;">0</span> : <span style="color: #66cc66;">&#40;</span>tA-cA&gt;<span style="color: #cc66cc;color:#800000;">0</span><span style="color: #66cc66;">&#41;</span> ? -<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span>*<span style="color: #cc66cc;color:#800000;">2</span> : <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span>*<span style="color: #cc66cc;color:#800000;">2</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Also further to this it's important that the cA and the tA be normalized so they are not greater than Math.PI*2 or less than -Math.PI*2, if you're not sure then this equation will sort this out for you.</p>
<div class="igBar"><span id="lactionscript-27"><a href="#" onclick="javascript:showPlainTxt('actionscript-27'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-27">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">cA = <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">abs</span><span style="color: #66cc66;">&#40;</span>cA<span style="color: #66cc66;">&#41;</span>&gt;pi2<span style="color: #66cc66;">&#41;</span> ? <span style="color: #66cc66;">&#40;</span>cA&lt;<span style="color: #cc66cc;color:#800000;">0</span><span style="color: #66cc66;">&#41;</span> ? cA%pi2+ pi2 : cA%pi2 : cA;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">tA = <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">abs</span><span style="color: #66cc66;">&#40;</span>tA<span style="color: #66cc66;">&#41;</span>&gt;pi2<span style="color: #66cc66;">&#41;</span> ? <span style="color: #66cc66;">&#40;</span>tA&lt;<span style="color: #cc66cc;color:#800000;">0</span><span style="color: #66cc66;">&#41;</span> ? tA%pi2+ pi2 : tA%pi2 : tA; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>I also understand some people may not prefer to be using the unit radians to express an angle. If this is you then it's really no problem at all, just make sure cA and tA are in degrees and exchange Math.PI to the equivalent degrees value of 180.</p>
<div class="igBar"><span id="lactionscript-28"><a href="#" onclick="javascript:showPlainTxt('actionscript-28'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-28">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">tA += <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">abs</span><span style="color: #66cc66;">&#40;</span>tA-cA<span style="color: #66cc66;">&#41;</span> &lt;<span style="color: #cc66cc;color:#800000;">180</span><span style="color: #66cc66;">&#41;</span> ? <span style="color: #cc66cc;color:#800000;">0</span> : <span style="color: #66cc66;">&#40;</span>tA-cA&gt;<span style="color: #cc66cc;color:#800000;">0</span><span style="color: #66cc66;">&#41;</span> ? -<span style="color: #cc66cc;color:#800000;">180</span>*<span style="color: #cc66cc;color:#800000;">2</span> : <span style="color: #cc66cc;color:#800000;">180</span>*<span style="color: #cc66cc;color:#800000;">2</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>I have also included an example SWF below to better demonstrate this situation with and without the fix. To undo the fix change the radio button selection to 'normal' to see the error. In this example the green line is the target angle, the blue line is the current angle and the grey line is the location of PI or 180 degrees.<br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_simpleRotation_14478657"
			class="flashmovie"
			width="300"
			height="300">
	<param name="movie" value="http://www.flashdynamix.com/blog/wp-content/swf/simpleRotation.swf" />
	<param name="bgcolor" value="#171313" />
	<param name="allowscriptaccess" value="sameDomain" />
	<param name="allowfullscreen" value="true" />
	<param name="allownetworking" value="all" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.flashdynamix.com/blog/wp-content/swf/simpleRotation.swf"
			name="fm_simpleRotation_14478657"
			width="300"
			height="300">
		<param name="bgcolor" value="#171313" />
		<param name="allowscriptaccess" value="sameDomain" />
		<param name="allowfullscreen" value="true" />
		<param name="allownetworking" value="all" />
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
]]></content:encoded>
			<wfw:commentRss>http://www.lostinactionscript.com/blog/index.php/2008/10/20/simple-rotation-problem/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Flash In The Can 2009 Amsterdam</title>
		<link>http://www.lostinactionscript.com/blog/index.php/2008/10/11/flash-in-the-can-2009-amsterdam/</link>
		<comments>http://www.lostinactionscript.com/blog/index.php/2008/10/11/flash-in-the-can-2009-amsterdam/#comments</comments>
		<pubDate>Sat, 11 Oct 2008 06:45:25 +0000</pubDate>
		<dc:creator>Shane McCartney</dc:creator>
				<category><![CDATA[Interesting]]></category>

		<guid isPermaLink="false">http://www.lostinactionscript.com/blog/?p=80</guid>
		<description><![CDATA[A couple of weeks ago I was asked by Shawn Pucknell director of the FITC events to talk at the upcoming 2009 conference. I graciously accepted his offer with some degree of terror as I've not presented to a group of people quite as large as the FITC event attracts.
There's a great line-up and more [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.fitc.ca/speaker_list.cfm?festival_id=80"><img src="http://www.lostinactionscript.com/blog/wp-content/uploads/2008/11/fitc_am09_250x250_banner.jpg" alt="" title="Flash In The Can 2009 Amsterdam" width="250" height="250" /></a>A couple of weeks ago I was asked by Shawn Pucknell director of the FITC events to talk at the upcoming 2009 conference. I graciously accepted his offer with some degree of terror as I've not presented to a group of people quite as large as the FITC event attracts.</p>
<p>There's a great line-up and more importantly a diversity of presenters from David Carson to Joshua Davis, so I think there will be something for everyone.</p>
<p>My talk will be on 'Efficient programming practices in AS3' and this does sound like the title of a quite dusty and dull book. When I proposed this talk among others (as he wanted a few ideas) to Shawn I had these awful visions of someone ranting for what might seem a lifetime by analysing Actionscript syntax examples to get across what might be an interesting point but instead emptyied the room. So in order to make this topic fun and information packed I will present these concepts visually by the well used practice of analogies. The format of the visuals I can't say yet but don't get your hopes up on some song and dance routine.</p>
<p>The talk is going to be really exciting and challenging for me, so that any one who knows a little Actionscript can get at least one takeaway. Enough said, for a line-up of the <a href="http://www.fitc.ca/speaker_list.cfm?festival_id=80">speakers</a> or <a href="http://www.fitc.ca/presentation_list.cfm?festival_id=80">presentations</a> follow the links and hope to see you in Feb 2009.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lostinactionscript.com/blog/index.php/2008/10/11/flash-in-the-can-2009-amsterdam/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
