<?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>Lambda &#187; ActionScript</title> <atom:link href="http://sroucheray.org/blog/category/actionscript/feed/" rel="self" type="application/rss+xml" /><link>http://sroucheray.org/blog</link> <description>Stephane Roucheray's trivial work and thoughts</description> <lastBuildDate>Sun, 27 Jun 2010 13:30:08 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.0</generator> <item><title>Photoshop Blend Modes available in Flash</title><link>http://sroucheray.org/blog/2010/06/photoshop-blend-modes-available-in-flash/</link> <comments>http://sroucheray.org/blog/2010/06/photoshop-blend-modes-available-in-flash/#comments</comments> <pubDate>Sun, 27 Jun 2010 13:27:19 +0000</pubDate> <dc:creator>Stéphane Roucheray</dc:creator> <category><![CDATA[ActionScript]]></category> <category><![CDATA[Pixel Bender]]></category><guid
isPermaLink="false">http://sroucheray.org/blog/?p=737</guid> <description><![CDATA[22 Photoshop blend modes available to Flash thanks to Pixel Bender. Plus, the source code is available as open source license !]]></description> <content:encoded><![CDATA[<h3>Short story</h3><p>For those who don&#8217;t want to read the full story, the source code for Photoshop blend modes ported to Flash with pixel bender kernels is available here : <a
href="http://github.com/sroucheray/sroucheray-as3/tree/master/pixelbender/blend_mode/">http://github.com/sroucheray/sroucheray-as3/tree/master/pixelbender/blend_mode/</a>.</p><h3>Long story</h3><p>If you are a Flash developer or designer you know that <a
href="http://help.adobe.com/en_US/flash/cs/using/WSd60f23110762d6b883b18f10cb1fe1af6-7d5ca.html">Flash blend modes</a> exist but are far less rich than <a
href="http://help.adobe.com/en_US/photoshop/cs/using/WSfd1234e1c4b69f30ea53e41001031ab64-77e9a.html">Photoshop blend modes</a>. Thus, it&#8217;s been a while that I developed <a
href="http://www.adobe.com/devnet/pixelbender/">Pixel Bender</a> kernels to mimic Photoshop blend modes in Flash.<br
/> My goal was, at one point, to release them as open source code but at that time I was working on some other projects so I put them aside and forgot about it&#8230;<br
/> Until the other day when, on Twitter, <a
href="http://twitter.com/nicoptere">@nicoptere</a> <a
href="http://twitter.com/nicoptere/status/16932228381">asked</a> :</p><blockquote><p>has anyone ever done a photoshop exact &#8216;Color&#8217; blendmode in AS3 ? if so are you sharing the sources ? huge thanks in advance ^^</p></blockquote><p>I <a
href="http://twitter.com/sroucheray/status/16938996971">answered to him</a> with a link to my <a
href="http://pastebin.com/t8Bd5x1H">solution&#8217;s source code in pastebin</a> and the excellent <a
href="http://twitter.com/quasimondo">@quasimondo</a> provided <a
href="http://twitter.com/quasimondo/status/16944725728">his own quickly hacked solution</a>.</p><p>So @nicoptere tested both solutions but none of them were very satisfying and in particular <a
href="http://twitpic.com/1zrpo7">did not exactly mimic Photoshop Color blend mode</a>.</p><p>I was a bit surprise because I took my inspiration <a
href="http://www.adobe.com/devnet/pdf/pdfs/blend_modes.pdf">directly from Adobe</a>. So I analyzed my source code and discovered a small bug that prevented the kernel to mimic Photoshop in low contrast images. I fixed it and decided to push the <a
href="http://github.com/sroucheray/sroucheray-as3/blob/master/pixelbender/blend_mode/Color.pbk">source code</a> to my <a
href="http://github.com/sroucheray/sroucheray-as3">GitHub repo</a>.</p><p>Finally @nicoptere seemed <a
href="http://twitter.com/nicoptere/status/17009974021">happy with the result</a> and me, happy to have helped him.</p><p>Twitter is a great tool for information sharing and the way it has been used in this case is the way I love social network : people helping each other.</p><p>To conclude, the source code of the pixel bender Color blend mode as well as 21 &#8220;Photoshop like&#8221; other blend modes are available here : <a
href="http://github.com/sroucheray/sroucheray-as3/tree/master/pixelbender/blend_mode/">http://github.com/sroucheray/sroucheray-as3/tree/master/pixelbender/blend_mode/</a>.</p><p>Note : for full information on antecedence, this work on pixel bender kernels to mimic Photoshop blend modes in Flash had already been done by others, in particular here by Shane McCartney : <a
href="http://www.lostinactionscript.com/blog/index.php/2009/05/26/custom-blend-modes-for-flash-10/">http://www.lostinactionscript.com/blog/index.php/2009/05/26/custom-blend-modes-for-flash-10/</a>. The work I have done has not been inspired by those antecedent works because I have been aware of them afterwards. Note (bis), on this site, it is said that the Color blend mode is still in development while the source code is available <a
href="http://code.google.com/p/blendmodes4flash/source/browse/trunk/pbk/BlendModeColor.pbk">here</a>. The solution is less simple than mine though.</p><div
class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center"><ul
class="socials"><li
class="shr-delicious"> <a
href="http://delicious.com/post?url=http://sroucheray.org/blog/2010/06/photoshop-blend-modes-available-in-flash/&amp;title=Photoshop+Blend+Modes+available+in+Flash" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a></li><li
class="shr-digg"> <a
href="http://digg.com/submit?phase=2&amp;url=http://sroucheray.org/blog/2010/06/photoshop-blend-modes-available-in-flash/&amp;title=Photoshop+Blend+Modes+available+in+Flash" rel="nofollow" class="external" title="Digg this!">Digg this!</a></li><li
class="shr-facebook"> <a
href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://sroucheray.org/blog/2010/06/photoshop-blend-modes-available-in-flash/&amp;t=Photoshop+Blend+Modes+available+in+Flash" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a></li><li
class="shr-googlebuzz"> <a
href="http://www.google.com/buzz/post?url=http://sroucheray.org/blog/2010/06/photoshop-blend-modes-available-in-flash/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a></li><li
class="shr-linkedin"> <a
href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://sroucheray.org/blog/2010/06/photoshop-blend-modes-available-in-flash/&amp;title=Photoshop+Blend+Modes+available+in+Flash&amp;summary=22%20Photoshop%20blend%20modes%20available%20to%20Flash%20thanks%20to%20Pixel%20Bender.%20Plus%2C%20the%20source%20code%20is%20available%20as%20open%20source%20license%20%21&amp;source=Lambda" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a></li><li
class="shr-reddit"> <a
href="http://reddit.com/submit?url=http://sroucheray.org/blog/2010/06/photoshop-blend-modes-available-in-flash/&amp;title=Photoshop+Blend+Modes+available+in+Flash" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a></li><li
class="shr-stumbleupon"> <a
href="http://www.stumbleupon.com/submit?url=http://sroucheray.org/blog/2010/06/photoshop-blend-modes-available-in-flash/&amp;title=Photoshop+Blend+Modes+available+in+Flash" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a></li><li
class="shr-twitter"> <a
href="http://twitter.com/home?status=Photoshop+Blend+Modes+available+in+Flash+-+http://bit.ly/d7NOtN&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a></li><li
class="shr-yahoobuzz"> <a
href="http://buzz.yahoo.com/submit/?submitUrl=http://sroucheray.org/blog/2010/06/photoshop-blend-modes-available-in-flash/&amp;submitHeadline=Photoshop+Blend+Modes+available+in+Flash&amp;submitSummary=22%20Photoshop%20blend%20modes%20available%20to%20Flash%20thanks%20to%20Pixel%20Bender.%20Plus%2C%20the%20source%20code%20is%20available%20as%20open%20source%20license%20%21&amp;submitCategory=science&amp;submitAssetType=text" rel="nofollow" class="external" title="Buzz up!">Buzz up!</a></li></ul><div
style="clear:both;"></div></div>]]></content:encoded> <wfw:commentRss>http://sroucheray.org/blog/2010/06/photoshop-blend-modes-available-in-flash/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>How to insert a SWF file in an ASDoc API documentation ?</title><link>http://sroucheray.org/blog/2010/02/how-to-insert-a-swf-file-in-an-asdoc-api-documentation/</link> <comments>http://sroucheray.org/blog/2010/02/how-to-insert-a-swf-file-in-an-asdoc-api-documentation/#comments</comments> <pubDate>Tue, 02 Feb 2010 15:22:49 +0000</pubDate> <dc:creator>Stéphane Roucheray</dc:creator> <category><![CDATA[ActionScript]]></category> <category><![CDATA[Flash]]></category> <category><![CDATA[JavaScript]]></category> <category><![CDATA[asdoc]]></category> <category><![CDATA[swf]]></category><guid
isPermaLink="false">http://sroucheray.org/blog/?p=605</guid> <description><![CDATA[ASDoc API documentation is well designed for developers but remain difficult to read for others. Some of my co-workers are web designer. They code a bit but they want API to be simple and they want usage examples. In the past days I developed some image filters and effects for them. The resulting API has [...]]]></description> <content:encoded><![CDATA[<p><img
width="550" src="http://sroucheray.org/blog/wp-content/uploads/2010/02/ASDocScanlineEffect.jpg" alt="ASDoc with inline SWF file" /></p><p>ASDoc API documentation is well designed for developers but remain difficult to read for others. Some of my co-workers are web designer. They code a bit but they want API to be simple and they want usage examples. In the past days I developed some image filters and effects for them. The resulting API has very few meaning without a real example of code and a way to test it. Thus, I wanted them to be able to access the code examples as well as being able to test the result of each effects, inline, in the ASDoc documentation. Click the image below to see the rendering SWF tester.</p><p><a
href="http://sroucheray.org/blog/wp-content/uploads/2010/02/effectTester.swf" rel="shadowbox;height=780;width=1000"><img
src="http://sroucheray.org/blog/wp-content/uploads/2010/02/effectTester.jpg" alt="Effect tester" /></a></p><p>Code examples are easy to integrate using the <span
class="pre">@example</span> and <span
class="pre">@includeExample</span> (<a
href="http://help.adobe.com/en_US/Flex/4.0/html/WSd0ded3821e0d52fe1e63e3d11c2f44bc36-7ff6.html">Flex 4</a>), but there is no default way of inserting SWF files directly (as far as I know).</p><p>In order to insert a SWF file in a generated ASDoc API documentation, one needs to understand the process of generating documentation with ASDoc. On one side there are packages and classes, on the other side ASDoc templates files. Generating documentation consists for the <span
class="pre">asdoc.exe</span> application of parsing the classes for any special comments and injecting what has been found in the templates. The result is output in a directory and is made of a bunch of HTML, CSS, JavaScript files&#8230;</p><p>The type of special comments the ASDoc process is looking for looks like that :</p><div
class="codecolorer-container actionscript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div
class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color: #808080; font-style: italic;">/**<br
/> &nbsp;* Apply an RGB distortion effect on a DisplayObject<br
/> &nbsp;* <br
/> &nbsp;* @param target The DisplayObject on which to apply the effect<br
/> &nbsp;*/</span><br
/> override <span
style="color: #0066CC;">public</span> <span
style="color: #000000; font-weight: bold;">function</span> <span
style="color: #0066CC;">apply</span><span
style="color: #66cc66;">&#40;</span><span
style="color: #0066CC;">target</span> : DisplayObject<span
style="color: #66cc66;">&#41;</span>:<span
style="color: #0066CC;">void</span><span
style="color: #66cc66;">&#123;</span><br
/> &nbsp; &nbsp; ...<br
/> <span
style="color: #66cc66;">&#125;</span></div></div><p>Special tags starting with an <span
class="pre">@</span> can be used in these comments and will be interpreted by the ASDoc process. Fortunately HTML tags can be used as well inside these comments and will be output unchanged. I make use of this feature to insert SWF files inside the documentation.</p><h3>Step 1 : adding the required JavaScript libraries to the ASDoc templates</h3><p><em>Note </em>: in the following section you have to download several components to make it works. <a
href="http://sroucheray.org/blog/wp-content/uploads/2010/02/asdoc-inline-swf-templates.zip">I packaged all of them in a zip file</a>.</p><p>ASDoc templates are located in a Flex SDK sub-directory by default : <span
class="pre">FLEX_SDK_DIR\asdoc\templates</span><br
/> To keep unmodified the original templates you can copy this folder outside the Flex directory. In this case to make the ASDoc process being aware of this change use the command parameter <span
class="pre">-templates-path &#8216;path/to/your/new/template_folder&#8217;</span><br
/> <a
href="http://livedocs.adobe.com/flex/3/html/help.html?content=asdoc_1.html">Full ASDoc documentation is located on Adobe Web site</a></p><p>In the template folder locate the file <span
class="pre">asdoc-util.xsl</span> and in there search for those lines :</p><div
class="codecolorer-container xml dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div
class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;script</span> <span
style="color: #000066;">language</span>=<span
style="color: #ff0000;">&quot;javascript&quot;</span> <span
style="color: #000066;">type</span>=<span
style="color: #ff0000;">&quot;text/javascript&quot;</span><span
style="color: #000000; font-weight: bold;">&gt;</span></span><br
/> &nbsp; &nbsp; <span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;xsl:attribute</span> <span
style="color: #000066;">name</span>=<span
style="color: #ff0000;">&quot;src&quot;</span><span
style="color: #000000; font-weight: bold;">&gt;</span></span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;xsl:value-of</span> <span
style="color: #000066;">select</span>=<span
style="color: #ff0000;">&quot;$baseRef&quot;</span><span
style="color: #000000; font-weight: bold;">/&gt;</span></span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;xsl:text<span
style="color: #000000; font-weight: bold;">&gt;</span></span></span>asdoc.js<span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;/xsl:text<span
style="color: #000000; font-weight: bold;">&gt;</span></span></span><br
/> &nbsp; &nbsp; <span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;/xsl:attribute<span
style="color: #000000; font-weight: bold;">&gt;</span></span></span><br
/> <span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;/script<span
style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div><p>insert the following lines just before the previous ones :</p><div
class="codecolorer-container xml dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div
class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;script</span> <span
style="color: #000066;">language</span>=<span
style="color: #ff0000;">&quot;javascript&quot;</span> <span
style="color: #000066;">type</span>=<span
style="color: #ff0000;">&quot;text/javascript&quot;</span><span
style="color: #000000; font-weight: bold;">&gt;</span></span><br
/> &nbsp; &nbsp;<span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;xsl:attribute</span> <span
style="color: #000066;">name</span>=<span
style="color: #ff0000;">&quot;src&quot;</span><span
style="color: #000000; font-weight: bold;">&gt;</span></span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;xsl:value-of</span> <span
style="color: #000066;">select</span>=<span
style="color: #ff0000;">&quot;$baseRef&quot;</span><span
style="color: #000000; font-weight: bold;">/&gt;</span></span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;xsl:text<span
style="color: #000000; font-weight: bold;">&gt;</span></span></span>jquery.min.js<span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;/xsl:text<span
style="color: #000000; font-weight: bold;">&gt;</span></span></span><br
/> &nbsp; &nbsp; <span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;/xsl:attribute<span
style="color: #000000; font-weight: bold;">&gt;</span></span></span><br
/> <span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;/script<span
style="color: #000000; font-weight: bold;">&gt;</span></span></span><br
/> <span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;script</span> <span
style="color: #000066;">language</span>=<span
style="color: #ff0000;">&quot;javascript&quot;</span> <span
style="color: #000066;">type</span>=<span
style="color: #ff0000;">&quot;text/javascript&quot;</span><span
style="color: #000000; font-weight: bold;">&gt;</span></span><br
/> &nbsp; &nbsp;<span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;xsl:attribute</span> <span
style="color: #000066;">name</span>=<span
style="color: #ff0000;">&quot;src&quot;</span><span
style="color: #000000; font-weight: bold;">&gt;</span></span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;xsl:value-of</span> <span
style="color: #000066;">select</span>=<span
style="color: #ff0000;">&quot;$baseRef&quot;</span><span
style="color: #000000; font-weight: bold;">/&gt;</span></span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;xsl:text<span
style="color: #000000; font-weight: bold;">&gt;</span></span></span>swfobject.js<span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;/xsl:text<span
style="color: #000000; font-weight: bold;">&gt;</span></span></span><br
/> &nbsp; &nbsp; <span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;/xsl:attribute<span
style="color: #000000; font-weight: bold;">&gt;</span></span></span><br
/> <span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;/script<span
style="color: #000000; font-weight: bold;">&gt;</span></span></span><br
/> <span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;script</span> <span
style="color: #000066;">language</span>=<span
style="color: #ff0000;">&quot;javascript&quot;</span> <span
style="color: #000066;">type</span>=<span
style="color: #ff0000;">&quot;text/javascript&quot;</span><span
style="color: #000000; font-weight: bold;">&gt;</span></span><br
/> &nbsp; &nbsp;<span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;xsl:attribute</span> <span
style="color: #000066;">name</span>=<span
style="color: #ff0000;">&quot;src&quot;</span><span
style="color: #000000; font-weight: bold;">&gt;</span></span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;xsl:value-of</span> <span
style="color: #000066;">select</span>=<span
style="color: #ff0000;">&quot;$baseRef&quot;</span><span
style="color: #000000; font-weight: bold;">/&gt;</span></span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;xsl:text<span
style="color: #000000; font-weight: bold;">&gt;</span></span></span>swf-loader.js<span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;/xsl:text<span
style="color: #000000; font-weight: bold;">&gt;</span></span></span><br
/> &nbsp; &nbsp; <span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;/xsl:attribute<span
style="color: #000000; font-weight: bold;">&gt;</span></span></span><br
/> <span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;/script<span
style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div><p>As you may guess we will use jQuery and SWFObject to achieve our goal. Download <a
href="http://jquery.com/">jQuery</a> and <a
href="http://code.google.com/p/swfobject/">SWFObject</a> and put the files in the templates directory (rename the files to match the previous lines). From the SWFObject download ZIP file, extracts the <span
class="pre">expressInstall.swf</span> file in the templates directory as well.</p><p>The third file is made by myself and will help substitute special HTML tags in the documentation by SWF files. Save the following code in the file <span
class="pre">templates/swf-loader.js</span></p><div
class="codecolorer-container javascript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div
class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<span
style="color: #009900;">&#40;</span>document<span
style="color: #009900;">&#41;</span>.<span
style="color: #660066;">ready</span><span
style="color: #009900;">&#40;</span><span
style="color: #003366; font-weight: bold;">function</span><span
style="color: #009900;">&#40;</span><span
style="color: #009900;">&#41;</span><span
style="color: #009900;">&#123;</span><br
/> &nbsp; &nbsp; <span
style="color: #003366; font-weight: bold;">var</span> idBase <span
style="color: #339933;">=</span> <span
style="color: #3366CC;">&quot;swfLoader&quot;</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; <span
style="color: #003366; font-weight: bold;">var</span> idNum <span
style="color: #339933;">=</span> <span
style="color: #CC0000;">0</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; <span
style="color: #003366; font-weight: bold;">var</span> width<span
style="color: #339933;">,</span> height<span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; <span
style="color: #003366; font-weight: bold;">var</span> params <span
style="color: #339933;">=</span> <span
style="color: #009900;">&#123;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; quality<span
style="color: #339933;">:</span> <span
style="color: #3366CC;">&quot;high&quot;</span><span
style="color: #339933;">,</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; scale<span
style="color: #339933;">:</span> <span
style="color: #3366CC;">&quot;noscale&quot;</span><span
style="color: #339933;">,</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; allowscriptaccess<span
style="color: #339933;">:</span> <span
style="color: #3366CC;">&quot;always&quot;</span><span
style="color: #339933;">,</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; bgcolor<span
style="color: #339933;">:</span> <span
style="color: #3366CC;">&quot;#FFFFFF&quot;</span><br
/> &nbsp; &nbsp; <span
style="color: #009900;">&#125;</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; <span
style="color: #003366; font-weight: bold;">var</span> flashvars <span
style="color: #339933;">=</span> <span
style="color: #009900;">&#123;</span><span
style="color: #009900;">&#125;</span><span
style="color: #339933;">;</span><br
/> <br
/> &nbsp; &nbsp; $<span
style="color: #009900;">&#40;</span><span
style="color: #3366CC;">&quot;div[src]&quot;</span><span
style="color: #009900;">&#41;</span>.<span
style="color: #660066;">each</span><span
style="color: #009900;">&#40;</span><span
style="color: #003366; font-weight: bold;">function</span><span
style="color: #009900;">&#40;</span><span
style="color: #009900;">&#41;</span><span
style="color: #009900;">&#123;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; $<span
style="color: #009900;">&#40;</span><span
style="color: #000066; font-weight: bold;">this</span><span
style="color: #009900;">&#41;</span>.<span
style="color: #660066;">attr</span><span
style="color: #009900;">&#40;</span><span
style="color: #3366CC;">&quot;id&quot;</span><span
style="color: #339933;">,</span>idBase <span
style="color: #339933;">+</span> idNum<span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; width <span
style="color: #339933;">=</span> $<span
style="color: #009900;">&#40;</span><span
style="color: #000066; font-weight: bold;">this</span><span
style="color: #009900;">&#41;</span>.<span
style="color: #660066;">attr</span><span
style="color: #009900;">&#40;</span><span
style="color: #3366CC;">'width'</span><span
style="color: #009900;">&#41;</span> <span
style="color: #339933;">||</span> <span
style="color: #3366CC;">&quot;100%&quot;</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; height <span
style="color: #339933;">=</span> $<span
style="color: #009900;">&#40;</span><span
style="color: #000066; font-weight: bold;">this</span><span
style="color: #009900;">&#41;</span>.<span
style="color: #660066;">attr</span><span
style="color: #009900;">&#40;</span><span
style="color: #3366CC;">'height'</span><span
style="color: #009900;">&#41;</span> <span
style="color: #339933;">||</span> <span
style="color: #3366CC;">&quot;100%&quot;</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #003366; font-weight: bold;">var</span> flasvarsString <span
style="color: #339933;">=</span> $<span
style="color: #009900;">&#40;</span><span
style="color: #000066; font-weight: bold;">this</span><span
style="color: #009900;">&#41;</span>.<span
style="color: #660066;">attr</span><span
style="color: #009900;">&#40;</span><span
style="color: #3366CC;">&quot;flashvars&quot;</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #003366; font-weight: bold;">var</span> flashvarsArray <span
style="color: #339933;">=</span> flasvarsString.<span
style="color: #660066;">split</span><span
style="color: #009900;">&#40;</span><span
style="color: #3366CC;">&quot;&amp;&quot;</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #000066; font-weight: bold;">for</span> <span
style="color: #009900;">&#40;</span> <span
style="color: #003366; font-weight: bold;">var</span> i <span
style="color: #339933;">=</span> <span
style="color: #CC0000;">0</span><span
style="color: #339933;">;</span> i <span
style="color: #339933;">&lt;</span> flashvarsArray.<span
style="color: #660066;">length</span><span
style="color: #339933;">;</span> i<span
style="color: #339933;">++</span><span
style="color: #009900;">&#41;</span> <span
style="color: #009900;">&#123;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #003366; font-weight: bold;">var</span> flasvar <span
style="color: #339933;">=</span> flashvarsArray<span
style="color: #009900;">&#91;</span>i<span
style="color: #009900;">&#93;</span>.<span
style="color: #660066;">split</span><span
style="color: #009900;">&#40;</span><span
style="color: #3366CC;">&quot;:&quot;</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; flashvars<span
style="color: #009900;">&#91;</span>flasvar<span
style="color: #009900;">&#91;</span><span
style="color: #CC0000;">0</span><span
style="color: #009900;">&#93;</span><span
style="color: #009900;">&#93;</span> <span
style="color: #339933;">=</span> flasvar<span
style="color: #009900;">&#91;</span><span
style="color: #CC0000;">1</span><span
style="color: #009900;">&#93;</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #009900;">&#125;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; swfobject.<span
style="color: #660066;">embedSWF</span><span
style="color: #009900;">&#40;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span
style="color: #009900;">&#40;</span><span
style="color: #000066; font-weight: bold;">this</span><span
style="color: #009900;">&#41;</span>.<span
style="color: #660066;">attr</span><span
style="color: #009900;">&#40;</span><span
style="color: #3366CC;">&quot;src&quot;</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">,</span> <br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; idBase <span
style="color: #339933;">+</span> idNum<span
style="color: #339933;">,</span> <br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width<span
style="color: #339933;">,</span> <br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height<span
style="color: #339933;">,</span> <br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #3366CC;">&quot;10.0.0&quot;</span><span
style="color: #339933;">,</span> <br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #3366CC;">&quot;expressInstall.swf&quot;</span><span
style="color: #339933;">,</span> <br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; flashvars<span
style="color: #339933;">,</span> <br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; params<span
style="color: #339933;">,</span> <br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #009900;">&#123;</span><span
style="color: #009900;">&#125;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; <br
/> &nbsp; &nbsp; &nbsp; &nbsp; idNum<span
style="color: #339933;">++;</span><br
/> &nbsp; &nbsp; <span
style="color: #009900;">&#125;</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span><br
/> <span
style="color: #009900;">&#125;</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span></div></div><h3>Step 2 : adding special HTML Tag in  ASDoc classes comments</h3><p>Now that the files are in place it&#8217;s possible to add special HTML tags in comments to insert SWF files :</p><div
class="codecolorer-container actionscript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div
class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color: #808080; font-style: italic;">/**<br
/> &nbsp;* Creates an RGB distortion effect (Timed effect).<br
/> &nbsp;* &lt;div src='../../../swf/effectTester.swf' <br
/> &nbsp;* &nbsp; width='780px' height='550px' flashvars='form:mosaicForm'&gt;&lt;/div&gt;<br
/> &nbsp;*/</span></div></div><p>The div tag will be replaced by the SWF files located at <span
class="pre">&#8216;../../../swf/effectTester.swf&#8217;</span> passing <span
class="pre">width</span>, <span
class="pre">height</span> and <span
class="pre">flashvars</span> parameters.<br
/> Flashvars must be of the following form :<br
/> <span
class="pre">var1:value1&#038;var2:value2&#038;var3:value3</span>.</p><h3>Step 3 : where to put the SWF files</h3><p>Put the SWF files in the <span
class="pre">doc_output_directory/swf</span>.</p><div
class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center"><ul
class="socials"><li
class="shr-delicious"> <a
href="http://delicious.com/post?url=http://sroucheray.org/blog/2010/02/how-to-insert-a-swf-file-in-an-asdoc-api-documentation/&amp;title=How+to+insert+a+SWF+file+in+an+ASDoc+API+documentation+%3F" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a></li><li
class="shr-digg"> <a
href="http://digg.com/submit?phase=2&amp;url=http://sroucheray.org/blog/2010/02/how-to-insert-a-swf-file-in-an-asdoc-api-documentation/&amp;title=How+to+insert+a+SWF+file+in+an+ASDoc+API+documentation+%3F" rel="nofollow" class="external" title="Digg this!">Digg this!</a></li><li
class="shr-facebook"> <a
href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://sroucheray.org/blog/2010/02/how-to-insert-a-swf-file-in-an-asdoc-api-documentation/&amp;t=How+to+insert+a+SWF+file+in+an+ASDoc+API+documentation+%3F" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a></li><li
class="shr-googlebuzz"> <a
href="http://www.google.com/buzz/post?url=http://sroucheray.org/blog/2010/02/how-to-insert-a-swf-file-in-an-asdoc-api-documentation/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a></li><li
class="shr-linkedin"> <a
href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://sroucheray.org/blog/2010/02/how-to-insert-a-swf-file-in-an-asdoc-api-documentation/&amp;title=How+to+insert+a+SWF+file+in+an+ASDoc+API+documentation+%3F&amp;summary=%0D%0A%0D%0AASDoc%20API%20documentation%20is%20well%20designed%20for%20developers%20but%20remain%20difficult%20to%20read%20for%20others.%20Some%20of%20my%20co-workers%20are%20web%20designer.%20They%20code%20a%20bit%20but%20they%20want%20API%20to%20be%20simple%20and%20they%20want%20usage%20examples.%20In%20the%20past%20days%20I%20developed%20some%20image%20filters%20and%20effects%20for%20them.%20The%20resultin&amp;source=Lambda" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a></li><li
class="shr-reddit"> <a
href="http://reddit.com/submit?url=http://sroucheray.org/blog/2010/02/how-to-insert-a-swf-file-in-an-asdoc-api-documentation/&amp;title=How+to+insert+a+SWF+file+in+an+ASDoc+API+documentation+%3F" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a></li><li
class="shr-stumbleupon"> <a
href="http://www.stumbleupon.com/submit?url=http://sroucheray.org/blog/2010/02/how-to-insert-a-swf-file-in-an-asdoc-api-documentation/&amp;title=How+to+insert+a+SWF+file+in+an+ASDoc+API+documentation+%3F" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a></li><li
class="shr-twitter"> <a
href="http://twitter.com/home?status=How+to+insert+a+SWF+file+in+an+ASDoc+API+documentation+%3F+-+&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a></li><li
class="shr-yahoobuzz"> <a
href="http://buzz.yahoo.com/submit/?submitUrl=http://sroucheray.org/blog/2010/02/how-to-insert-a-swf-file-in-an-asdoc-api-documentation/&amp;submitHeadline=How+to+insert+a+SWF+file+in+an+ASDoc+API+documentation+%3F&amp;submitSummary=%0D%0A%0D%0AASDoc%20API%20documentation%20is%20well%20designed%20for%20developers%20but%20remain%20difficult%20to%20read%20for%20others.%20Some%20of%20my%20co-workers%20are%20web%20designer.%20They%20code%20a%20bit%20but%20they%20want%20API%20to%20be%20simple%20and%20they%20want%20usage%20examples.%20In%20the%20past%20days%20I%20developed%20some%20image%20filters%20and%20effects%20for%20them.%20The%20resultin&amp;submitCategory=science&amp;submitAssetType=text" rel="nofollow" class="external" title="Buzz up!">Buzz up!</a></li></ul><div
style="clear:both;"></div></div>]]></content:encoded> <wfw:commentRss>http://sroucheray.org/blog/2010/02/how-to-insert-a-swf-file-in-an-asdoc-api-documentation/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Papervision : Mouse interaction with 2D MovieMaterial</title><link>http://sroucheray.org/blog/2009/12/papervision-mouse-interaction-with-2d-moviematerial/</link> <comments>http://sroucheray.org/blog/2009/12/papervision-mouse-interaction-with-2d-moviematerial/#comments</comments> <pubDate>Thu, 10 Dec 2009 13:01:55 +0000</pubDate> <dc:creator>Stéphane Roucheray</dc:creator> <category><![CDATA[ActionScript]]></category> <category><![CDATA[Flash]]></category> <category><![CDATA[Papervision]]></category> <category><![CDATA[MovieMaterial]]></category> <category><![CDATA[Papervision3D]]></category><guid
isPermaLink="false">http://sroucheray.org/blog/?p=508</guid> <description><![CDATA[The nature of Papervision MovieMaterial gives users the ability to interact with it's content. However it can be tricky to make it work.]]></description> <content:encoded><![CDATA[<p><a
href="http://blog.papervision3d.org/">Papervision</a> lets apply textures as MovieClip on 3D object surfaces. This kind of textures is called <a
href="http://papervision3d.googlecode.com/svn/trunk/as3/trunk/docs/org/papervision3d/materials/MovieMaterial.html">MovieMaterial</a>. The nature of MovieMaterial gives users the ability to interact with it&#8217;s content. However it&#8217;s often tricky to make it works.</p><p>In the following example I applied a MovieMaterial to a <a
href="http://papervision3d.googlecode.com/svn/trunk/as3/trunk/docs/org/papervision3d/objects/primitives/Cube.html">Cube</a> (wihout depth so it looks like a <a
href="http://papervision3d.googlecode.com/svn/trunk/as3/trunk/docs/index.html?org/papervision3d/objects/primitives/Cube.html&#038;org/papervision3d/objects/primitives/class-list.html">PaperPlane</a>) :</p><object
classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_0" width="600" height="600"><param
name="movie" value="http://sroucheray.org/blog/wp-content/uploads/2009/11/moviematerial-interaction.swf" /> <!--[if !IE]>--> <object
type="application/x-shockwave-flash" data="http://sroucheray.org/blog/wp-content/uploads/2009/11/moviematerial-interaction.swf" width="600" height="600"> <!--<![endif]--><p>The Flash plugin is required to view this object.</p> <!--[if !IE]>--> </object> <!--<![endif]--> </object><p>The button and TextField are both children of the MovieClip used as the material in the MovieMaterial. This example shows how the mouse can interact with the button. While it rotates along with the cube and its MovieMaterial, it handles well the three events : mouse over, mouse out and mouse click.</p><h2>MouseClick on a button inside a MovieMaterial</h2><p>MouseClick on a button is really easy to implement. A simple listener is added to the button Object :</p><div
class="codecolorer-container actionscript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div
class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color: #808080; font-style: italic;">//WhitePanel class is an asset in the Fla's library</span><br
/> panel = <span
style="color: #000000; font-weight: bold;">new</span> WhitePanel<span
style="color: #66cc66;">&#40;</span><span
style="color: #66cc66;">&#41;</span>;<br
/> <br
/> <span
style="color: #808080; font-style: italic;">//Set up the okButton inside the panel</span><br
/> <span
style="color: #000000; font-weight: bold;">var</span> okButton : <span
style="color: #0066CC;">MovieClip</span> = <span
style="color: #0066CC;">MovieClip</span><span
style="color: #66cc66;">&#40;</span>panel.<span
style="color: #006600;">okButton</span><span
style="color: #66cc66;">&#41;</span>;<br
/> okButton.<span
style="color: #006600;">mouseChildren</span> = <span
style="color: #000000; font-weight: bold;">false</span>;<br
/> okButton.<span
style="color: #006600;">addEventListener</span><span
style="color: #66cc66;">&#40;</span>MouseEvent.<span
style="color: #006600;">CLICK</span>, clickListener<span
style="color: #66cc66;">&#41;</span>;<br
/> <br
/> <span
style="color: #000000; font-weight: bold;">var</span> okInc : <span
style="color: #0066CC;">Number</span> = <span
style="color: #cc66cc;">0</span>;<br
/> <br
/> <span
style="color: #000000; font-weight: bold;">function</span> clickListener <span
style="color: #66cc66;">&#40;</span><span
style="color: #0066CC;">e</span>:MouseEvent<span
style="color: #66cc66;">&#41;</span>:<span
style="color: #0066CC;">void</span><span
style="color: #66cc66;">&#123;</span><br
/> &nbsp;++okInc;<br
/> &nbsp;<span
style="color: #0066CC;">TextField</span><span
style="color: #66cc66;">&#40;</span>panel.<span
style="color: #006600;">title</span><span
style="color: #66cc66;">&#41;</span>.<span
style="color: #0066CC;">text</span> = <span
style="color: #ff0000;">&quot;Click on OK Button : &quot;</span>+ okInc;<br
/> <span
style="color: #66cc66;">&#125;</span></div></div><p>On button click the text field is well updated.</p><h2>Mouse over and mouse out a sprite inside a MovieMaterial</h2><p>The mouse over and mouse out events are a little bit more tricky to implement. In general, when a zone is interactive you want the mouse to change its aspects. When over it is transformed to a hand cursor and when out to the simple arrow cursor.<br
/> When working on a 2D stage it is done via these affectations :</p><div
class="codecolorer-container actionscript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div
class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">okButton.<span
style="color: #006600;">buttonMode</span> = <span
style="color: #000000; font-weight: bold;">true</span>;<br
/> okButton.<span
style="color: #0066CC;">useHandCursor</span>= <span
style="color: #000000; font-weight: bold;">true</span>; <span
style="color: #808080; font-style: italic;">//This is true by default</span></div></div><p>Thus the hand cursor appears when over the okButton MovieClip. Unfortunately it doesn&#8217;t work with Papervision. The workaround is to affect handlers to the MovieClip and globally change the aspect of the mouse cursor :</p><div
class="codecolorer-container actionscript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div
class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">okButton.<span
style="color: #006600;">addEventListener</span><span
style="color: #66cc66;">&#40;</span>MouseEvent.<span
style="color: #006600;">MOUSE_OVER</span>, handleOver<span
style="color: #66cc66;">&#41;</span>;<br
/> okButton.<span
style="color: #006600;">addEventListener</span><span
style="color: #66cc66;">&#40;</span>MouseEvent.<span
style="color: #006600;">MOUSE_OUT</span>, handleOut<span
style="color: #66cc66;">&#41;</span>;<br
/> <br
/> <span
style="color: #000000; font-weight: bold;">function</span> handleOver<span
style="color: #66cc66;">&#40;</span>event:MouseEvent<span
style="color: #66cc66;">&#41;</span>:<span
style="color: #0066CC;">void</span> <span
style="color: #66cc66;">&#123;</span><br
/> &nbsp; &nbsp; <span
style="color: #808080; font-style: italic;">//Globally change the mouse cursor aspect</span><br
/> &nbsp; &nbsp; viewport.<span
style="color: #006600;">containerSprite</span>.<span
style="color: #006600;">buttonMode</span> = <span
style="color: #000000; font-weight: bold;">true</span>;<br
/> &nbsp; &nbsp; <span
style="color: #808080; font-style: italic;">//Not required, changes the aspect of the button</span><br
/> &nbsp; &nbsp; <span
style="color: #808080; font-style: italic;">//in our case</span><br
/> &nbsp; &nbsp; <span
style="color: #0066CC;">MovieClip</span><span
style="color: #66cc66;">&#40;</span>event.<span
style="color: #006600;">currentTarget</span><span
style="color: #66cc66;">&#41;</span>.<span
style="color: #0066CC;">gotoAndStop</span><span
style="color: #66cc66;">&#40;</span><span
style="color: #cc66cc;">2</span><span
style="color: #66cc66;">&#41;</span>;<br
/> <span
style="color: #66cc66;">&#125;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <br
/> <span
style="color: #000000; font-weight: bold;">function</span> handleOut<span
style="color: #66cc66;">&#40;</span>event:MouseEvent<span
style="color: #66cc66;">&#41;</span>:<span
style="color: #0066CC;">void</span><br
/> <span
style="color: #66cc66;">&#123;</span><br
/> &nbsp; &nbsp; <span
style="color: #808080; font-style: italic;">//Globally change the mouse cursor aspect</span><br
/> &nbsp; &nbsp; viewport.<span
style="color: #006600;">containerSprite</span>.<span
style="color: #006600;">buttonMode</span> = <span
style="color: #000000; font-weight: bold;">false</span>;<br
/> &nbsp; &nbsp; <span
style="color: #0066CC;">MovieClip</span><span
style="color: #66cc66;">&#40;</span>event.<span
style="color: #006600;">currentTarget</span><span
style="color: #66cc66;">&#41;</span>.<span
style="color: #0066CC;">gotoAndStop</span><span
style="color: #66cc66;">&#40;</span><span
style="color: #cc66cc;">1</span><span
style="color: #66cc66;">&#41;</span>;<br
/> <span
style="color: #66cc66;">&#125;</span></div></div><p>&#8212;</p><p>Download the demo sources <a
href="http://sroucheray.org/blog/wp-content/plugins/download-monitor/download.php?id=1" title="Download MMInteractionDemo.zip">MMInteractionDemo.zip</a></p><div
class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center"><ul
class="socials"><li
class="shr-delicious"> <a
href="http://delicious.com/post?url=http://sroucheray.org/blog/2009/12/papervision-mouse-interaction-with-2d-moviematerial/&amp;title=Papervision+%3A+Mouse+interaction+with+2D+MovieMaterial" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a></li><li
class="shr-digg"> <a
href="http://digg.com/submit?phase=2&amp;url=http://sroucheray.org/blog/2009/12/papervision-mouse-interaction-with-2d-moviematerial/&amp;title=Papervision+%3A+Mouse+interaction+with+2D+MovieMaterial" rel="nofollow" class="external" title="Digg this!">Digg this!</a></li><li
class="shr-facebook"> <a
href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://sroucheray.org/blog/2009/12/papervision-mouse-interaction-with-2d-moviematerial/&amp;t=Papervision+%3A+Mouse+interaction+with+2D+MovieMaterial" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a></li><li
class="shr-googlebuzz"> <a
href="http://www.google.com/buzz/post?url=http://sroucheray.org/blog/2009/12/papervision-mouse-interaction-with-2d-moviematerial/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a></li><li
class="shr-linkedin"> <a
href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://sroucheray.org/blog/2009/12/papervision-mouse-interaction-with-2d-moviematerial/&amp;title=Papervision+%3A+Mouse+interaction+with+2D+MovieMaterial&amp;summary=The%20nature%20of%20Papervision%20MovieMaterial%20gives%20users%20the%20ability%20to%20interact%20with%20it%27s%20content.%20However%20it%20can%20be%20tricky%20to%20make%20it%20work.&amp;source=Lambda" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a></li><li
class="shr-reddit"> <a
href="http://reddit.com/submit?url=http://sroucheray.org/blog/2009/12/papervision-mouse-interaction-with-2d-moviematerial/&amp;title=Papervision+%3A+Mouse+interaction+with+2D+MovieMaterial" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a></li><li
class="shr-stumbleupon"> <a
href="http://www.stumbleupon.com/submit?url=http://sroucheray.org/blog/2009/12/papervision-mouse-interaction-with-2d-moviematerial/&amp;title=Papervision+%3A+Mouse+interaction+with+2D+MovieMaterial" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a></li><li
class="shr-twitter"> <a
href="http://twitter.com/home?status=Papervision+%3A+Mouse+interaction+with+2D+MovieMaterial+-+http://bit.ly/bf6h8r&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a></li><li
class="shr-yahoobuzz"> <a
href="http://buzz.yahoo.com/submit/?submitUrl=http://sroucheray.org/blog/2009/12/papervision-mouse-interaction-with-2d-moviematerial/&amp;submitHeadline=Papervision+%3A+Mouse+interaction+with+2D+MovieMaterial&amp;submitSummary=The%20nature%20of%20Papervision%20MovieMaterial%20gives%20users%20the%20ability%20to%20interact%20with%20it%27s%20content.%20However%20it%20can%20be%20tricky%20to%20make%20it%20work.&amp;submitCategory=science&amp;submitAssetType=text" rel="nofollow" class="external" title="Buzz up!">Buzz up!</a></li></ul><div
style="clear:both;"></div></div>]]></content:encoded> <wfw:commentRss>http://sroucheray.org/blog/2009/12/papervision-mouse-interaction-with-2d-moviematerial/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Array.sort() should not be used to shuffle an array</title><link>http://sroucheray.org/blog/2009/11/array-sort-should-not-be-used-to-shuffle-an-array/</link> <comments>http://sroucheray.org/blog/2009/11/array-sort-should-not-be-used-to-shuffle-an-array/#comments</comments> <pubDate>Mon, 16 Nov 2009 12:48:43 +0000</pubDate> <dc:creator>Stéphane Roucheray</dc:creator> <category><![CDATA[ActionScript]]></category> <category><![CDATA[JavaScript]]></category> <category><![CDATA[Array]]></category> <category><![CDATA[Random]]></category> <category><![CDATA[Randomize]]></category> <category><![CDATA[Sort]]></category><guid
isPermaLink="false">http://sroucheray.org/blog/?p=375</guid> <description><![CDATA[When a developer searches the web for an algorithm to shuffle an array in JavaScript or ActionScript, he will surely find a way to achieve that using the <samp>Array.sort()</samp> method (see references : <a
href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/sort">JavaScript</a>, <a
href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/Array.html#sort%28%29">ActionScript 3</a>)...]]></description> <content:encoded><![CDATA[<p>When a developer searches the web for an algorithm to shuffle an array in JavaScript or ActionScript, he will surely find a way to achieve that using the <samp>Array.sort()</samp> method (see references : <a
href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/sort">JavaScript</a>, <a
href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/Array.html#sort%28%29">ActionScript 3</a>). While this method is intended to sort an array, it can also be used to randomize it (!). In general, here and there, the following algorithm comes forth :</p><div
class="codecolorer-container javascript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div
class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color: #006600; font-style: italic;">/**<br
/> &nbsp;* Add a randomize method to the Array object prototype<br
/> &nbsp;* Usage : <br
/> &nbsp;* &nbsp;var tmpArray = [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e&quot;];<br
/> &nbsp;* &nbsp;tmpArray.randomize();<br
/> &nbsp;*/</span><br
/> Array.<span
style="color: #660066;">prototype</span>.<span
style="color: #660066;">randomize</span> <span
style="color: #339933;">=</span> <span
style="color: #003366; font-weight: bold;">function</span> <span
style="color: #009900;">&#40;</span><span
style="color: #009900;">&#41;</span><span
style="color: #009900;">&#123;</span><br
/> &nbsp; &nbsp; <span
style="color: #000066; font-weight: bold;">this</span>.<span
style="color: #660066;">sort</span><span
style="color: #009900;">&#40;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #003366; font-weight: bold;">function</span><span
style="color: #009900;">&#40;</span>a<span
style="color: #339933;">,</span>b<span
style="color: #009900;">&#41;</span> <span
style="color: #009900;">&#123;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #000066; font-weight: bold;">return</span> Math.<span
style="color: #660066;">round</span><span
style="color: #009900;">&#40;</span> Math.<span
style="color: #660066;">random</span><span
style="color: #009900;">&#40;</span><span
style="color: #009900;">&#41;</span> <span
style="color: #339933;">*</span> <span
style="color: #CC0000;">2</span> <span
style="color: #009900;">&#41;</span> <span
style="color: #339933;">-</span> <span
style="color: #CC0000;">1</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #009900;">&#125;</span><br
/> &nbsp; &nbsp; <span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span><br
/> <span
style="color: #009900;">&#125;</span><span
style="color: #339933;">;</span></div></div><p>The principle of this implementation is simple. It takes advantage of the comparison <samp>Function</samp> that can be passed to the <samp>Array.sort()</samp> method. This function defines the sort order. It will be passed two objects (from the array) <samp>a</samp> and <samp>b</samp>, compare them and return <samp>-1</samp>, <samp>0</samp> or <samp>1</samp> whether <samp>a</samp> is less, equal or greater than <samp>b</samp>. The idea, to shuffle an array, is to randomly output <samp>-1</samp>, <samp>0</samp> or <samp>1</samp>. This is the purpose of the expression <samp>Math.round( Math.random() * 2 ) &#8211; 1</samp>. This idea is bad.</p><h2>Shuffling an array with <samp>Array.sort()</samp> results in&#8230; a not so shuffled array</h2><p>Implementing a shuffle function on arrays, this way, is bad. At first glance it seems to produce well randomized arrays, but the random distribution is not uniform. I will illustrate this in a minute. Before that, give a look at the table below. It&#8217;s interactive. When you click start, it will run the following process :</p><ol><li> Create an array with ten letters in alphabetical orders from A to J</p><div
class="codecolorer-container javascript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div
class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color: #003366; font-weight: bold;">var</span> simpleArray <span
style="color: #339933;">=</span> <span
style="color: #009900;">&#91;</span><span
style="color: #3366CC;">&quot;A&quot;</span><span
style="color: #339933;">,</span><span
style="color: #3366CC;">&quot;B&quot;</span><span
style="color: #339933;">,</span><span
style="color: #3366CC;">&quot;C&quot;</span><span
style="color: #339933;">,</span><span
style="color: #3366CC;">&quot;D&quot;</span><span
style="color: #339933;">,</span><span
style="color: #3366CC;">&quot;E&quot;</span><span
style="color: #339933;">,</span><span
style="color: #3366CC;">&quot;F&quot;</span><span
style="color: #339933;">,</span><span
style="color: #3366CC;">&quot;G&quot;</span><span
style="color: #339933;">,</span><span
style="color: #3366CC;">&quot;H&quot;</span><span
style="color: #339933;">,</span><span
style="color: #3366CC;">&quot;I&quot;</span><span
style="color: #339933;">,</span><span
style="color: #3366CC;">&quot;J&quot;</span><span
style="color: #009900;">&#93;</span><span
style="color: #339933;">;</span></div></div></li><li>Copy this array in a second array</li><li>Run a shuffle algorithm against the second array</li><li>Look where the letters are in the second array and record their position in the table columns</li><li>Return to the step 2 and start the process again until a certain number of iterations has been reached</li></ol><p>This repetitive process is pretty simple. It is not intended to give a mathematical evidence of the problem but to illustrate the consequences of a badly implemented shuffle algorithm. Note that the copy at step 2 is always made from the original array (not from the last shuffled array).</p><p>In this first example and to make sure you understand how this table work, step 3 is bypassed. Thus the copied array is always exactly the same as the original one. Click on <em>Start</em> button will launch the process (The number of iterations can be changed).</p><div
id="noshuffle"></div><p>Normally, at the end of the process, you should see a table full of zeros with only the diagonal (top-left / bottom-right) filled with the number of iterations. It means that, at every steps, letters in the second array are at the same position than in the first one. This is what was expected because there is no shuffle.</p><p>Let&#8217;s do the same thing but now step 3 uses the shuffle algorithm we have seen before.</p><div
id="arraysort"></div><p>The result is interesting, isn&#8217;t it ? The position of letters has well been set randomly over iterations. Almost every cells in the table are filled with numbers. Let&#8217;s give a closer look. Actually, the nearer a cell is from the diagonal (top-left / bottom-right) the higher its number. Moreover there are still zeros in some cells far from this diagonal. Obviously, it means letters are more likely to be near their original position, after a shuffle.</p><h2>How to better shuffle an array with <samp>Array.sort()</samp> ?</h2><p>We said the comparison function returned randomly either <samp>-1</samp>, <samp>0</samp> or <samp>1</samp>. What exactly happens in each case ? Let&#8217;s quote the Mozilla developer Center for the <a
href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/sort#Description"><samp>Array.sort()</samp> comparison function description</a></p><div
style="padding:1em 4em; font-size:1.1em;"> If <samp>compareFunction</samp> is supplied, the array elements are sorted according to the return value of the compare function. If a and b are two elements being compared, then:</p><ul><li>If <samp>compareFunction(a, b)</samp> is less than 0, sort <samp>a</samp> to a lower index than <samp>b</samp>.</li><li>If <samp>compareFunction(a, b)</samp> returns 0, leave <samp>a</samp> and <samp>b</samp> unchanged with respect to each other, but sorted with respect to all different elements. Note: the ECMAscript standard does not guarantee this behaviour, and thus not all browsers (e.g. Mozilla versions dating back to at least 2003) respect this.</li><li>If <samp>compareFunction(a, b)</samp> is greater than 0, sort <samp>b</samp> to a lower index than <samp>a</samp>.</li></ul></div><p>The <samp>Array.sort()</samp> method uses a <a
href="http://en.wikipedia.org/wiki/Bubble_sort">Bubble Sort algorithm</a>. Roughly, it steps through array elements and compare each one with its next adjacent element. It swaps the elements when the comparison function return <samp>1</samp>. What does it do when the comparison function return <samp>0</samp> or <samp>-1</samp> ? Actually nothing and here is the issue ! As the comparison function randomly generate <samp>-1</samp>, <samp>0</samp> or <samp>1</samp>, each of those numbers has the same chance to arise. Unfortunately a letter can change its position only if <samp>1</samp> arises. It means that a letter has twice the chance not to move than to move !</p><p>So to resolve the issue the comparison function must not generate 3 numbers randomly but only two : <samp>0</samp> or <samp>1</samp>. Thus a letter has the same chance to move than to stay in place. Below is the new implementation (Note that it is simpler than the previous one).</p><div
class="codecolorer-container javascript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div
class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color: #006600; font-style: italic;">/**<br
/> &nbsp;* Add a randomize method to the Array object prototype<br
/> &nbsp;* Usage : <br
/> &nbsp;* &nbsp;var tmpArray = [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e&quot;];<br
/> &nbsp;* &nbsp;tmpArray.randomize2();<br
/> &nbsp;*/</span><br
/> Array.<span
style="color: #660066;">prototype</span>.<span
style="color: #660066;">randomize2</span> <span
style="color: #339933;">=</span> <span
style="color: #003366; font-weight: bold;">function</span> <span
style="color: #009900;">&#40;</span><span
style="color: #009900;">&#41;</span><span
style="color: #009900;">&#123;</span><br
/> &nbsp; &nbsp; <span
style="color: #000066; font-weight: bold;">this</span>.<span
style="color: #660066;">sort</span><span
style="color: #009900;">&#40;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #003366; font-weight: bold;">function</span><span
style="color: #009900;">&#40;</span>a<span
style="color: #339933;">,</span>b<span
style="color: #009900;">&#41;</span> <span
style="color: #009900;">&#123;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #000066; font-weight: bold;">return</span> &nbsp;Math.<span
style="color: #660066;">round</span><span
style="color: #009900;">&#40;</span> Math.<span
style="color: #660066;">random</span><span
style="color: #009900;">&#40;</span><span
style="color: #009900;">&#41;</span> <span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #009900;">&#125;</span><br
/> &nbsp; &nbsp; <span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span><br
/> <span
style="color: #009900;">&#125;</span><span
style="color: #339933;">;</span></div></div><p>The following table shows the result of this new implementation :</p><div
id="arraysort2"></div><p>This result seems much more random than the previous one. There are much less zeros filling the table, however we can still see a kind of diagonal pattern where higher numbers seem much more on the diagonal. It is less obvious than before but still there. The reason for this can be found in the Bubble Sort algorithm and its implementation. Think about if A &lt; B and B &lt; C then not need to compare A and C.Thus, some comparisons are not done and optimization in code results in a greater efficiency to sort but an issue when shuffle.</p><p><em>Update : it seems there are differences between browsers. Notably, the method explained here is more accurate in Firefox but less in IE. Both gives bad uniform random, though. Not tested in other browsers</em></p><h2>Shuffle arrays the good way</h2><p>Fortunately it is not required to use <samp>Array.sort()</samp> to shuffle an array. Implement a shuffle function using <a
href="http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle">Fisher-Yates algorithm</a> is better and still easy.</p><p>Below is the code implementing a shuffle function using the Fisher-Yates algorithm. This algorithm provides uniform random.</p><div
class="codecolorer-container javascript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div
class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color: #006600; font-style: italic;">/*<br
/> &nbsp;* Add a shuffle function to Array object prototype<br
/> &nbsp;* Usage : <br
/> &nbsp;* &nbsp;var tmpArray = [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e&quot;];<br
/> &nbsp;* &nbsp;tmpArray.shuffle();<br
/> &nbsp;*/</span><br
/> Array.<span
style="color: #660066;">prototype</span>.<span
style="color: #660066;">shuffle</span> <span
style="color: #339933;">=</span> <span
style="color: #003366; font-weight: bold;">function</span> <span
style="color: #009900;">&#40;</span><span
style="color: #009900;">&#41;</span><span
style="color: #009900;">&#123;</span><br
/> &nbsp; &nbsp; <span
style="color: #003366; font-weight: bold;">var</span> i <span
style="color: #339933;">=</span> <span
style="color: #000066; font-weight: bold;">this</span>.<span
style="color: #660066;">length</span><span
style="color: #339933;">,</span> j<span
style="color: #339933;">,</span> temp<span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; <span
style="color: #000066; font-weight: bold;">if</span> <span
style="color: #009900;">&#40;</span> i <span
style="color: #339933;">==</span> <span
style="color: #CC0000;">0</span> <span
style="color: #009900;">&#41;</span> <span
style="color: #000066; font-weight: bold;">return</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; <span
style="color: #000066; font-weight: bold;">while</span> <span
style="color: #009900;">&#40;</span> <span
style="color: #339933;">--</span>i <span
style="color: #009900;">&#41;</span> <span
style="color: #009900;">&#123;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; j <span
style="color: #339933;">=</span> Math.<span
style="color: #660066;">floor</span><span
style="color: #009900;">&#40;</span> Math.<span
style="color: #660066;">random</span><span
style="color: #009900;">&#40;</span><span
style="color: #009900;">&#41;</span> <span
style="color: #339933;">*</span> <span
style="color: #009900;">&#40;</span> i <span
style="color: #339933;">+</span> <span
style="color: #CC0000;">1</span> <span
style="color: #009900;">&#41;</span> <span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; temp <span
style="color: #339933;">=</span> <span
style="color: #000066; font-weight: bold;">this</span><span
style="color: #009900;">&#91;</span>i<span
style="color: #009900;">&#93;</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #000066; font-weight: bold;">this</span><span
style="color: #009900;">&#91;</span>i<span
style="color: #009900;">&#93;</span> <span
style="color: #339933;">=</span> <span
style="color: #000066; font-weight: bold;">this</span><span
style="color: #009900;">&#91;</span>j<span
style="color: #009900;">&#93;</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #000066; font-weight: bold;">this</span><span
style="color: #009900;">&#91;</span>j<span
style="color: #009900;">&#93;</span> <span
style="color: #339933;">=</span> temp<span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; <span
style="color: #009900;">&#125;</span><br
/> <span
style="color: #009900;">&#125;</span><span
style="color: #339933;">;</span></div></div><p>To prove the superiority of Fisher-Yates algorithm in <samp>Array.sort()</samp> implementation play with the table below.</p><div
id="shuffle"></div><p>With these results, it is obvious that this algorithm is far more efficient in distributing uniformly the letters in the array over iterations than <samp>Array.sort()</samp> style algorithms. Distribution is much more the same across cells.</p><div
class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center"><ul
class="socials"><li
class="shr-delicious"> <a
href="http://delicious.com/post?url=http://sroucheray.org/blog/2009/11/array-sort-should-not-be-used-to-shuffle-an-array/&amp;title=Array.sort%28%29+should+not+be+used+to+shuffle+an+array" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a></li><li
class="shr-digg"> <a
href="http://digg.com/submit?phase=2&amp;url=http://sroucheray.org/blog/2009/11/array-sort-should-not-be-used-to-shuffle-an-array/&amp;title=Array.sort%28%29+should+not+be+used+to+shuffle+an+array" rel="nofollow" class="external" title="Digg this!">Digg this!</a></li><li
class="shr-facebook"> <a
href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://sroucheray.org/blog/2009/11/array-sort-should-not-be-used-to-shuffle-an-array/&amp;t=Array.sort%28%29+should+not+be+used+to+shuffle+an+array" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a></li><li
class="shr-googlebuzz"> <a
href="http://www.google.com/buzz/post?url=http://sroucheray.org/blog/2009/11/array-sort-should-not-be-used-to-shuffle-an-array/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a></li><li
class="shr-linkedin"> <a
href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://sroucheray.org/blog/2009/11/array-sort-should-not-be-used-to-shuffle-an-array/&amp;title=Array.sort%28%29+should+not+be+used+to+shuffle+an+array&amp;summary=When%20a%20developer%20searches%20the%20web%20for%20an%20algorithm%20to%20shuffle%20an%20array%20in%20JavaScript%20or%20ActionScript%2C%20he%20will%20surely%20find%20a%20way%20to%20achieve%20that%20using%20the%20Array.sort%28%29%20method%20%28see%20references%20%3A%20JavaScript%2C%20ActionScript%203%29...&amp;source=Lambda" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a></li><li
class="shr-reddit"> <a
href="http://reddit.com/submit?url=http://sroucheray.org/blog/2009/11/array-sort-should-not-be-used-to-shuffle-an-array/&amp;title=Array.sort%28%29+should+not+be+used+to+shuffle+an+array" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a></li><li
class="shr-stumbleupon"> <a
href="http://www.stumbleupon.com/submit?url=http://sroucheray.org/blog/2009/11/array-sort-should-not-be-used-to-shuffle-an-array/&amp;title=Array.sort%28%29+should+not+be+used+to+shuffle+an+array" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a></li><li
class="shr-twitter"> <a
href="http://twitter.com/home?status=Array.sort%28%29+should+not+be+used+to+shuffle+an+array+-+http://bit.ly/diyrW4&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a></li><li
class="shr-yahoobuzz"> <a
href="http://buzz.yahoo.com/submit/?submitUrl=http://sroucheray.org/blog/2009/11/array-sort-should-not-be-used-to-shuffle-an-array/&amp;submitHeadline=Array.sort%28%29+should+not+be+used+to+shuffle+an+array&amp;submitSummary=When%20a%20developer%20searches%20the%20web%20for%20an%20algorithm%20to%20shuffle%20an%20array%20in%20JavaScript%20or%20ActionScript%2C%20he%20will%20surely%20find%20a%20way%20to%20achieve%20that%20using%20the%20Array.sort%28%29%20method%20%28see%20references%20%3A%20JavaScript%2C%20ActionScript%203%29...&amp;submitCategory=science&amp;submitAssetType=text" rel="nofollow" class="external" title="Buzz up!">Buzz up!</a></li></ul><div
style="clear:both;"></div></div>]]></content:encoded> <wfw:commentRss>http://sroucheray.org/blog/2009/11/array-sort-should-not-be-used-to-shuffle-an-array/feed/</wfw:commentRss> <slash:comments>9</slash:comments> </item> <item><title>How to get a mouse hand over a TextField in AS3 ?</title><link>http://sroucheray.org/blog/2009/11/how-to-get-a-mouse-hand-over-a-textfield-in-as3/</link> <comments>http://sroucheray.org/blog/2009/11/how-to-get-a-mouse-hand-over-a-textfield-in-as3/#comments</comments> <pubDate>Fri, 13 Nov 2009 09:16:49 +0000</pubDate> <dc:creator>Stéphane Roucheray</dc:creator> <category><![CDATA[ActionScript]]></category> <category><![CDATA[Flash]]></category> <category><![CDATA[Hand]]></category> <category><![CDATA[JavaScript]]></category> <category><![CDATA[Mouse]]></category> <category><![CDATA[MouseOver]]></category><guid
isPermaLink="false">http://sroucheray.org/blog/?p=363</guid> <description><![CDATA[It's pretty simple...]]></description> <content:encoded><![CDATA[<p>It&#8217;s pretty simple, <tt>buttonMode</tt> and <tt>mouseChildren</tt> properties of the <tt><a
href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/text/TextField.html">TextField</a></tt> parent should be set like that :</p><div
class="codecolorer-container actionscript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div
class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color: #000000; font-weight: bold;">var</span> sprite : Sprite = <span
style="color: #000000; font-weight: bold;">new</span> Sprite<span
style="color: #66cc66;">&#40;</span><span
style="color: #66cc66;">&#41;</span>;<br
/> <span
style="color: #000000; font-weight: bold;">var</span> <span
style="color: #0066CC;">textField</span> : <span
style="color: #0066CC;">TextField</span> = <span
style="color: #000000; font-weight: bold;">new</span> <span
style="color: #0066CC;">TextField</span><span
style="color: #66cc66;">&#40;</span><span
style="color: #66cc66;">&#41;</span>;<br
/> sprite.<span
style="color: #006600;">addChild</span><span
style="color: #66cc66;">&#40;</span><span
style="color: #0066CC;">textField</span><span
style="color: #66cc66;">&#41;</span>;<br
/> <br
/> sprite.<span
style="color: #006600;">buttonMode</span> = <span
style="color: #000000; font-weight: bold;">true</span>;<br
/> sprite.<span
style="color: #006600;">mouseChildren</span> = <span
style="color: #000000; font-weight: bold;">false</span>;</div></div><div
class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center"><ul
class="socials"><li
class="shr-delicious"> <a
href="http://delicious.com/post?url=http://sroucheray.org/blog/2009/11/how-to-get-a-mouse-hand-over-a-textfield-in-as3/&amp;title=How+to+get+a+mouse+hand+over+a+TextField+in+AS3+%3F" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a></li><li
class="shr-digg"> <a
href="http://digg.com/submit?phase=2&amp;url=http://sroucheray.org/blog/2009/11/how-to-get-a-mouse-hand-over-a-textfield-in-as3/&amp;title=How+to+get+a+mouse+hand+over+a+TextField+in+AS3+%3F" rel="nofollow" class="external" title="Digg this!">Digg this!</a></li><li
class="shr-facebook"> <a
href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://sroucheray.org/blog/2009/11/how-to-get-a-mouse-hand-over-a-textfield-in-as3/&amp;t=How+to+get+a+mouse+hand+over+a+TextField+in+AS3+%3F" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a></li><li
class="shr-googlebuzz"> <a
href="http://www.google.com/buzz/post?url=http://sroucheray.org/blog/2009/11/how-to-get-a-mouse-hand-over-a-textfield-in-as3/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a></li><li
class="shr-linkedin"> <a
href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://sroucheray.org/blog/2009/11/how-to-get-a-mouse-hand-over-a-textfield-in-as3/&amp;title=How+to+get+a+mouse+hand+over+a+TextField+in+AS3+%3F&amp;summary=It%27s%20pretty%20simple...&amp;source=Lambda" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a></li><li
class="shr-reddit"> <a
href="http://reddit.com/submit?url=http://sroucheray.org/blog/2009/11/how-to-get-a-mouse-hand-over-a-textfield-in-as3/&amp;title=How+to+get+a+mouse+hand+over+a+TextField+in+AS3+%3F" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a></li><li
class="shr-stumbleupon"> <a
href="http://www.stumbleupon.com/submit?url=http://sroucheray.org/blog/2009/11/how-to-get-a-mouse-hand-over-a-textfield-in-as3/&amp;title=How+to+get+a+mouse+hand+over+a+TextField+in+AS3+%3F" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a></li><li
class="shr-twitter"> <a
href="http://twitter.com/home?status=How+to+get+a+mouse+hand+over+a+TextField+in+AS3+%3F+-+http://bit.ly/96dz7T&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a></li><li
class="shr-yahoobuzz"> <a
href="http://buzz.yahoo.com/submit/?submitUrl=http://sroucheray.org/blog/2009/11/how-to-get-a-mouse-hand-over-a-textfield-in-as3/&amp;submitHeadline=How+to+get+a+mouse+hand+over+a+TextField+in+AS3+%3F&amp;submitSummary=It%27s%20pretty%20simple...&amp;submitCategory=science&amp;submitAssetType=text" rel="nofollow" class="external" title="Buzz up!">Buzz up!</a></li></ul><div
style="clear:both;"></div></div>]]></content:encoded> <wfw:commentRss>http://sroucheray.org/blog/2009/11/how-to-get-a-mouse-hand-over-a-textfield-in-as3/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Flash Toolbox</title><link>http://sroucheray.org/blog/2009/09/flash-toolbox/</link> <comments>http://sroucheray.org/blog/2009/09/flash-toolbox/#comments</comments> <pubDate>Sun, 27 Sep 2009 10:35:58 +0000</pubDate> <dc:creator>Stéphane Roucheray</dc:creator> <category><![CDATA[ActionScript]]></category> <category><![CDATA[Flash]]></category><guid
isPermaLink="false">http://sroucheray.org/blog/?p=272</guid> <description><![CDATA[I maintain here some ActionScript3 tools and frameworks I use in my day to day work.]]></description> <content:encoded><![CDATA[<p><em>Last update Wednesday, December 2, 2009</em></p><p>I maintain here some ActionScript3 tools and frameworks I use in my day to day work. This list is not intended to reflect all tools you can Google out there, just the ones I use. If you know something I should test and add here, <a
href="http://sroucheray.org/blog/contact/">send me an email</a>.</p><h2 id="editors">Editors</h2><ul><li> <strong>FDT</strong> : <a
href="http://fdt.powerflasher.com/">http://fdt.powerflasher.com/</a><p>The best ActionScript editor I have used so far. Based on Eclipse : syntax and error highlighting, completion, debugger&#8230;</p><p><em>Alternatives : <a
href="http://www.flashdevelop.org/wikidocs/index.php?title=Main_Page">Flash Develop</a> | <a
href="http://www.adobe.com/products/flex/">Flex Builder</a></em><br
/> <em>Must have tool : <a
href="http://www.rozengain.com/blog/2009/10/09/eclipse-plug-in-download-as3-libraries-straight-to-your-eclipseflex-builderfdt-project/">eclipse-plug-in-download-as3-libraries-straight-to-your-eclipseflex-builderfdt-project</a> quite a long but expressive name, isn&#8217;t it ?</em></li><li> <strong>Notepad++</strong> : <a
href="http://notepad-plus.sourceforge.net/">http://notepad-plus.sourceforge.net/</a><p> Not specially dedicated to ActionScript but really handy to open all kind of files with colour highlighting (AS, XML, JS, HTML) and to make quick modifications or to do repetitive tasks (a lot of plugins included by default).</p></li></ul><h2 id="frameworks">Frameworks</h2><ul><li> <strong>AMFPHP</strong> : <a
href="http://www.amfphp.org/">http://www.amfphp.org/</a></p><p> Ease communication between ActionScript and PHP.</p></li><li> <strong>AS3Dmod</strong> : <a
href="http://code.google.com/p/as3dmod/">http://code.google.com/p/as3dmod/</a> | <a
href="http://www.everydayflash.com/flash/as3dmod/doc/">API</a><p>3D modifiers for Papervision 3D. Intended to change 3D objects aspect applying constraints on them.</li><li> <strong>Papervision3D</strong> : <a
href="http://dev.papervision3d.org/">http://dev.papervision3d.org/</a> | <a
href="http://papervision3d.googlecode.com/svn/trunk/as3/trunk/docs/index.html">API</a><p>Realtime 3D engine.</p><p><em>Alternatives : <a
href="http://away3d.com/">Away 3D</a>, <a
href="http://www.flashsandy.org/">Sandy</a></em><br
/> <em>Must have tools : <a
href="http://www.rozengain.com/blog/2008/01/02/export-your-blender-objects-straight-to-away3d-papervision3d-and-sandy/">Blender to AS3 export</a>, <a
href="http://blog.anthony-scavarelli.com/?p=77">Air Collada Viewer</a>, <a
href="http://www.closier.nl/prefab/">Air Prefab : Away3D texture mapping</a></em></li><li> <strong>Gaia Flash Framework</strong> : <a
href="http://www.gaiaflashframework.com/">http://www.gaiaflashframework.com/</a><p>A flash site or module manager. It handles pages, transitions, depth, assets&#8230; A great tool for developers when they work with artists.</p></li><li> <strong>Tweenlite / Tweenmax</strong> : <a
href="http://blog.greensock.com/tweenliteas3/">http://blog.greensock.com/tweenliteas3/</a><p>Great tweening engine : help to manage transitions incrementing or decrementing any number values of any object during a specified amount of time. It offers several transitions curves.<br
/> <em><br
/> Alternatives : <a
href="http://code.google.com/p/tweener/">Tweener</a> | <a
href="http://gskinner.com/libraries/gtween/">gTween</a></em></li><li> <strong>Thunderbolt</strong> : <a
href="http://code.google.com/p/flash-thunderbolt/">http://code.google.com/p/flash-thunderbolt/</a><p>Logging in FDT, Flash IDE and Firebug ! What else ?</p></li><li> <strong>Mr. Doob</strong> : <a
href="http://code.google.com/p/mrdoob/">http://code.google.com/p/mrdoob/</a><p>Useful bunch of classes : <a
href="http://code.google.com/p/mrdoob/wiki/stats">Stats</a>, <a
href="http://code.google.com/p/mrdoob/wiki/videoplayer">Video player</a></p></li></ul><h2 id="javascript">JavaScript</h2><ul><li> <strong>SWFObject2</strong> : <a
href="http://code.google.com/p/swfobject/">http://code.google.com/p/swfobject/</a><p>Safely embed SWF files in Web pages without struggling with browser detection and specific implementations.</li><li> <strong>SWFFIT</strong> : <a
href="http://swffit.millermedeiros.com/">http://swffit.millermedeiros.com/</a><p> Smartly activate scrollbars to the browser if a SWF object is greater than the size of the browser window. Great for full Flash sites !</p></li></ul><div
class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center"><ul
class="socials"><li
class="shr-delicious"> <a
href="http://delicious.com/post?url=http://sroucheray.org/blog/2009/09/flash-toolbox/&amp;title=Flash+Toolbox" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a></li><li
class="shr-digg"> <a
href="http://digg.com/submit?phase=2&amp;url=http://sroucheray.org/blog/2009/09/flash-toolbox/&amp;title=Flash+Toolbox" rel="nofollow" class="external" title="Digg this!">Digg this!</a></li><li
class="shr-facebook"> <a
href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://sroucheray.org/blog/2009/09/flash-toolbox/&amp;t=Flash+Toolbox" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a></li><li
class="shr-googlebuzz"> <a
href="http://www.google.com/buzz/post?url=http://sroucheray.org/blog/2009/09/flash-toolbox/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a></li><li
class="shr-linkedin"> <a
href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://sroucheray.org/blog/2009/09/flash-toolbox/&amp;title=Flash+Toolbox&amp;summary=I%20maintain%20here%20some%20ActionScript3%20tools%20and%20frameworks%20I%20use%20in%20my%20day%20to%20day%20work.&amp;source=Lambda" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a></li><li
class="shr-reddit"> <a
href="http://reddit.com/submit?url=http://sroucheray.org/blog/2009/09/flash-toolbox/&amp;title=Flash+Toolbox" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a></li><li
class="shr-stumbleupon"> <a
href="http://www.stumbleupon.com/submit?url=http://sroucheray.org/blog/2009/09/flash-toolbox/&amp;title=Flash+Toolbox" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a></li><li
class="shr-twitter"> <a
href="http://twitter.com/home?status=Flash+Toolbox+-+http://bit.ly/9YUZZF&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a></li><li
class="shr-yahoobuzz"> <a
href="http://buzz.yahoo.com/submit/?submitUrl=http://sroucheray.org/blog/2009/09/flash-toolbox/&amp;submitHeadline=Flash+Toolbox&amp;submitSummary=I%20maintain%20here%20some%20ActionScript3%20tools%20and%20frameworks%20I%20use%20in%20my%20day%20to%20day%20work.&amp;submitCategory=science&amp;submitAssetType=text" rel="nofollow" class="external" title="Buzz up!">Buzz up!</a></li></ul><div
style="clear:both;"></div></div>]]></content:encoded> <wfw:commentRss>http://sroucheray.org/blog/2009/09/flash-toolbox/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced) (user agent is rejected)
Database Caching using disk

Served from: sroucheray.org @ 2010-07-31 15:06:45 -->