<?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>SavageLook.com</title>
	<atom:link href="http://savagelook.com/blog/feed" rel="self" type="application/rss+xml" />
	<link>http://savagelook.com/blog</link>
	<description>Blowing your mind, one line of code at a time</description>
	<lastBuildDate>Tue, 31 Aug 2010 23:39:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Reflection in Away3D</title>
		<link>http://savagelook.com/blog/away3d/reflection-in-away3d</link>
		<comments>http://savagelook.com/blog/away3d/reflection-in-away3d#comments</comments>
		<pubDate>Tue, 31 Aug 2010 20:57:27 +0000</pubDate>
		<dc:creator>Tony Lukasavage</dc:creator>
				<category><![CDATA[ActionScript3]]></category>
		<category><![CDATA[Away3D]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Code Demos]]></category>
		<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[reflection]]></category>

		<guid isPermaLink="false">http://savagelook.com/blog/?p=593</guid>
		<description><![CDATA[Create real-time reflections in Away3D using some trickery with render sessions and BitmapData<p><a href="http://savagelook.com/blog/away3d/reflection-in-away3d">Reflection in Away3D</a> is a post from: <a href="http://savagelook.com/blog">SavageLook.com</a></p>
]]></description>
			<content:encoded><![CDATA[<p><a rel="shadowbox;width=800;height=600;" href="http://savagelook.com/demos/reflect_away3d/reflect_away3d.html"><img class="size-full wp-image-629" title="Reflection in Away3D" src="http://savagelook.com/blog/wp-content/uploads/2010/08/reflect3.jpg" alt="Reflection in Away3D" width="584" height="304" /></a></p>
<p>→ <a rel="shadowbox;width=800;height=600;" href="http://savagelook.com/demos/reflect_away3d/reflect_away3d.html">Click here</a> or the image above for the reflection demo<br />
→ <a href="http://savagelook.com/demos/reflect_away3d/srcview/index.html">View the source code</a><br />
→ <a href="http://savagelook.com/misc/reflect_away3d.zip">Download the source code</a></p>
<p>I alluded to a desire to implement reflections in Away3D in my prior post on <a href="http://savagelook.com/blog/code/reflection-in-as3">reflections in AS3</a>.  Well here it is.  It wasn&#8217;t quite as easy of a translation as I thought it would be, but with lots of digging through the <a href="http://groups.google.com/group/away3d-dev/browse_thread/thread/4b520ebf4f7953d7/0052eb24c4178190" target="_blank">Away3D dev list</a>, as well as spotting a good example at <a href="http://www.geepers.co.uk/software/viewreflection.html" target="_blank">geepers.co.uk</a>, I managed to get a basic demo up and running.</p>
<p>While there&#8217;s a good bit of code that goes into this demo, the secret sauce is right here:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">  <span style="color: #009900;">// must render before making the following calls</span>
  _view.<span style="color: #004993;">render</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
  <span style="color: #009900;">// find 2d bounding box of sphere</span>
  _drawn = <span style="color: #000000;">&#40;</span>_view.session.getContainer<span style="color: #000000;">&#40;</span>_view<span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> <span style="color: #004993;">DisplayObjectContainer</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">getChildAt</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
  _bounds = _drawn.<span style="color: #004993;">getRect</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>What this code does is give us the DisplayObject that contains our 3D object within the given view.  We are also able to determine the bounds of the DisplayObject and its 2 dimensional position within the view.  With this information we are able to effectively create a snapshot of the visible 3d object.  From there we need to create BitmapData that is the inverse of the DisplayObject.  To do that we apply the appropriate matrix (invert the y scale) to the DisplayObject when it is drawn to BitmapData.  After that we assign the BitmapData to the display Bitmap and then position it according to the bounds of the DisplayObject.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">  <span style="color: #009900;">// redraw reflection</span>
  _bmd = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">BitmapData</span><span style="color: #000000;">&#40;</span>_drawn.<span style="color: #004993;">width</span>, _drawn.<span style="color: #004993;">height</span>, <span style="color: #0033ff; font-weight: bold;">true</span>, 0x00ffffff<span style="color: #000000;">&#41;</span>;
  _matrix.<span style="color: #004993;">createBox</span><span style="color: #000000;">&#40;</span>_xscale, <span style="color: #000000; font-weight: bold;">-</span>_yscale, <span style="color: #000000; font-weight:bold;">0</span>, _drawn.<span style="color: #004993;">width</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span>, _drawn.<span style="color: #004993;">height</span> <span style="color: #000000; font-weight: bold;">*</span> _yscale <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span>;
  _bmd.<span style="color: #004993;">draw</span><span style="color: #000000;">&#40;</span>_drawn, _matrix<span style="color: #000000;">&#41;</span>;
  _bitmapReflect.<span style="color: #004993;">bitmapData</span> = _bmd;
  _bitmapReflect.<span style="color: #004993;">x</span> = _bounds.<span style="color: #004993;">x</span>;
  _bitmapReflect.<span style="color: #004993;">y</span> = <span style="color: #004993;">stage</span>.<span style="color: #004993;">stageHeight</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000; font-weight: bold;">+</span> _distance;</pre></div></div>

<p>Finally we create an alpha gradient mask that will be applied to the Bitmap in order to give it that cool, fading reflection look.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">  <span style="color: #009900;">// redraw gradient mask for reflection</span>
  _matrix.<span style="color: #004993;">createGradientBox</span><span style="color: #000000;">&#40;</span>_bitmapReflect.<span style="color: #004993;">width</span>, _bitmapReflect.<span style="color: #004993;">height</span> <span style="color: #000000; font-weight: bold;">*</span> _yscale <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span>, <span style="color: #004993;">Math</span>.<span style="color: #004993;">PI</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span>, <span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
  _bitmapReflectGradient.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
  _bitmapReflectGradient.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">beginGradientFill</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;linear&quot;</span>, <span style="color: #000000;">&#91;</span>0xffffff, 0xffffff<span style="color: #000000;">&#93;</span>, <span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0.9</span>, <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span>, <span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #000000; font-weight:bold;">255</span><span style="color: #000000;">&#93;</span>, _matrix<span style="color: #000000;">&#41;</span>;
  _bitmapReflectGradient.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">drawRect</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #000000; font-weight:bold;">0</span>, _bitmapReflect.<span style="color: #004993;">width</span>, _bitmapReflect.<span style="color: #004993;">height</span><span style="color: #000000;">&#41;</span>;
  _bitmapReflectGradient.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
  _bitmapReflectGradient.<span style="color: #004993;">x</span> = _bitmapReflect.<span style="color: #004993;">x</span>;
  _bitmapReflectGradient.<span style="color: #004993;">y</span> = _bitmapReflect.<span style="color: #004993;">y</span>;</pre></div></div>

<p>And there you go, reflections in Away3D.  There are a number of limitations to this method, though:</p>
<ul>
<li>It can only draw reflections of objects currently visible in the view.  In fact, there should be a check on the<br />
<em>(_view.session.getContainer(_view) as DisplayObjectContainer).getChildAt(0) </em><br />
call to make sure that the view contains any children.</li>
<li>The reflection is drawn of the entire view, not just the object in question.  That&#8217;s why this works best with only one object in the view.  You can use multiple views to get reflections for multiple objects.</li>
<li>This example only does reflections of the view as its manipulated along the X &amp; Y planes.  Moving the object along the Z plane will not effect the reflection properly.  I&#8217;m sure a method utilizing planes could do better.</li>
</ul>
<p>If those limitations don&#8217;t bother you, then go to town.  If they do, be patient.  I&#8217;m working on another idea for reflection in Away3D that will be a lot more flexible, though more complex and processor intensive.  </p>
<p>Remember how my <a href="http://savagelook.com/blog/away3d/away3d-simpleshadow-and-simple-shadows">previous blog post on shadows</a> (of course you do) showed how you can easily enhance the 3D feel of your site?  Of course you do.  Now you can add reflections to that repetoire.  It&#8217;s all about subtle changes to give your work a more polished look and feel.  Have fun and let me know if you create reflections this way, or if you have an implementation of your own.</p>
<p><a href="http://savagelook.com/blog/away3d/reflection-in-away3d">Reflection in Away3D</a> is a post from: <a href="http://savagelook.com/blog">SavageLook.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://savagelook.com/blog/away3d/reflection-in-away3d/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Configure Flex SDK in Flash Builder 4</title>
		<link>http://savagelook.com/blog/flash-builder-4/configure-flex-sdk-in-flash-builder-4</link>
		<comments>http://savagelook.com/blog/flash-builder-4/configure-flex-sdk-in-flash-builder-4#comments</comments>
		<pubDate>Fri, 27 Aug 2010 18:06:59 +0000</pubDate>
		<dc:creator>Tony Lukasavage</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Flash Builder 4]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Portfolio]]></category>

		<guid isPermaLink="false">http://savagelook.com/blog/?p=502</guid>
		<description><![CDATA[A quick guide to installing a new Flex SDK version in Flash Builder 4 <p><a href="http://savagelook.com/blog/flash-builder-4/configure-flex-sdk-in-flash-builder-4">Configure Flex SDK in Flash Builder 4</a> is a post from: <a href="http://savagelook.com/blog">SavageLook.com</a></p>
]]></description>
			<content:encoded><![CDATA[<p>OK, this is a pretty boring update to the blog, but I thought it might be useful to at least a handful of people.  Flash Builder 4 comes with a stock version of the Flex 3.5 and 4.0 SDKs.  If you are like me, though, you want the latest and greatest as soon as you can get your hands on it.  For that reason I put together this very short and simple explanation of how to install specific Flex SDKs for your Flash Builder 4.  For those familiar with Flex Builder 3, this will seem pretty familiar.</p>
<p>- <b>FLASH_BUILDER_4_HOME</b> is your Flash Builder 4 install path (i.e., C:\Program Files\Adobe\Flash Builder 4)<br />
- <b> SDK_VERSION</b> is the version number of your Flex SDK (i.e., 4.1.0)</p>
<ol>
<li>Get your desired Flex SDK from the <a href="http://opensource.adobe.com/wiki/display/flexsdk/Downloads" target="_blank">Flex SDK Download page</a>.
<p><div id="attachment_505" class="wp-caption alignnone" style="width: 427px"><a href="http://opensource.adobe.com/wiki/display/flexsdk/Downloads" target="_blank"><img class="size-full wp-image-505   " title="Flex SDK Download Page" src="http://savagelook.com/blog/wp-content/uploads/2010/08/flex_download.jpg" alt="" width="417" height="236" /></a><p class="wp-caption-text">Flex SDK Download Page</p></div></li>
<li>Unzip the archive to FLASH_BUILDER_4_HOME/sdks/SDK_VERSION</li>
<li>Open Flash Builder 4 and in the menu bar goto Windows -&gt; Preferences
<p><img class="alignnone size-full wp-image-511" title="Preferences" src="http://savagelook.com/blog/wp-content/uploads/2010/08/preferences.jpg" alt="" width="437" height="463" /></li>
<li>In the left pane of the Preferences window expand &#8220;Flash Builder&#8221; and click &#8220;Installed Flex SDKs&#8221;.  Click &#8220;Add&#8230;&#8221; in the right pane.
<p><img class="alignnone size-full wp-image-513" title="Installed Flex SDKs" src="http://savagelook.com/blog/wp-content/uploads/2010/08/installed_sdks.jpg" alt="" width="415" height="287" /></li>
<li>In the &#8220;Add Flex SDK&#8221; window enter the location of your new SDK (FLASH_BUILDER_4_HOME/sdks/SDK_VERSION) or click the &#8220;Browse..&#8221; button to find it yourself.  If you enter the path correctly, the &#8220;Flex SDK Name&#8221; field should auto-populate with the correct SDK name.
<p><img class="alignnone size-full wp-image-515" title="SDK Location" src="http://savagelook.com/blog/wp-content/uploads/2010/08/location.jpg" alt="" width="443" height="167" /></li>
<li>Click &#8220;OK&#8221; and your Flex SDK should be successfully installed.  You can now also set it as the default, if you wish, for all your future Flex projects.  Just click the checkbox next to the name of your SDK and click &#8220;Apply&#8221;.</li>
</ol>
<p>Even if you set up a new SDK as the default, there&#8217;s no reason you have to use it on all of your projects.  During the creation of a new Flex project you can specify which SDK you want to use in the &#8220;Flex SDK version&#8221; section.  You simply need to click the &#8220;Use a specific SDK&#8221; radio button and then select one of your installed SDKs from the drop down.  </p>
<p>You can also change the SDK after the project is created.  With your project selected, goto Project -> Properties and then click on &#8220;Flex Compiler&#8221; in the left pane.  On the right you&#8217;ll now see the same &#8220;Flex SDK version&#8221; section that was mentioned in the last paragraph.  Just change it and click &#8220;Apply&#8221;.</p>
<p>And thats about it.  Dig and have fun, Flash Builder 4 really is a fantastic IDE.</p>
<p><a href="http://savagelook.com/blog/flash-builder-4/configure-flex-sdk-in-flash-builder-4">Configure Flex SDK in Flash Builder 4</a> is a post from: <a href="http://savagelook.com/blog">SavageLook.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://savagelook.com/blog/flash-builder-4/configure-flex-sdk-in-flash-builder-4/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reflection in AS3</title>
		<link>http://savagelook.com/blog/code/reflection-in-as3</link>
		<comments>http://savagelook.com/blog/code/reflection-in-as3#comments</comments>
		<pubDate>Wed, 25 Aug 2010 20:41:56 +0000</pubDate>
		<dc:creator>Tony Lukasavage</dc:creator>
				<category><![CDATA[ActionScript3]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Code Demos]]></category>
		<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[generateFilterRect]]></category>
		<category><![CDATA[reflection]]></category>

		<guid isPermaLink="false">http://savagelook.com/blog/?p=466</guid>
		<description><![CDATA[Use AS3 to create a reflection effect on your DisplayObjects<p><a href="http://savagelook.com/blog/code/reflection-in-as3">Reflection in AS3</a> is a post from: <a href="http://savagelook.com/blog">SavageLook.com</a></p>
]]></description>
			<content:encoded><![CDATA[<p><a href="http://savagelook.com/misc/reflect.zip">Source code + Flash Develop project</a></p>
<p>Inspired by this <a href="http://www.adobe.com/devnet/flash/articles/reflect_class_as3.html" target="_blank">tutorial on reflections in AS3</a> at adobe devnet, I decided to play with reflections in Actionscript3.  As usual I can never follow a tutorial or step by step process without constantly trying to tweak it.</p>
<p>In my process of tweaking I found a slight short coming in the example given.  While it does a fantastic job of handling standard DisplayObjects, I found that things get a little messed up when you add filters to these objects.  Notice how the edges of the first image are cut off and sharp, whereas the the second image that accounts for the filters&#8217; impact on DisplayObjects&#8217; dimensions looks smooth:</p>
<div style="margin-left: auto; margin-right: auto; width: 450px;">
<table>
<tbody>
<tr>
<td>
<p><div class="wp-caption alignleft" style="width: 210px"><a rel="shadowbox" href="http://savagelook.com/images/reflect_bad.jpg"><img title="Reflections cut-off" src="http://savagelook.com/images/reflect_bad.jpg" alt="Reflections cut-off" width="200" height="200" /></a><p class="wp-caption-text">Filters cut-off</p></div></td>
<td>
<p><div class="wp-caption alignleft" style="width: 210px"><a rel="shadowbox" href="http://savagelook.com/images/reflect_good.jpg"><img title="Reflections cut-off" src="http://savagelook.com/images/reflect_good.jpg" alt="Reflections cut-off" width="200" height="200" /></a><p class="wp-caption-text">Filters complete</p></div></td>
</tr>
</tbody>
</table>
</div>
<p>In my efforts to remedy this problem I came across a very useful function for BitmapData called <a href="http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/display/BitmapData.html#generateFilterRect()" target="_blank">generateFilterRect()</a>.  Given a Rectangle and a BitmapFilter this function will return the Rectangle that would actually encompass the DisplayObject along with its filter.  With a simple bit of iteration we can traverse an object&#8217;s list of filters and determine what the max dimensions will be.  Here&#8217;s the function I added to take care of it:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">  <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> _createReflectionBitmapData<span style="color: #000000;">&#40;</span>obj<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">BitmapData</span> <span style="color: #000000;">&#123;</span>
      <span style="color: #6699cc; font-weight: bold;">var</span> filterRect<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Rectangle</span>;
      <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">width</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = obj.<span style="color: #004993;">width</span>;
      <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">height</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = obj.<span style="color: #004993;">height</span>;
      <span style="color: #6699cc; font-weight: bold;">var</span> bmd<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">BitmapData</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">BitmapData</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">width</span>, <span style="color: #004993;">height</span>, <span style="color: #0033ff; font-weight: bold;">true</span>, 0xffffff<span style="color: #000000;">&#41;</span>;
      <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">matrix</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Matrix</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Matrix</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
      <span style="color: #009900;">// filters can cause a display object to render outside of its rectangle</span>
      <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #0033ff; font-weight: bold;">each</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">filter</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">BitmapFilter</span> <span style="color: #0033ff; font-weight: bold;">in</span> obj.<span style="color: #004993;">filters</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        filterRect = bmd.<span style="color: #004993;">generateFilterRect</span><span style="color: #000000;">&#40;</span>bmd.<span style="color: #004993;">rect</span>, <span style="color: #004993;">filter</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #004993;">width</span> = filterRect.<span style="color: #004993;">width</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #004993;">width</span> <span style="color: #000000; font-weight: bold;">?</span> filterRect.<span style="color: #004993;">width</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">width</span>;
        <span style="color: #004993;">height</span> = filterRect.<span style="color: #004993;">height</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #004993;">height</span> <span style="color: #000000; font-weight: bold;">?</span> filterRect.<span style="color: #004993;">height</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">height</span>;
      <span style="color: #000000;">&#125;</span>
&nbsp;
      <span style="color: #009900;">// create, invert, and position relfection bitmapdata</span>
      bmd = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">BitmapData</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">width</span>, <span style="color: #004993;">height</span>, <span style="color: #0033ff; font-weight: bold;">true</span>, 0xffffff<span style="color: #000000;">&#41;</span>;
      <span style="color: #004993;">matrix</span>.<span style="color: #004993;">createBox</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span>, <span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span>, <span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #000000;">&#40;</span><span style="color: #004993;">width</span> <span style="color: #000000; font-weight: bold;">-</span> obj.<span style="color: #004993;">width</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span>, <span style="color: #004993;">height</span> <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">height</span> <span style="color: #000000; font-weight: bold;">-</span> obj.<span style="color: #004993;">height</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span>;
      bmd.<span style="color: #004993;">draw</span><span style="color: #000000;">&#40;</span>obj, <span style="color: #004993;">matrix</span><span style="color: #000000;">&#41;</span>;
&nbsp;
      <span style="color: #0033ff; font-weight: bold;">return</span> bmd;
    <span style="color: #000000;">&#125;</span></pre></div></div>

<p>The end result is BitmapData that contains our inverted DisplayObject, now properly sized and positioned.  We can now pass this into a Bitmap object and continue on with the code in the tutorial mentioned at the beginning of this post.  Or&#8230; you can use my stripped down and less functional version to get a simple view of how reflections are achieved in AS3:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span>
<span style="color: #000000;">&#123;</span>
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Bitmap</span>;
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">BitmapData</span>;
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">DisplayObject</span>;
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">Event</span>;
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.filters</span>.<span style="color: #004993;">BitmapFilter</span>;
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.filters</span>.<span style="color: #004993;">GlowFilter</span>;
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.geom</span>.<span style="color: #004993;">Matrix</span>;
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.geom</span>.<span style="color: #004993;">Rectangle</span>;
&nbsp;
  <span style="color: #3f5fbf;">/**
   * ...
   * @author Tony Lukasavage - SavageLook.com
   */</span>
  <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Main extends <span style="color: #004993;">Sprite</span>
  <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
    <span style="color: #000000;">&#123;</span>
      <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">stage</span><span style="color: #000000;">&#41;</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
      <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span>.<span style="color: #004993;">ADDED_TO_STAGE</span>, <span style="color: #004993;">init</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Event</span> = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
    <span style="color: #000000;">&#123;</span>
      <span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span>.<span style="color: #004993;">ADDED_TO_STAGE</span>, <span style="color: #004993;">init</span><span style="color: #000000;">&#41;</span>;
&nbsp;
      <span style="color: #009900;">// create main glow circle</span>
      <span style="color: #6699cc; font-weight: bold;">var</span> obj<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
      <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">matrix</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Matrix</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Matrix</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
      <span style="color: #6699cc; font-weight: bold;">var</span> radius<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">100</span>;
      <span style="color: #004993;">matrix</span>.<span style="color: #004993;">createGradientBox</span><span style="color: #000000;">&#40;</span>radius<span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">2</span>, radius<span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">2</span>, <span style="color: #004993;">Math</span>.<span style="color: #004993;">PI</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span>;
      obj.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">beginGradientFill</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;linear&quot;</span>, <span style="color: #000000;">&#91;</span>0x888888, 0xffffff<span style="color: #000000;">&#93;</span>, <span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span>, <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span>, <span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #000000; font-weight:bold;">255</span><span style="color: #000000;">&#93;</span>, <span style="color: #004993;">matrix</span><span style="color: #000000;">&#41;</span>;
      obj.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">drawCircle</span><span style="color: #000000;">&#40;</span>radius, radius, radius<span style="color: #000000;">&#41;</span>;
      obj.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
      obj.<span style="color: #004993;">x</span> = <span style="color: #004993;">stage</span>.<span style="color: #004993;">stageWidth</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000; font-weight: bold;">-</span> radius;
      obj.<span style="color: #004993;">y</span> = <span style="color: #004993;">stage</span>.<span style="color: #004993;">stageHeight</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000; font-weight: bold;">-</span> radius<span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">1.5</span>;
      obj.<span style="color: #004993;">filters</span> = <span style="color: #000000;">&#91;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">GlowFilter</span><span style="color: #000000;">&#40;</span>0xffffff, <span style="color: #000000; font-weight:bold;">1</span>, <span style="color: #000000; font-weight:bold;">20</span>, <span style="color: #000000; font-weight:bold;">20</span>, <span style="color: #000000; font-weight:bold;">2</span>, <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>;
      <span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>obj<span style="color: #000000;">&#41;</span>;
&nbsp;
      <span style="color: #009900;">// create reflection</span>
      <span style="color: #6699cc; font-weight: bold;">var</span> bmd<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">BitmapData</span> = _createReflectionBitmapData<span style="color: #000000;">&#40;</span>obj<span style="color: #000000;">&#41;</span>;
      <span style="color: #6699cc; font-weight: bold;">var</span> bitmapReflect<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Bitmap</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Bitmap</span><span style="color: #000000;">&#40;</span>bmd<span style="color: #000000;">&#41;</span>;
      bitmapReflect.<span style="color: #004993;">x</span> = <span style="color: #004993;">stage</span>.<span style="color: #004993;">stageWidth</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000; font-weight: bold;">-</span> bitmapReflect.<span style="color: #004993;">width</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span>;
      bitmapReflect.<span style="color: #004993;">y</span> = obj.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">+</span> radius<span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">2</span>;
      <span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>bitmapReflect<span style="color: #000000;">&#41;</span>;
&nbsp;
      <span style="color: #009900;">// create gradient for reflection</span>
      <span style="color: #6699cc; font-weight: bold;">var</span> grad<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
      <span style="color: #004993;">matrix</span>.<span style="color: #004993;">createGradientBox</span><span style="color: #000000;">&#40;</span>bitmapReflect.<span style="color: #004993;">width</span>, bitmapReflect.<span style="color: #004993;">height</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span>, <span style="color: #004993;">Math</span>.<span style="color: #004993;">PI</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span>, <span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
      grad.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">beginGradientFill</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;linear&quot;</span>, <span style="color: #000000;">&#91;</span>0xffffff, 0xffffff<span style="color: #000000;">&#93;</span>, <span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span>, <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span>, <span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #000000; font-weight:bold;">255</span><span style="color: #000000;">&#93;</span>, <span style="color: #004993;">matrix</span><span style="color: #000000;">&#41;</span>;
      grad.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">drawRect</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #000000; font-weight:bold;">0</span>, bitmapReflect.<span style="color: #004993;">width</span>, bitmapReflect.<span style="color: #004993;">height</span><span style="color: #000000;">&#41;</span>;
      grad.<span style="color: #004993;">x</span> = bitmapReflect.<span style="color: #004993;">x</span>;
      grad.<span style="color: #004993;">y</span> = bitmapReflect.<span style="color: #004993;">y</span>;
      grad.<span style="color: #004993;">cacheAsBitmap</span> = <span style="color: #0033ff; font-weight: bold;">true</span>;
      bitmapReflect.<span style="color: #004993;">cacheAsBitmap</span> = <span style="color: #0033ff; font-weight: bold;">true</span>;
      bitmapReflect.<span style="color: #004993;">mask</span> = grad;
      <span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>grad<span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> _createReflectionBitmapData<span style="color: #000000;">&#40;</span>obj<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">BitmapData</span> <span style="color: #000000;">&#123;</span>
      <span style="color: #6699cc; font-weight: bold;">var</span> filterRect<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Rectangle</span>;
      <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">width</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = obj.<span style="color: #004993;">width</span>;
      <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">height</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = obj.<span style="color: #004993;">height</span>;
      <span style="color: #6699cc; font-weight: bold;">var</span> bmd<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">BitmapData</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">BitmapData</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">width</span>, <span style="color: #004993;">height</span>, <span style="color: #0033ff; font-weight: bold;">true</span>, 0xffffff<span style="color: #000000;">&#41;</span>;
      <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">matrix</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Matrix</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Matrix</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
      <span style="color: #009900;">// filters can cause a display object to render outside of its rectangle</span>
      <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #0033ff; font-weight: bold;">each</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">filter</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">BitmapFilter</span> <span style="color: #0033ff; font-weight: bold;">in</span> obj.<span style="color: #004993;">filters</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        filterRect = bmd.<span style="color: #004993;">generateFilterRect</span><span style="color: #000000;">&#40;</span>bmd.<span style="color: #004993;">rect</span>, <span style="color: #004993;">filter</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #004993;">width</span> = filterRect.<span style="color: #004993;">width</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #004993;">width</span> <span style="color: #000000; font-weight: bold;">?</span> filterRect.<span style="color: #004993;">width</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">width</span>;
        <span style="color: #004993;">height</span> = filterRect.<span style="color: #004993;">height</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #004993;">height</span> <span style="color: #000000; font-weight: bold;">?</span> filterRect.<span style="color: #004993;">height</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">height</span>;
      <span style="color: #000000;">&#125;</span>
&nbsp;
      <span style="color: #009900;">// create, invert, and position relfection bitmapdata</span>
      bmd = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">BitmapData</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">width</span>, <span style="color: #004993;">height</span>, <span style="color: #0033ff; font-weight: bold;">true</span>, 0xffffff<span style="color: #000000;">&#41;</span>;
      <span style="color: #004993;">matrix</span>.<span style="color: #004993;">createBox</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span>, <span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span>, <span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #000000;">&#40;</span><span style="color: #004993;">width</span> <span style="color: #000000; font-weight: bold;">-</span> obj.<span style="color: #004993;">width</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span>, <span style="color: #004993;">height</span> <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">height</span> <span style="color: #000000; font-weight: bold;">-</span> obj.<span style="color: #004993;">height</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span>;
      bmd.<span style="color: #004993;">draw</span><span style="color: #000000;">&#40;</span>obj, <span style="color: #004993;">matrix</span><span style="color: #000000;">&#41;</span>;
&nbsp;
      <span style="color: #0033ff; font-weight: bold;">return</span> bmd;
    <span style="color: #000000;">&#125;</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>And thats the basics.  If you want an in depth description of each step and how they are performed, I will again refer you to the <a href="http://www.adobe.com/devnet/flash/articles/reflect_class_as3.html" target="_blank">terrific tutorial by Ben Pritchard</a>.  In the meantime, enjoy your new found knowledge and start putting it to use.  Everyone else is.  Seriously.  Like every image anymore has a reflection under it.  This is really starting to irk my &#8220;swim against the current&#8221; side.  Oh well, nothing a glass of Jack can&#8217;t cure.</p>
<p>Is everyone doing this in Away3D?  No?  Well you can add me to the list soon <img src='http://savagelook.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><a href="http://savagelook.com/blog/code/reflection-in-as3">Reflection in AS3</a> is a post from: <a href="http://savagelook.com/blog">SavageLook.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://savagelook.com/blog/code/reflection-in-as3/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adobe Alchemy</title>
		<link>http://savagelook.com/blog/actionscript3/adobe-alchemy</link>
		<comments>http://savagelook.com/blog/actionscript3/adobe-alchemy#comments</comments>
		<pubDate>Mon, 23 Aug 2010 12:26:20 +0000</pubDate>
		<dc:creator>Tony Lukasavage</dc:creator>
				<category><![CDATA[ActionScript3]]></category>
		<category><![CDATA[Alchemy]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[as3]]></category>

		<guid isPermaLink="false">http://savagelook.com/blog/?p=384</guid>
		<description><![CDATA[A quick overview and tips for the Adobe Labs project Alchemy. It is a platform that allows you to leverage the performance of C/C++ libraries by compiling them into byte code usable in AS3.<p><a href="http://savagelook.com/blog/actionscript3/adobe-alchemy">Adobe Alchemy</a> is a post from: <a href="http://savagelook.com/blog">SavageLook.com</a></p>
]]></description>
			<content:encoded><![CDATA[<p><a href="http://labs.adobe.com/" target="_blank">Adobe Labs</a> has a prerelease project called <a href="http://labs.adobe.com/technologies/alchemy/" target="_blank">Alchemy</a>, which allows you to compile C/C++ code into SWC libraries that are usable in your AS3 code.  For a former C/C++ coder like myself, this is music to my ears, but those without that background might be wondering why the hell you would even bother.  Well, there&#8217;s 2 major points to consider:</p>
<ul>
<li>You&#8217;ll be able to use the existing mountains of C/C++ libraries in your AS3 without having to create a port.</li>
<li>To quote the Adobe Alchemy page:  <em>(Its) ideally suited for computation-intensive use cases, such as audio/video transcoding, data manipulation, XML parsing, cryptographic functions or physics simulation, performance can be considerably faster than ActionScript 3.0&#8230;</em></li>
</ul>
<p>Now before you go getting all excited to compile your favorite C/C++ library into an SWC, there are some things to consider:</p>
<ul>
<li>The more OS and other library dependencies your compiling target has, the less likely it is to work.</li>
<li>This is a prerelease labs project, so expect bugs and lots of visits to the <a href="http://forums.adobe.com/community/labs/alchemy" target="_blank">Alchemy forums</a>.  This should probably not be used for production code.</li>
<li>Adobe has not made it clear whether or not they plan to continue development of Alchemy, or whether it will ever be rolled into an official release.</li>
</ul>
<p>If that hasn&#8217;t scared you off I&#8217;d highly suggest going to the <a href="http://labs.adobe.com/technologies/alchemy/" target="_blank">Alchemy project page</a> to get your necessary downloads and then heading immediately to the <a href="http://labs.adobe.com/wiki/index.php/Alchemy:Documentation:Getting_Started" target="_blank">&#8220;Getting Started&#8221; page</a> to setup up your development environment.  See if you can get their basic stringecho.c program working.  Once you have built your environment and compiled your first SWC for use in your AS3 code, it&#8217;s time to actually build your own Alchemy version of a C/C++ library.  Here&#8217;s a few examples of libraries that have been successfully ported to AS3 via Alchemy:</p>
<ul>
<li>OggVorbis and Crypto from the <a href="http://labs.adobe.com/wiki/index.php/Alchemy:Libraries" target="_blank">Alchemy ports page</a></li>
<li><a href="http://wiki.github.com/jesses/wck/box2d-flash-alchemy-port" target="_blank">Box2D Physics Engine</a></li>
<li><a href="http://www.libspark.org/svn/as3/FLARToolKit/branches/alchemy/" target="_blank">FLARToolkit Augmented Reality Library</a></li>
<li><a href="http://www.peternitsch.net/demo/aa-lib/index.html" target="_blank">aalib Ascii Art Library</a></li>
</ul>
<div style="margin-left: auto; margin-right: auto; width: 450px;">
<table>
<tbody>
<tr>
<td>
<p><div class="wp-caption alignnone" style="width: 225px"><a rel="shadowbox;height=650;width=1000;" href="http://www.peternitsch.net/demo/aa-lib/aalib.swf"><img class="   " title="aalib Ascii Art in Alchemy" src="http://savagelook.com/images/ascii.jpg" alt="aalib Ascii Art in Alchemy" width="215" height="138" /></a><p class="wp-caption-text">aalib Ascii Art in Alchemy</p></div></td>
<td>
<p><div class="wp-caption alignnone" style="width: 225px"><a rel="shadowbox;height=600;width=800;" href="http://www.sideroller.com/wck"><img class="   " title="Box2D Physics in Alchemy" src="http://savagelook.com/images/box2d_alchemy.png" alt="Box2D Physics in Alchemy" width="215" height="138" /></a><p class="wp-caption-text">Box2D Physics in Alchemy</p></div></td>
</tr>
</tbody>
</table>
</div>
<p>Now remember how I said you would inevitably run into bugs?  Yeah, that&#8217;s gonna happen, it wasn&#8217;t just a maybe.  Well, here&#8217;s a list of bugs I&#8217;ve run into so far (in attempting to port <a href="http://www.ijg.org/" target="_blank">IJG&#8217;s JPEG library</a>) and what I had to do to work around them.  And by &#8220;work around them&#8221; I mean &#8220;what people on the Alchemy forums did to work around them.&#8221;  </p>
<ul>
<li>
<h3 style="text-decoration: underline;">adl.exe stuck</h3>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">checking whether we are cross compiling... \
<span style="color: #007800;">$FLEX_HOME</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>adl.exe c:\\cygwin<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>t35f0.0<span style="color: #000000; font-weight: bold;">/</span>app.xml \
<span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>adl.trace <span style="color: #000000; font-weight: bold;">&amp;</span>amp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$!</span></pre></div></div>

<p>Cygwin must installed at C:\cygwin because Swfbridge, which loads AIR apps on the fly during configure scripts, is hardcoded to reference C:\cygwin.  </p>
<p>If you are working on a Linux system and get a similar error, make sure that you can execute your $FLEX_HOME/bin/adl file successfully.  The executable for the standard Flex 3.2 SDK does not include a valid Linux ADL, only Windows and Mac.  For a Linux version, download the <a href="http://www.adobe.com/products/air/tools/sdk/" target="_blank">AIR SDK for Linux</a> and use its ADL.</li>
<li>
<h3 style="text-decoration: underline;">Bad regex in achack/gcc</h3>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Compiler<span style="color: #7a0874; font-weight: bold;">&#93;</span> Error <span style="color: #666666; font-style: italic;">#1084: Syntax error: expecting identifier before \</span>
leftbrace.
    91011.achacks.as, Ln <span style="color: #000000;">1</span>, Col <span style="color: #000000;">18</span>:
    package cmodule. <span style="color: #7a0874; font-weight: bold;">&#123;</span></pre></div></div>

<p>Change line 274 of $ALCHEMY_HOME/achacks/gcc in the following way:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#if($o =~ /([^\.]*)/)</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$o</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/([^\/\.]+)(\..*)*$/</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>or just replace $ALCHEMY_HOME/achacks/gcc with <a href="http://savagelook.com/misc/gcc">this fixed version</a>.</li>
<li>
<h3 style="text-decoration: underline;">Missing asmachine.abc</h3>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>Compiler<span style="color: #7a0874; font-weight: bold;">&#93;</span> Error <span style="color: #666666; font-style: italic;">#1063: Unable to open file: \</span>
<span style="color: #007800;">$ALCHEMY_HOME</span><span style="color: #000000; font-weight: bold;">/</span>avm2-libc<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>asmachine.abc.</pre></div></div>

<p>Don&#8217;t compile shared libraries, only static.  You can usually set this in a configure script using &#8220;&#8211;enable-shared=no &#8211;enable-static=yes&#8221;.  You can also pass the &#8220;-static&#8221; option to gcc directly when compiling.</li>
</ul>
<p>That&#8217;s the list so far, but I&#8217;m sure there&#8217;ll be more.  When all else fails, be sure to check the your /tmp directory for log files.  I hope its saves anyone reading this a few hours as thats how long it took me to track these all down as an Alchemy noob.  If you have the brains, guts, and patience to churn out an Alchemy port of a C/C++ library, leave a comment and let me know about it.  Hopefully if enough of us do some real head turning work with it Adobe will actually put some serious effort into an actual supported release.  Keep your fingers crossed.</p>
<p><a href="http://savagelook.com/blog/actionscript3/adobe-alchemy">Adobe Alchemy</a> is a post from: <a href="http://savagelook.com/blog">SavageLook.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://savagelook.com/blog/actionscript3/adobe-alchemy/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Box2DFlashAS3 v2.1a HelloWorld</title>
		<link>http://savagelook.com/blog/code/box2dflashas3-fun</link>
		<comments>http://savagelook.com/blog/code/box2dflashas3-fun#comments</comments>
		<pubDate>Wed, 18 Aug 2010 19:34:40 +0000</pubDate>
		<dc:creator>Tony Lukasavage</dc:creator>
				<category><![CDATA[ActionScript3]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Code Demos]]></category>
		<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[box2d]]></category>
		<category><![CDATA[box2dflashas3]]></category>

		<guid isPermaLink="false">http://savagelook.com/blog/?p=332</guid>
		<description><![CDATA[A pure AS3 Box2D (Box2DFlashAS3) v2.1a HelloWorld demo, no FLA file required<p><a href="http://savagelook.com/blog/code/box2dflashas3-fun">Box2DFlashAS3 v2.1a HelloWorld</a> is a post from: <a href="http://savagelook.com/blog">SavageLook.com</a></p>
]]></description>
			<content:encoded><![CDATA[<div class="wp-caption aligncenter" style="width: 526px"><a href="http://savagelook.com/demos/box2d/box2d.swf" target="_self" rel="shadowbox;height=600;width=800;"><img class="  " title="Box2D demo" src="http://savagelook.com/images/box2d_full.jpg" alt="Box2D demo" width="516" height="487" /></a><p class="wp-caption-text">Box2D demo</p></div>
<p>Click the image above for the demo.<br />
<a href="http://savagelook.com/demos/box2d/srcview/index.html" target="_self">Click here</a> or right click on the demo to view the source code.</p>
<p>Inspired by <a href="http://www.youtube.com/watch?v=mnyynpq-TXo" rel="shadowbox[post-332];player=swf;width=640;height=385;" target="_blank">this clip</a> of Box2D running on Android, I decided to dive into this 2D physics engine I have heard so much about.  While the version of Box2D I used is the AS3 version called <a href="http://www.box2dflash.org/" target="_blank">Box2DFlashAS3</a>, the <a href="http://www.box2d.org/" target="_blank">original version</a> is written in C++.  Basically it very simply lets you apply 2D physics to your objects, or &#8220;bodies,&#8221; in AS3.</p>
<p>Most of the examples and tutorials I saw were lacking 2 things:</p>
<ol>
<li> A way to apply sprites to my &#8220;bodies&#8221; without the use of a flash project (FLA) file.</li>
<li>Code that was compatible with the latest version of Box2DFlashAS3, v2.1a at the time of this post.</li>
</ol>
<p>So to resolve that situation, or to account for my search engine deficiency, I present the HelloWorld example from the Box2DFlashAS3 2.1a distribution modified to be pure AS3:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span><span style="color: #000000;">&#123;</span>
<span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
  <span style="color: #3f5fbf;">/*
   * Tony Lukasavage - SavageLook.com - 8/18/2010
   * Box2DFlashAS3 2.1a HelloWorld example, minus the need for an accompanying FLA
   *
   * This the basic Box2DFlashAS3 HelloWorld.as file from the source distribution
   * with some adjustments made so that you do not need an FLA file to compile and
   * run the code.  A simple bonus for us pure AS3 guys.  Also a few minor modifications
   * are made to account for changes between version 2.0 and 2.1, like adding a type
   * for body definitions.  Finally, I threw in an click handler to toggle between
   * normal and debug drawing.
   *
   */</span>
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Collision.<span style="color: #000000; font-weight: bold;">*</span>;
  <span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Collision.Shapes.<span style="color: #000000; font-weight: bold;">*</span>;
  <span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Common.<span style="color: #004993;">Math</span>.<span style="color: #000000; font-weight: bold;">*</span>;
  <span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Dynamics.<span style="color: #000000; font-weight: bold;">*</span>;
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">import</span> __AS3__.vec.Vector;
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">import</span> com.adobe.viewsource.ViewSource;
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">Event</span>;
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">MouseEvent</span>;
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.geom</span>.<span style="color: #004993;">Matrix</span>;
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span>.<span style="color: #004993;">TextField</span>;
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span>.<span style="color: #004993;">TextFormat</span>;
&nbsp;
  <span style="color: #000000;">&#91;</span>SWF<span style="color: #000000;">&#40;</span><span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;800&quot;</span>, <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;600&quot;</span>, <span style="color: #004993;">frameRate</span>=<span style="color: #990000;">&quot;30&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
  <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> box2d extends <span style="color: #004993;">Sprite</span>
  <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _world<span style="color: #000000; font-weight: bold;">:</span>b2World;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _velocityIterations<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">10</span>;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _positionIterations<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">10</span>;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _timeStep<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">1.0</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">30.0</span>;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _showDebug<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> = <span style="color: #0033ff; font-weight: bold;">true</span>;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _debugSprite<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span>;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _bodySprites<span style="color: #000000; font-weight: bold;">:</span>Vector. = <span style="color: #0033ff; font-weight: bold;">new</span> Vector.<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
    <span style="color: #009900;">// Box2D uses meters for measurement, AS3 uses pixels.  1 meter = 30 pixels</span>
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> _worldRatio<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">30</span>;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> box2d<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
      <span style="color: #009900;">// Add event for main loop</span>
      <span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span>.<span style="color: #004993;">ENTER_FRAME</span>, Update, <span style="color: #0033ff; font-weight: bold;">false</span>, <span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>;
      <span style="color: #004993;">stage</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">CLICK</span>, onClick <span style="color: #000000;">&#41;</span>;
&nbsp;
      <span style="color: #009900;">// add background gradient</span>
      <span style="color: #6699cc; font-weight: bold;">var</span> bg<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
      <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">matrix</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Matrix</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Matrix</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
      <span style="color: #004993;">matrix</span>.<span style="color: #004993;">createGradientBox</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">stage</span>.<span style="color: #004993;">stageWidth</span>, <span style="color: #004993;">stage</span>.<span style="color: #004993;">stageHeight</span>, <span style="color: #004993;">Math</span>.<span style="color: #004993;">PI</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span>, <span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
      bg.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">beginGradientFill</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;linear&quot;</span>, <span style="color: #000000;">&#91;</span>0x9999ff, 0xffffff<span style="color: #000000;">&#93;</span>, <span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span>, <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span>, <span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #000000; font-weight:bold;">255</span><span style="color: #000000;">&#93;</span>, <span style="color: #004993;">matrix</span><span style="color: #000000;">&#41;</span>;
      bg.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">drawRect</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #004993;">stage</span>.<span style="color: #004993;">stageWidth</span>, <span style="color: #004993;">stage</span>.<span style="color: #004993;">stageHeight</span><span style="color: #000000;">&#41;</span>;
      bg.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
      <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>bg<span style="color: #000000;">&#41;</span>;
&nbsp;
      <span style="color: #009900;">// Define the gravity vector</span>
      <span style="color: #6699cc; font-weight: bold;">var</span> gravity<span style="color: #000000; font-weight: bold;">:</span>b2Vec2 = <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0.0</span>, <span style="color: #000000; font-weight:bold;">10.0</span><span style="color: #000000;">&#41;</span>;
&nbsp;
      <span style="color: #009900;">// Allow bodies to sleep</span>
      <span style="color: #6699cc; font-weight: bold;">var</span> doSleep<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> = <span style="color: #0033ff; font-weight: bold;">true</span>;
&nbsp;
      <span style="color: #009900;">// Construct a world object</span>
      _world = <span style="color: #0033ff; font-weight: bold;">new</span> b2World<span style="color: #000000;">&#40;</span>gravity, doSleep<span style="color: #000000;">&#41;</span>;
&nbsp;
      <span style="color: #009900;">// set debug draw</span>
      <span style="color: #6699cc; font-weight: bold;">var</span> debugDraw<span style="color: #000000; font-weight: bold;">:</span>b2DebugDraw = <span style="color: #0033ff; font-weight: bold;">new</span> b2DebugDraw<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
      _debugSprite = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
      <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>_debugSprite<span style="color: #000000;">&#41;</span>;
      debugDraw.SetSprite<span style="color: #000000;">&#40;</span>_debugSprite<span style="color: #000000;">&#41;</span>;
      debugDraw.SetDrawScale<span style="color: #000000;">&#40;</span>_worldRatio<span style="color: #000000;">&#41;</span>;
      debugDraw.SetFillAlpha<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0.5</span><span style="color: #000000;">&#41;</span>;
      debugDraw.SetLineThickness<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span>;
      debugDraw.SetAlpha<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span>;
      debugDraw.SetFlags<span style="color: #000000;">&#40;</span>b2DebugDraw.e_shapeBit <span style="color: #000000; font-weight: bold;">|</span> b2DebugDraw.e_jointBit<span style="color: #000000;">&#41;</span>;
      _world.SetDebugDraw<span style="color: #000000;">&#40;</span>debugDraw<span style="color: #000000;">&#41;</span>;
&nbsp;
      <span style="color: #009900;">// Vars used to create bodies</span>
      <span style="color: #6699cc; font-weight: bold;">var</span> body<span style="color: #000000; font-weight: bold;">:</span>b2Body;
      <span style="color: #6699cc; font-weight: bold;">var</span> bodyDef<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef;
      <span style="color: #6699cc; font-weight: bold;">var</span> boxShape<span style="color: #000000; font-weight: bold;">:</span>b2PolygonShape;
      <span style="color: #6699cc; font-weight: bold;">var</span> circleShape<span style="color: #000000; font-weight: bold;">:</span>b2CircleShape;
&nbsp;
      <span style="color: #009900;">// Adding sprite variable for dynamically creating body userData</span>
      <span style="color: #6699cc; font-weight: bold;">var</span> sprite<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span>;
      <span style="color: #6699cc; font-weight: bold;">var</span> groundHeight<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">60</span>;
&nbsp;
      sprite = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
      sprite.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">lineStyle</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span>;
      sprite.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">beginFill</span><span style="color: #000000;">&#40;</span>0x444444<span style="color: #000000;">&#41;</span>;
      sprite.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">drawRect</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #004993;">stage</span>.<span style="color: #004993;">stageWidth</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span>, <span style="color: #000000; font-weight: bold;">-</span>groundHeight<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span>, <span style="color: #004993;">stage</span>.<span style="color: #004993;">stageWidth</span>, groundHeight<span style="color: #000000;">&#41;</span>;
      sprite.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
      bodyDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
      bodyDef.<span style="color: #004993;">type</span> = b2Body.b2_staticBody;
      bodyDef.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #004993;">stage</span>.<span style="color: #004993;">stageWidth</span> <span style="color: #000000; font-weight: bold;">/</span> _worldRatio <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span>, <span style="color: #000000;">&#40;</span><span style="color: #004993;">stage</span>.<span style="color: #004993;">stageHeight</span> <span style="color: #000000; font-weight: bold;">-</span> sprite.<span style="color: #004993;">height</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">/</span> _worldRatio<span style="color: #000000;">&#41;</span>;
      bodyDef.userData = sprite;
      <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>bodyDef.userData<span style="color: #000000;">&#41;</span>;
&nbsp;
      boxShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
      boxShape.SetAsBox<span style="color: #000000;">&#40;</span>sprite.<span style="color: #004993;">width</span><span style="color: #000000; font-weight: bold;">/</span>_worldRatio<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span>, sprite.<span style="color: #004993;">height</span><span style="color: #000000; font-weight: bold;">/</span>_worldRatio<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span>;
&nbsp;
      <span style="color: #6699cc; font-weight: bold;">var</span> fixtureDef<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
      fixtureDef.shape = boxShape;
      fixtureDef.friction = <span style="color: #000000; font-weight:bold;">0.3</span>;
      fixtureDef.density = <span style="color: #000000; font-weight:bold;">0</span>; <span style="color: #009900;">// static bodies require zero density</span>
&nbsp;
      body = _world.CreateBody<span style="color: #000000;">&#40;</span>bodyDef<span style="color: #000000;">&#41;</span>;
      body.CreateFixture<span style="color: #000000;">&#40;</span>fixtureDef<span style="color: #000000;">&#41;</span>;
&nbsp;
      <span style="color: #009900;">// Add some objects</span>
      <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">1</span>; i <span style="color: #000000; font-weight: bold;">&amp;</span>lt; <span style="color: #000000; font-weight:bold;">20</span>; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #009900;">// create generic body definition</span>
        bodyDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
        bodyDef.<span style="color: #004993;">type</span> = b2Body.b2_dynamicBody;
        bodyDef.<span style="color: #004993;">position</span>.<span style="color: #004993;">x</span> = <span style="color: #004993;">Math</span>.<span style="color: #004993;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">15</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">5</span>;
        bodyDef.<span style="color: #004993;">position</span>.<span style="color: #004993;">y</span> = <span style="color: #004993;">Math</span>.<span style="color: #004993;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">10</span>;
        <span style="color: #6699cc; font-weight: bold;">var</span> rX<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">Math</span>.<span style="color: #004993;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">0.5</span>;
        <span style="color: #6699cc; font-weight: bold;">var</span> rY<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">Math</span>.<span style="color: #004993;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">1</span>;
        <span style="color: #6699cc; font-weight: bold;">var</span> spriteX<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = rX <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">30</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">2</span>;
        <span style="color: #6699cc; font-weight: bold;">var</span> spriteY<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = rY <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">30</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">2</span>;
&nbsp;
        <span style="color: #009900;">// Box</span>
        <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">Math</span>.<span style="color: #004993;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>lt; <span style="color: #000000; font-weight:bold;">0.5</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
          sprite = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
          sprite.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">lineStyle</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span>;
          sprite.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">beginFill</span><span style="color: #000000;">&#40;</span>0xff6666<span style="color: #000000;">&#41;</span>;
          sprite.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">drawRect</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span>spriteX<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span>, <span style="color: #000000; font-weight: bold;">-</span>spriteY<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span>, spriteX, spriteY<span style="color: #000000;">&#41;</span>;
          sprite.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
          bodyDef.userData = sprite;
&nbsp;
          boxShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
          boxShape.SetAsBox<span style="color: #000000;">&#40;</span>rX, rY<span style="color: #000000;">&#41;</span>;
&nbsp;
          fixtureDef.shape = boxShape;
          fixtureDef.density = <span style="color: #000000; font-weight:bold;">1.0</span>;
          fixtureDef.friction = <span style="color: #000000; font-weight:bold;">0.5</span>;
          fixtureDef.restitution = <span style="color: #000000; font-weight:bold;">0.2</span>;
&nbsp;
          body = _world.CreateBody<span style="color: #000000;">&#40;</span>bodyDef<span style="color: #000000;">&#41;</span>;
          body.CreateFixture<span style="color: #000000;">&#40;</span>fixtureDef<span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
        <span style="color: #009900;">// Circle</span>
        <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
          sprite = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
          sprite.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">lineStyle</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span>;
          sprite.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">beginFill</span><span style="color: #000000;">&#40;</span>0x44ff44<span style="color: #000000;">&#41;</span>;
          sprite.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">drawCircle</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #000000; font-weight:bold;">0</span>, spriteX<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span>;
          sprite.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
          bodyDef.userData = sprite;
&nbsp;
          circleShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2CircleShape<span style="color: #000000;">&#40;</span>rX<span style="color: #000000;">&#41;</span>;
&nbsp;
          fixtureDef.shape = circleShape;
          fixtureDef.density = <span style="color: #000000; font-weight:bold;">1.0</span>;
          fixtureDef.friction = <span style="color: #000000; font-weight:bold;">0.5</span>;
          fixtureDef.restitution = <span style="color: #000000; font-weight:bold;">0.2</span>;
&nbsp;
          body = _world.CreateBody<span style="color: #000000;">&#40;</span>bodyDef<span style="color: #000000;">&#41;</span>;
          body.CreateFixture<span style="color: #000000;">&#40;</span>fixtureDef<span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        _bodySprites.<span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>bodyDef.userData <span style="color: #0033ff; font-weight: bold;">as</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>bodyDef.userData<span style="color: #000000;">&#41;</span>;
      <span style="color: #000000;">&#125;</span>
&nbsp;
      <span style="color: #009900;">// enable view source</span>
      ViewSource.addMenuItem<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span>, <span style="color: #990000;">&quot;srcview/index.html&quot;</span><span style="color: #000000;">&#41;</span>;
      <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">text</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">TextField</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextField</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
      <span style="color: #004993;">text</span>.<span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;Right click to view source&quot;</span>;
      <span style="color: #004993;">text</span>.<span style="color: #004993;">setTextFormat</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextFormat</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;arial&quot;</span>, <span style="color: #000000; font-weight:bold;">14</span>, <span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
      <span style="color: #004993;">text</span>.<span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">20</span>;
      <span style="color: #004993;">text</span>.<span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">20</span>;
      <span style="color: #004993;">text</span>.<span style="color: #004993;">width</span> = <span style="color: #000000; font-weight:bold;">200</span>;
      <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">text</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> onClick<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
      _showDebug = <span style="color: #000000; font-weight: bold;">!</span>_showDebug;
      <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span>_showDebug<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        _debugSprite.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
      <span style="color: #000000;">&#125;</span>
      <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #0033ff; font-weight: bold;">each</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> sprite<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span> <span style="color: #0033ff; font-weight: bold;">in</span> _bodySprites<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        sprite.<span style="color: #004993;">visible</span> = <span style="color: #000000; font-weight: bold;">!</span>_showDebug;
      <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Update<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
      _world.Step<span style="color: #000000;">&#40;</span>_timeStep, _velocityIterations, _positionIterations<span style="color: #000000;">&#41;</span>;
      <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>_showDebug<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        _world.DrawDebugData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
      <span style="color: #000000;">&#125;</span>
&nbsp;
      <span style="color: #009900;">// Go through body list and update sprite positions/rotations</span>
      <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> bb<span style="color: #000000; font-weight: bold;">:</span>b2Body = _world.GetBodyList<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>; bb; bb = bb.GetNext<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>bb.GetUserData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">is</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
          <span style="color: #6699cc; font-weight: bold;">var</span> sprite<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span> = bb.GetUserData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> <span style="color: #004993;">Sprite</span>;
          sprite.<span style="color: #004993;">x</span> = bb.GetPosition<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">30</span>;
          sprite.<span style="color: #004993;">y</span> = bb.GetPosition<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">30</span>;
          sprite.<span style="color: #004993;">rotation</span> = bb.GetAngle<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">180</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #004993;">Math</span>.<span style="color: #004993;">PI</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
      <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Very cool stuff that adds lots of possibilities to your Flash projects.  I can&#8217;t wait to start playing with the more complex aspects like joints, buoyancy and breakable bodies.  More intensely awesome demos sure to follow.</p>
<p><a href="http://savagelook.com/blog/code/box2dflashas3-fun">Box2DFlashAS3 v2.1a HelloWorld</a> is a post from: <a href="http://savagelook.com/blog">SavageLook.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://savagelook.com/blog/code/box2dflashas3-fun/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ShadowBox JS for Wordpress</title>
		<link>http://savagelook.com/blog/wordpress/shadowbox-js-for-wordpress</link>
		<comments>http://savagelook.com/blog/wordpress/shadowbox-js-for-wordpress#comments</comments>
		<pubDate>Wed, 18 Aug 2010 02:23:17 +0000</pubDate>
		<dc:creator>Tony Lukasavage</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://savagelook.com/blog/?p=355</guid>
		<description><![CDATA[Just a quick update to let you know that my Flash demos will be from now on be displayed in ShadowBox.js via the ShadowBox JS Wordpress plugin.  Its a lightweight javascript library that allows you to show all kinds of media on your website in a slick popup window.  You&#8217;ve probably seen them before on [...]<p><a href="http://savagelook.com/blog/wordpress/shadowbox-js-for-wordpress">ShadowBox JS for Wordpress</a> is a post from: <a href="http://savagelook.com/blog">SavageLook.com</a></p>
]]></description>
			<content:encoded><![CDATA[<div id="attachment_357" class="wp-caption aligncenter" style="width: 501px"><a href="http://www.shadowbox-js.com/"><img class="size-large wp-image-357  " title="shadowbox_full" src="http://savagelook.com/blog/wp-content/uploads/2010/08/shadowbox_full-1024x640.jpg" alt="" width="491" height="307" /></a><p class="wp-caption-text">ShadowBox JS in action</p></div>
<p>Just a quick update to let you know that my Flash demos will be from now on be displayed in <a href="http://www.shadowbox-js.com/" target="_blank">ShadowBox.js</a> via the <a href="http://sivel.net/wordpress/shadowbox-js/" target="_blank">ShadowBox JS Wordpress plugin</a>.  Its a lightweight javascript library that allows you to show all kinds of media on your website in a slick popup window.  You&#8217;ve probably seen them before on video and image gallery sites.</p>
<p>While the ShadowBox JS plugin will handle all your images, videos, SWFs, etc&#8230; by default, I prefer to manually determine which media will utilize it.  And to do so, its as simple as adding &#8220;rel=shadowbox&#8221; to your anchor tags, which I use in my <a href="http://savagelook.com/blog/code/box2dflashas3-fun">Box2D demo post</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;a rel=&quot;shadowbox;height=600;width=800;&quot; 
    href=&quot;http://savagelook.com/demos/box2d/box2d.swf&quot; 
    target=&quot;_self&quot;&gt;
  &lt;img class=&quot;  &quot; title=&quot;Box2D demo&quot; 
         src=&quot;http://savagelook.com/images/box2d_full.jpg&quot; 
         alt=&quot;Box2D demo&quot; width=&quot;516&quot; height=&quot;487&quot; /&gt;
&lt;/a&gt;</pre></div></div>

<p>I avoided pre-built blogs for the longest time because I&#8217;m a ridiculously customization driven programmer, but with what Wordpress has available for free, I wonder why I wasn&#8217;t using it all along.  I highly suggest ShadowBox.js for your Wordpress blog or any website that needs a little extra eye-catching flair.  And let&#8217;s face it, if you&#8217;ve been around my blog for any amount of time, it&#8217;s all about eye candy.</p>
<p><a href="http://savagelook.com/blog/wordpress/shadowbox-js-for-wordpress">ShadowBox JS for Wordpress</a> is a post from: <a href="http://savagelook.com/blog">SavageLook.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://savagelook.com/blog/wordpress/shadowbox-js-for-wordpress/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Webcam Video in Actionscript3</title>
		<link>http://savagelook.com/blog/code/webcam-video-in-actionscript3</link>
		<comments>http://savagelook.com/blog/code/webcam-video-in-actionscript3#comments</comments>
		<pubDate>Thu, 12 Aug 2010 03:21:13 +0000</pubDate>
		<dc:creator>Tony Lukasavage</dc:creator>
				<category><![CDATA[ActionScript3]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Code Demos]]></category>
		<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[webcam]]></category>

		<guid isPermaLink="false">http://savagelook.com/blog/?p=319</guid>
		<description><![CDATA[A simple example of how to access, use, and tweak your webcam in AS3<p><a href="http://savagelook.com/blog/code/webcam-video-in-actionscript3">Webcam Video in Actionscript3</a> is a post from: <a href="http://savagelook.com/blog">SavageLook.com</a></p>
]]></description>
			<content:encoded><![CDATA[<div class="wp-caption aligncenter" style="width: 459px"><a href="http://savagelook.com/demos/webcam/webcam.html" rel="shadowbox;height=600;width=800;"><img class=" " title="Webcam test" src="http://savagelook.com/images/webcam_post.jpg" alt="" width="449" height="321" /></a><p class="wp-caption-text">Webcam test in AS3</p></div>
<p>Click the above picture for the webcam demo (webcam required).<br />
Right click on the demo, or <a href="http://savagelook.com/demos/webcam/srcview/index.html" target="_self">click here for the source code</a>.</p>
<p>This is a pretty simple demo compared to some of my other stuff, but it&#8217;s a key point for a lot of them.  Knowing how to use the webcam independently of an existing library can open up lots of options beside augmented reality.  For that reason, I present this small demo showing off how easy it is to do so in Actionscript3.</p>
<p>Here&#8217;s a slightly modified excerpt from the full source code that is the meat and potatoes of the demo:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> camera<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Camera</span> = <span style="color: #004993;">Camera</span>.<span style="color: #004993;">getCamera</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
camera.<span style="color: #004993;">setQuality</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">100</span><span style="color: #000000;">&#41;</span>;
camera.<span style="color: #004993;">setMode</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">800</span>,<span style="color: #000000; font-weight:bold;">600</span>,<span style="color: #000000; font-weight:bold;">60</span>,<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> video<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Video</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Video</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">800</span>,<span style="color: #000000; font-weight:bold;">600</span><span style="color: #000000;">&#41;</span>;
video.<span style="color: #004993;">attachCamera</span><span style="color: #000000;">&#40;</span>camera<span style="color: #000000;">&#41;</span>;
<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>video<span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>As you can see, its as simple as creating a Camera object, attaching it to a Video object and adding the Video object to the main sprite.   The demo will show you how to manipulate image quality, camera frame rate, and viewport size.  For more details on all the properties and methods of each, check out the ASDocs on <a href="http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/media/Camera.html" target="_blank">Camera</a> and <a href="http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/media/Video.html" target="_blank">Video</a>.</p>
<p>What can you do with this besides making yet another video chat application?  I don&#8217;t know about you, but I&#8217;m planning an Away3DLite project that will involve multiple levels of &#8220;reflection&#8221; based on the images from the webcam.  It will be awesome.  Now I just need to figure out how I&#8217;m going to do it.  Details&#8230;</p>
<p><a href="http://savagelook.com/blog/code/webcam-video-in-actionscript3">Webcam Video in Actionscript3</a> is a post from: <a href="http://savagelook.com/blog">SavageLook.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://savagelook.com/blog/code/webcam-video-in-actionscript3/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Droid X and Android: My new best friends</title>
		<link>http://savagelook.com/blog/android/droid-x-and-android-my-new-best-friends</link>
		<comments>http://savagelook.com/blog/android/droid-x-and-android-my-new-best-friends#comments</comments>
		<pubDate>Wed, 11 Aug 2010 03:01:52 +0000</pubDate>
		<dc:creator>Tony Lukasavage</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[droid x]]></category>

		<guid isPermaLink="false">http://savagelook.com/blog/?p=242</guid>
		<description><![CDATA[I got myself a Droid X a few weeks ago and have been loving it.  I finally got around to building my development environment and actually got started working on my first app.  Right now I&#8217;m just toying around with the GPS service, but there&#8217;s tons of stuff I want to get to.  I&#8217;m hoping [...]<p><a href="http://savagelook.com/blog/android/droid-x-and-android-my-new-best-friends">Droid X and Android: My new best friends</a> is a post from: <a href="http://savagelook.com/blog">SavageLook.com</a></p>
]]></description>
			<content:encoded><![CDATA[<p>I got myself a Droid X a few weeks ago and have been loving it.  I finally got around to building my development environment and actually got started working on my first app.  Right now I&#8217;m just toying around with the GPS service, but there&#8217;s tons of stuff I want to get to.  I&#8217;m hoping to post up some screenshots, demos, and code soon.  For now the setup is:</p>
<ul>
<li><a href="http://www.eclipse.org/downloads/packages/release/galileo/sr2" target="_blank">Eclipse 3.5.2</a> + Android Plugin</li>
<li><a href="http://developer.android.com/sdk/index.html" target="_blank">Android 2.1 SDK</a> (til I get Froyo in a couple weeks)</li>
<li>USB connected Droid X (the emulator sucks to develop against)</li>
<li>A total lack of Java experience</li>
<li>Jack Daniel&#8217;s</li>
</ul>
<p>I know, it sounds awesome, but anything that includes Jack Daniel&#8217;s sounds awesome.  I also want to get my hands on the <a href="http://developer.android.com/sdk/ndk/index.html" target="_blank">Android Native Development Kit (NDK)</a> but just haven&#8217;t had time yet.  Android is going to be my favorite mistress for a little while, but don&#8217;t worry.  I&#8217;ll be back to Away3D in no time, especially once I get that Froyo update and can run Flash on my Droid X!</p>
<p><a href="http://savagelook.com/blog/android/droid-x-and-android-my-new-best-friends">Droid X and Android: My new best friends</a> is a post from: <a href="http://savagelook.com/blog">SavageLook.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://savagelook.com/blog/android/droid-x-and-android-my-new-best-friends/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Away3dLite: Bitmaps and BlendModes</title>
		<link>http://savagelook.com/blog/away3d/bitmaps-and-blendmodes</link>
		<comments>http://savagelook.com/blog/away3d/bitmaps-and-blendmodes#comments</comments>
		<pubDate>Tue, 10 Aug 2010 17:20:32 +0000</pubDate>
		<dc:creator>Tony Lukasavage</dc:creator>
				<category><![CDATA[Away3D]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Code Demos]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[away3dlite]]></category>
		<category><![CDATA[blending]]></category>
		<category><![CDATA[filters]]></category>

		<guid isPermaLink="false">http://savagelook.com/away3d/?p=40</guid>
		<description><![CDATA[Combine the Away3DLite engine with standard Flash blendmodes and filters for some interesting effects <p><a href="http://savagelook.com/blog/away3d/bitmaps-and-blendmodes">Away3dLite: Bitmaps and BlendModes</a> is a post from: <a href="http://savagelook.com/blog">SavageLook.com</a></p>
]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://www.savagelook.com/demos/image3d/sandbox.html" rel="shadowbox;height=600;width=800;"><img class="aligncenter size-full wp-image-43" title="image3d" src="http://savagelook.com/blog/wp-content/uploads/2010/06/image3d1.jpg" alt="" width="433" height="322" /></a></p>
<p>I finally took some time away from Away3D&#8230; and dove into Away3DLite!  Away3dLite is quite simply your choice when you need performance over functionality.  It strips a lot of the heavier features from Away3D and leverages improvements in Flash Player 10 directly.  For this reason it&#8217;s only compatible with Flash Player 10 (sorry 2.x users).  Away3dLite in the right hands, though, is no slouch in the visual flair department.</p>
<p>In this demo I take a JPG, slice and dice it up into cubes, apply a color material to each cube that is the &#8220;color average&#8221; of a chunk of BitmapData, then let you change the background color and blend mode to get some interesting visual effects.  The demo below has almost 5000 faces and 400 color materials, which would likely bring Away3D down to a crawl in terms of frame rate.  With Away3dLite, though, I&#8217;m currently getting a steady ~27 frame per second!  Great performance and cool effects all rolled into one great package.</p>
<p>You can right click and &#8220;view source&#8221; on the demo to get a look at exactly what I did, but there&#8217;s one section of code in particular I&#8217;d like to point out here.  In Away3D, if you want to apply Flash filters and blending, you needed to do the following:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> object<span style="color: #000000; font-weight: bold;">:</span>Cube = <span style="color: #0033ff; font-weight: bold;">new</span> Cube<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
object.ownCanvas = <span style="color: #0033ff; font-weight: bold;">true</span>;
object.<span style="color: #004993;">filters</span> = <span style="color: #000000;">&#91;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">GlowFilter</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>;
object.blendmode = <span style="color: #004993;">BlendMode</span>.<span style="color: #004993;">ADD</span>;
view.scene.<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>object<span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>In Away3DLite, things are slightly different.  In Away3DLite, objects don&#8217;t have their own canvas by default, I assume as a performance boost.  To give your objects a canvas and achieve the same as the above code, you have to create your own canvas in the layer property of Object3D and add it to the view, like this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> object<span style="color: #000000; font-weight: bold;">:</span>Cube6 = <span style="color: #0033ff; font-weight: bold;">new</span> Cube6<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
object.layer = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
object.layer.<span style="color: #004993;">filters</span> = <span style="color: #000000;">&#91;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">GlowFilter</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>;
object.layer.blendmode = <span style="color: #004993;">BlendMode</span>.<span style="color: #004993;">ADD</span>;
view.<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>cube.layer<span style="color: #000000;">&#41;</span>;
view.scene.<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>cube<span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>Hopefully this saves somebody switching from Away3D to Away3DLite a few minutes (or hours).</p>
<p><strong><span style="text-decoration: underline;">Featured Away3dLite Cod</span></strong><span style="text-decoration: underline;"><strong>e: </strong></span></p>
<ul>
<li>flash.display.BitmapData.getPixel()</li>
<li>flash.display.BlendMode</li>
<li>away3dlite.primitives.Cube6</li>
<li>away3dlite.core.base.Object3D.layer</li>
</ul>
<p><a href="http://savagelook.com/blog/away3d/bitmaps-and-blendmodes">Away3dLite: Bitmaps and BlendModes</a> is a post from: <a href="http://savagelook.com/blog">SavageLook.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://savagelook.com/blog/away3d/bitmaps-and-blendmodes/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>3DS in Away3D</title>
		<link>http://savagelook.com/blog/away3d/3ds-in-away3d</link>
		<comments>http://savagelook.com/blog/away3d/3ds-in-away3d#comments</comments>
		<pubDate>Tue, 10 Aug 2010 02:28:02 +0000</pubDate>
		<dc:creator>Tony Lukasavage</dc:creator>
				<category><![CDATA[Away3D]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Code Demos]]></category>
		<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[3ds]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://savagelook.com/away3d/?p=6</guid>
		<description><![CDATA[Learn how to import your 3DS models into the Away3D engine<p><a href="http://savagelook.com/blog/away3d/3ds-in-away3d">3DS in Away3D</a> is a post from: <a href="http://savagelook.com/blog">SavageLook.com</a></p>
]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a title="3DS Load Demo" href="http://savagelook.com/demos/3ds_load/sandbox.html" rel="shadowbox;height=600;width=800;"><img class="aligncenter size-full wp-image-9" title="torusknot" src="http://savagelook.com/blog/wp-content/uploads/2010/06/torusknot1.jpg" alt="" width="423" height="349" /></a></p>
<p>I&#8217;m starting to cook up a few game ideas with some friends of mine and I wanted to get a sense of what Away3D could really do.  To start, I made this very basic example of Away3D loading a fairly high poly 3DS file with minimal animation.  More specifically, it&#8217;s a rotating, 2880 poly, torus knot with a wire frame material.  While Away3D isn&#8217;t really made to handle models with this many polys, it gives me an idea of how it will handle a total polycount of about 3000.</p>
<p><strong>Featured Away3D code</strong>: Max3DS.load() and WireColorMaterial</p>
<p>Click the image above to access the example.  You can right click on the example and click &#8220;view source&#8221; to,  you guessed it, view the source.</p>
<p><a href="http://savagelook.com/blog/away3d/3ds-in-away3d">3DS in Away3D</a> is a post from: <a href="http://savagelook.com/blog">SavageLook.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://savagelook.com/blog/away3d/3ds-in-away3d/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->