<?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>Almer/Blank Labs &#187; Actionscript 3.0</title>
	<atom:link href="http://labs.almerblank.com/tag/actionscript-3-0/feed/" rel="self" type="application/rss+xml" />
	<link>http://labs.almerblank.com</link>
	<description>Blog of the Talent at Almer/Blank</description>
	<lastBuildDate>Mon, 19 Jul 2010 22:55:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>OSMF Sample Player Update for 1.0</title>
		<link>http://labs.almerblank.com/2010/07/osmf-sample-player-update-for-1-0/</link>
		<comments>http://labs.almerblank.com/2010/07/osmf-sample-player-update-for-1-0/#comments</comments>
		<pubDate>Tue, 06 Jul 2010 02:31:37 +0000</pubDate>
		<dc:creator>rblank</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Code & Samples]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[adob]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[max]]></category>
		<category><![CDATA[OSMF]]></category>

		<guid isPermaLink="false">http://labs.almerblank.com/?p=1518</guid>
		<description><![CDATA[I&#039;ve finally started work on my OSMF lab for MAX, &#039;Designing Custom Video Players with OSMF&#039; (you can browse the catalog of talks and presentations and then you can register here).
As you may know, OSMF 1.0 has been release, so one of the first tasks I set for myself was to test the code I [...]]]></description>
			<content:encoded><![CDATA[<p>I&#039;ve finally started work on my OSMF lab for MAX, &#039;Designing Custom Video Players with OSMF&#039; (you can <a href="http://max.adobe.com/sessions/catalog/" target="_blank">browse the catalog of talks and presentations</a> and then you can <a href="http://max.adobe.com/register" target="_blank">register here</a>).</p>
<p>As you may know, OSMF 1.0 has been release, so one of the first tasks I set for myself was to test the code I wrote in April for OSMF 0.95 (which I posted, along with the screencasts of my talk at FITC, <a href="http://labs.almerblank.com/2010/04/new-intro-to-adobe-osmf-videos/">here</a>). And, lo and behold, all of them worked!</p>
<p>Well, all except one. The final demo file, the <cite>Full Sample Player</cite> was playing, but the video was invisible and all the controls were disabled. So I set out to figure out why. (For those who don&#039;t want to read to the end, you can <a href="http://labs.almerblank.com/wp-content/uploads/2010/07/Full-Basic-Player-Update_20100705.zip">download the updated project file, for Flash CS5, here</a>.)</p>
<p><span id="more-1518"></span>It wasn&#039;t long before I found the culprit. It turns out that the MediaPlayer in OSMF now dispatches the &#039;ready&#039; MediaPlayerStateChangeEvent when the video is ready to play for the first time &#8212; not just when it&#039;s ready to play again. So, the result of my last code sample, with OSMF 1.0, was to hide the video and disable the controls &#8212; at the start of the video playback! Not what I wanted.</p>
<p>So, if we just remove lines 157 and 158 (seen below), from the _onMediaPlayerStateChange function, the player will work.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;ready&quot;</span>:
	_disableControls <span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#41;</span> ;
	_cleanUpVideo <span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#41;</span> ;
	<span style="color: #b1b100;">break</span>;</pre></div></div>

<p>But now, when our video ends, the video doesn&#039;t get reset (or &#039;cleaned up&#039; or however you want to say it) &#8212; it looks ugly and doesn&#039;t behave how we would expect (because we just removed the code that&#039;s supposed to clean up these videos).</p>
<p>So, how do we clean up at the end of a video? Well, you can now listen for the TimeEvent.COMPLETE event on the MediaPlayer instance &#8212; when it&#039;s fired, the playback of your media is done.</p>
<p>So, if we add this line to the _setupOSMF() function:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">_mediaPlayer.<span style="color: #006600;">addEventListener</span> <span style="color: #66cc66;">&#40;</span> TimeEvent.<span style="color: #006600;">COMPLETE</span> , _onComplete , <span style="color: #000000; font-weight: bold;">false</span> , <span style="color: #cc66cc;">0</span> , <span style="color: #000000; font-weight: bold;">true</span> <span style="color: #66cc66;">&#41;</span> ;</pre></div></div>

<p>&#8230;and then declare the _onComplete function, adding back in those two lines we removed from the _onMediaPlayerStateChange function:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _onComplete <span style="color: #66cc66;">&#40;</span> evt : TimeEvent <span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	_disableControls <span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#41;</span> ;
	_cleanUpVideo <span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#41;</span> ;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>One final note&#8230; Adobe added in string constants for all of the MediaPlayerStateChangeEvent types, grouped in the new MediaPlayerState class. So instead of comparing against the string, &#034;ready&#034;, you can now compare against the string constant of MediaPlayerState.READY. All of them are listed <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/org/osmf/media/MediaPlayerState.html" target="_blank">here</a> and have been included in the <a href="http://labs.almerblank.com/wp-content/uploads/2010/07/Full-Basic-Player-Update_20100705.zip">updated source files that accompany this post</a>.</p>
<p>See you in October at MAX in LA!</p>
<p>And, as always, share and enjoy!</p>
<p>-r</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.almerblank.com/2010/07/osmf-sample-player-update-for-1-0/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>R Blank Speaking at FITC SF</title>
		<link>http://labs.almerblank.com/2010/06/r-blank-speaking-at-fitc-sf/</link>
		<comments>http://labs.almerblank.com/2010/06/r-blank-speaking-at-fitc-sf/#comments</comments>
		<pubDate>Thu, 24 Jun 2010 02:07:00 +0000</pubDate>
		<dc:creator>rblank</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Actionscript 3.0]]></category>

		<guid isPermaLink="false">http://labs.almerblank.com/?p=1513</guid>
		<description><![CDATA[Howdy all:
I know blogging&#039;s been light for the past several months. Work here at Almer/Blank has had me pretty consumed.
But, as I gear up and prepare for a busy autumn of talks and courses, you can expect some heavier posting.
First up, I&#039;ll be presenting at FITC San Francisco &#8212; the first SF installment of the [...]]]></description>
			<content:encoded><![CDATA[<p>Howdy all:</p>
<p>I know blogging&#039;s been light for the past several months. Work here at <a href="http://almerblank.com" target="_blank">Almer/Blank</a> has had me pretty consumed.</p>
<p>But, as I gear up and prepare for a busy autumn of talks and courses, you can expect some heavier posting.</p>
<p>First up, I&#039;ll be presenting at <a href="http://www.fitc.ca/events/schedule/?event=110" target="_blank">FITC San Francisco</a> &#8212; the first SF installment of the really amazing <a href="http://fitc.ca/" target="_blank">FITC conferences</a>.</p>
<p><a href="http://www.fitc.ca/events/schedule/?event=110"><img class="alignnone size-full wp-image-1055" src="http://www.rblank.com/wp-content/uploads/2010/06/FITC_sf2010_200x150_speaker_.jpg" alt="" width="200" height="150" /></a></p>
<p><span id="more-1513"></span>On day one, August 17th, I&#039;ll be giving my talk, <a href="http://www.fitc.ca/events/presentations/presentation.cfm?event=110&amp;presentation_id=1215" target="_blank">&#039;Hearing Pictures with Synthia&#039;</a> &#8212; you can see an earlier version of that talk, from FITC Toronto in April, <a href="http://labs.almerblank.com/hearing-pictures-with-synthia/" target="_blank">here</a>, and play with Synthia at <a href="http://SynthiaHearsPictures.com" target="_blank">SynthiaHearsPictures.com</a>.</p>
<p>Then, on day three, August 19th, I&#039;ll be giving a talk on <a href="http://www.fitc.ca/events/presentations/presentation.cfm?event=110&amp;presentation_id=1277" target="_blank">&#039;Getting Started with Adobe Open Source Media Framework (OSMF)&#039;</a> in the &#039;Adobe Under the Hood&#039; room &#8212; a version from FITC Toronto in April you can view <a href="http://labs.almerblank.com/2010/04/new-intro-to-adobe-osmf-videos/" target="_blank">here</a>.</p>
<p>It will be an amazing conference, with a ton of great talks. Early bird pricing ends July 2nd, so get your tickets now!</p>
<p>Share and enjoy!</p>
<p>-r</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.almerblank.com/2010/06/r-blank-speaking-at-fitc-sf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ZamfBrowser 1.2 and ZendAmfServiceBrowser Update</title>
		<link>http://labs.almerblank.com/2010/02/zamfbrowser-1-2-and-zendamfservicebrowser-update/</link>
		<comments>http://labs.almerblank.com/2010/02/zamfbrowser-1-2-and-zendamfservicebrowser-update/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 21:58:42 +0000</pubDate>
		<dc:creator>Omar Gonzalez</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Code & Samples]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Zamf]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[ZendAMF]]></category>
		<category><![CDATA[ZendAMF Service Browser]]></category>

		<guid isPermaLink="false">http://labs.almerblank.com/?p=1321</guid>
		<description><![CDATA[Over the weekend I updated both the ZamfBrowser application and the ZendAmfServiceBrowser class that gives the ZamfBrowser information about your ZendAMF services set up.  The ZendAmfServiceBrowser class now supports using the Zend_Amf_Server-&#62;addDirectory() method.  I also integrated some optimization suggestions submitted by Marijn Huizendveld.  Thanks for your contributions Marijn!  ZamfBrowser got updates to fix all the [...]]]></description>
			<content:encoded><![CDATA[<p>Over the weekend I updated both the ZamfBrowser application and the ZendAmfServiceBrowser class that gives the ZamfBrowser information about your ZendAMF services set up.  <span id="more-1321"></span>The ZendAmfServiceBrowser class now supports using the Zend_Amf_Server-&gt;addDirectory() method.  I also integrated some optimization suggestions submitted by Marijn Huizendveld.  Thanks for your contributions Marijn!  ZamfBrowser got updates to fix all the currently reported bugs.  You can get more info about what exactly was updated, as well as download the source, at http://zamfbrowser.riaforge.com.  Info on the ZendAmfServiceBrowser class update can be found at http://www.zamfbrowser.org</p>
<p>If you have suggestions for enhancements or more bug fixes please do report them at http://zamfbrowser.riaforge.com  If you don&#039;t want to sign up for RIAForge just send me an email to omar@almerblank.com, I&#039;d really like to hear your suggestions and bug reports!</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.almerblank.com/2010/02/zamfbrowser-1-2-and-zendamfservicebrowser-update/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>OSMF Sample Player Update</title>
		<link>http://labs.almerblank.com/2010/02/osmf-sample-player-update/</link>
		<comments>http://labs.almerblank.com/2010/02/osmf-sample-player-update/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 22:36:05 +0000</pubDate>
		<dc:creator>rblank</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Code & Samples]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[OSMF]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://labs.almerblank.com/?p=1317</guid>
		<description><![CDATA[Some of you may have checked out the courses I posted over on the Adobe Developer Connection on building <a href="http://www.adobe.com/devnet/flash/articles/video_osmf.html" target="_blank">progressive</a> and <a href="http://www.adobe.com/devnet/flash/articles/video_osmf_streaming.html" target="_blank">streaming video players</a> with the Adobe Open Source Media Framework (OSMF).

Unfortunately, even those courses are relatively new, the code in them no longer works, because OSMF has advanced a few sprints. We're now at OSMF sprint 9, and the framework continues to shift quite a bit.

Because there are almost no examples on the web of using OSMF with Flash (as opposed to Flex), and I've had several people email me asking if I had time to update the code.

And, so, finally I did. At least for the progressive player. So you can download the <a href="http://www.adobe.com/devnet/flash/articles/video_osmf/osmf9_progressive_players_cs4.zip" target="_blank">Flash CS4 source code to build an OSMF player with the Sprint 9 framework</a> from the <a href="http://www.adobe.com/devnet/flash/articles/video_osmf.html" target="_blank">article on Building progressive video players in Flash with OSMF</a>.

Share and enjoy!

]]></description>
			<content:encoded><![CDATA[<p>Some of you may have checked out the courses I posted over on the Adobe Developer Connection on building <a href="http://www.adobe.com/devnet/flash/articles/video_osmf.html" target="_blank">progressive</a> and <a href="http://www.adobe.com/devnet/flash/articles/video_osmf_streaming.html" target="_blank">streaming video players</a> with the Adobe Open Source Media Framework (OSMF).</p>
<p>Unfortunately, even those courses are relatively new, the code in them no longer works, because OSMF has advanced a few sprints. We&#039;re now at OSMF sprint 9, and the framework continues to shift quite a bit.</p>
<p>Because there are almost no examples on the web of using OSMF with Flash (as opposed to Flex), and I&#039;ve had several people email me asking if I had time to update the code.</p>
<p>And, so, finally I did. At least for the progressive player. So you can download the <a href="http://www.adobe.com/devnet/flash/articles/video_osmf/osmf9_progressive_players_cs4.zip" target="_blank">Flash CS4 source code to build an OSMF player with the Sprint 9 framework</a> from the <a href="http://www.adobe.com/devnet/flash/articles/video_osmf.html" target="_blank">article on Building progressive video players in Flash with OSMF</a>.</p>
<p>Share and enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.almerblank.com/2010/02/osmf-sample-player-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multi-bitrate Streaming in Adobe OSMF</title>
		<link>http://labs.almerblank.com/2009/12/multi-bitrate-streaming-in-adobe-osmf/</link>
		<comments>http://labs.almerblank.com/2009/12/multi-bitrate-streaming-in-adobe-osmf/#comments</comments>
		<pubDate>Mon, 28 Dec 2009 19:31:53 +0000</pubDate>
		<dc:creator>rblank</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Code & Samples]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[training]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[flash video]]></category>
		<category><![CDATA[OSMF]]></category>

		<guid isPermaLink="false">http://labs.almerblank.com/?p=1299</guid>
		<description><![CDATA[My new online video course on Dynamic Multi-bitrate Streaming with Adobe Open Source Media Framework (OSMF) has just gone live on Adobe Developer Connection.
It&#039;s 35 minutes across five lessons and takes you through the process of converting the progressive OSMF video player (which we create in the first installment of this course on Building Progressive [...]]]></description>
			<content:encoded><![CDATA[<p>My new online video <a href="http://www.adobe.com/devnet/flash/articles/video_osmf_streaming.html" target="_blank">course on Dynamic Multi-bitrate Streaming with Adobe Open Source Media Framework</a> (OSMF) has just gone live on Adobe Developer Connection.</p>
<p>It&#039;s 35 minutes across five lessons and takes you through the process of converting the progressive OSMF video player (which we create in the first installment of this course on <a href="http://www.adobe.com/devnet/flash/articles/video_osmf.html" target="_blank">Building Progressive Video Players with Adobe OSMF</a>, into a dynamic multi-bitrate streaming player. Multi-bitrate streaming occurs when you program your Flash to deliver the highest quality video a viewer can see (dependent on their bandwidth). *<strong>Dynamic</strong>* multi-bitrate streaming is similar, with the additional feature of having your player constantly meters the bandwidth throughout viewing, to adjust the playback between multiple videos seamlessly, as the viewer&#039;s bandwidth may fluctuate.<span id="more-1299"></span></p>
<blockquote><p><strong>Please note:</strong> that the first course on progressive video players was built with OSMF Sprint 5. The second course on streaming with OSMF was built with OSMF Sprint 7. I spend the first lesson of the new course updating the progressive player to work with Sprint 7, and I wrote a few notes about <a href="http://www.rblank.com/2009/11/10/quick-note-on-osmf-0-7/" target="_blank">the major differences between OSMF 0.5 and 0.7 in a post on my personal blog</a> last month. Also note that, by the time the course was published by Adobe, OSMF had already moved forward to Spring 8.</p></blockquote>
<p>When I wrote the first course on building a progressive video player with OSMF, I was struck by two things:<br />
1) OSMF is clean &#8212; really clean &#8212; and it just works well in ways that the AS3 video API does not &#8212; for instance, with OSMF setting volume is a matter of talking to the volume property of the MediaPlayer<br />
2) OSMF felt like a bit of overkill &#8212; you need a lot of imports and classes (a MediaPlayer, a MediaElement, a NetLoader and a URLResource) just to build the simplest of progressive video players &#8212; that would be simple enough, requiring seven lines of code with raw AS3 if you knew it</p>
<p>But, I had a hunch that #2 above was due to the fact that I was using approximately 0.05% of this powerful framework &#8212; like trying to use a nuclear bomb when a shovel would do just fine.</p>
<p>Well, when I started learning how to write the code to build dynamic multi-bitrate streaming player, I quickly learned that my hunch was right. The benefits of OSMF really kick in once you do anything beyond the most basic video player.</p>
<p>In the case of streaming, to convert your progressive OSMF video player to a streaming OSMF video player, all you do is change the URL! Seriously, that&#039;s it. OSMF is smart enough to know that when you try to load a video from an RTMP server, you&#039;re trying to stream &#8212; and it takes care of the rest.</p>
<p>That was pretty neat. But the benefits really kicked in when I beefed my regular streaming OSMF video player to one that supports dynamic multi-bitrate streaming. All it took was just a few extra lines of code to turn my regular video player into one that supports dynamic multi-bitrate streaming. If you want to learn those lines of code, I&#039;d recommend checking out the course.</p>
<p>As I say, I&#039;m still just barely cracking the surface of OSMF, and I&#039;m really looking forward to digging deeper into its support for layouts, playlists and monetization. But, even with this second course, the massive time, workflow and standardization features of OSMF are already revealing themselves.</p>
<p>Share and enjoy!</p>
<p>-r</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.almerblank.com/2009/12/multi-bitrate-streaming-in-adobe-osmf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hype/Papervision3D Demo</title>
		<link>http://labs.almerblank.com/2009/11/hypepapervision3d-demo/</link>
		<comments>http://labs.almerblank.com/2009/11/hypepapervision3d-demo/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 19:40:11 +0000</pubDate>
		<dc:creator>Nolan Butcher</dc:creator>
				<category><![CDATA[Code & Samples]]></category>
		<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Hype]]></category>
		<category><![CDATA[Papervision]]></category>
		<category><![CDATA[RIA]]></category>

		<guid isPermaLink="false">http://flexgraphix.com/blog/?p=101</guid>
		<description><![CDATA[This post features a quick demo of some of the SoundAnalyzer capabilities of the Hype framework, including some code samples. After working with Hype, I've found that while it's definitely not a catch-all framework, it does help cut down on common repetitive coding tasks.

UPDATE - I decided to give a tween engine one more shot, and was able to use TweenMax while keeping the framerate at an acceptable level.]]></description>
			<content:encoded><![CDATA[So after getting my hands on the new <a href="http://hype.joshuadavis.com/">Hype</a> framework, I wanted to put together a simple demo together that utilizes a combination of the SoundAnalyzer class and some 3D eye candy (via Papervision3D).<br /><br />

First off, I can say that I really like being able to play around with the sound spectrum using only a couple lines of code. I also used the Rythm class to run an enter frame method, which is very convenient in that I didn't need to manually set up an event and listener.<br /><br />

Lastly, I wanted to also utilize a tweening engine to smooth out the particle movement, but doing so cut the framerate by about 80% (a little better with TweenMax/TweenLite, but still not good enough). I also briefly played around with the <a href="http://flintparticles.org/">Flint particle emitter</a>, but I'm not familiar enough with Papervision/Flint to get it working how I wanted.<br /><br />

<strong style="font-weight: bold;">UPDATE - I decided to give a tween engine one more shot, and was able to use TweenMax while keeping the framerate at an acceptable level.</strong><br /><br />

<strong style="font-weight: bold;">UPDATE 11/06/2009 - Updated code sample to reflect demo swf.</strong><br /><br />

<strong>UPDATE 3/29/2010 - It's come to my attention that Wordpress tends to be a bit moody when it comes to code formatting in posts, especially in the case of vectors (which use the greater than/less than characters). That said, I've posted a couple pastebin examples:<br /><br />

Link --> <a href="http://pastebin.com/LbBzZdjJ">Document class</a><br />
Link --> <a href="http://pastebin.com/uyk8gfnh">ApplicationView class</a><br />
</strong><br />
<span id="more-1215"></span>


Here's the demo in action-<br /><br />

<object width="580" height="580"><param name="movie" value="http://flexgraphix.com/blog/wp-content/uploads/2009/11/Paper_Hype_Lab3.swf"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://flexgraphix.com/blog/wp-content/uploads/2009/11/Paper_Hype_Lab3.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="580" height="580"></embed></object>

..and here's the code-<br />

Paper_Hype_Lab.as (this would be the document class in Flash):
<pre lang="actionscript3">package {
	import __AS3__.vec.Vector;

	import com.almerblanklabs.view.ApplicationView;
	import com.lifeztream.debug.FPS;

	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.MouseEvent;
	import flash.events.ProgressEvent;
	import flash.external.ExternalInterface;
	import flash.media.Sound;
	import flash.media.SoundChannel;
	import flash.media.SoundLoaderContext;
	import flash.media.SoundTransform;
	import flash.net.URLRequest;
	import flash.system.LoaderContext;
	import flash.system.Security;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;

	import flash.utils.setTimeout;

	import hype.framework.behavior.SimpleBehavior;
	import hype.framework.core.TimeType;
	import hype.framework.rhythm.SimpleRhythm;
	import hype.framework.sound.SoundAnalyzer;

	import org.papervision3d.objects.primitives.Sphere;

	[SWF(width='580', height='580', backgroundColor='#000000')]

	/**
	 *
	 * @author Nolan Butcher
	 *
	 * DISCLAIMER : This code sample is by no means an optimized example. It is a PROTOTYPE.
	 * 				Please keep this in mind when looking through this code.
	 *
	 */	

	public class Paper_Hype_Lab extends Sprite
	{
		private static const ARTIST : String = "Trioptic of the Sound Scientists";
		private static const AUDIO_PATH : String = 'http://flexgraphix.com/blog/wp-content/uploads/2009/11/';
		private static const AUDIO_FILES : Array = [
														{file:'evil_violin.mp3', title:'Evil Violin(Rich \'n Stingy)'},
														{file:'am_i_going_to_die.mp3', title:'Am I Going to Die'},
														{file:'going_pro.mp3', title:'Going Pro'},
														{file:'life_is_easily_taken.mp3', title:'Life is Easily Taken'},
														{file:'bubachu.mp3', title:'Bubachu'},
														{file:'midi_in-out.mp3', title:'Midi In/Out'},
														{file:'may_6.mp3', title:'May 6'},
														{file:'slow_descent.mp3', title:'Slow Descent'},
														{file:'nocens_sonitus.mp3', title:'Nocens Sonitus'},
														{file:'remember.mp3', title:'Remember'},
														{file:'soulful_east_coast.mp3', title:'Soulful East Coast'},
														{file:'sunrise_on_the_highway.mp3', title:'Sunrise on the Highway'},
														{file:'the_sad_truth_of_it_all.mp3', title:'The Sad Truth of it All'},
														{file:'blueberry_haze.mp3', title:'Blueberry Haze'}
													];

		private static const VOLUME : Number = 1;

		private var _view : ApplicationView;
		private var _sphere : Sphere;
		private var _music : Sound;
		private var _sndChannel : SoundChannel;
		private var _soundAnalyzer : SoundAnalyzer;
		private var _freq : Vector. = new Vector.;
		private var _rythm : SimpleRhythm;
		private var _fps : FPS;
		private var _audioIndex : int = 1;

		private var _button : Sprite;
		private var _hitArea : Sprite;

		private var _textField : TextField;
		private var _songText : TextField;

		private var _rotationX : Number = 0.3;
		private var _rotationY : Number = 0.3;
		private var _cameraPitch : Number = 90;
		private var _cameraYaw : Number = 270;

		private var _xDist : Number;
		private var _yDist : Number;

		private var _mouseDown : Boolean = false;

		public function Paper_Hype_Lab()
		{
			Security.allowDomain('*');

			stage.frameRate = 60;

			_sphere = new Sphere(null, 300, 24, 14);

			_view = new ApplicationView();
			_view.object3D = _sphere;
			_view.startRendering();

			addChild(_view);

			_initRythm();
			_initTextField();
			_loadSound();
			_initUI();

			// Get the FPS widget @ www.lifeztream.com
			_fps = new FPS();
			addChild(_fps);

		}

		private function _handleMouseEvents(evt:MouseEvent):void
		{
			switch(String(evt.type))
			{
				case MouseEvent.MOUSE_DOWN:
					_mouseDown = true;
				break;
				case MouseEvent.MOUSE_UP:
					_mouseDown = false;
				break;
			}
		}

		private function _loadSound():void
		{
			var context : SoundLoaderContext = new SoundLoaderContext(1000, true);
			var req : URLRequest = new URLRequest();
				req.url = AUDIO_PATH + AUDIO_FILES[_audioIndex].file;

			if (_rythm &amp;&amp; _rythm.isRunning) _pauseRythm();
			if (_sndChannel)
			{
				_sndChannel.stop();
				try {
					_music.close();
				} catch(e:Error) {
					trace ('cannot close sound stream');
				}
			}
			_music = new Sound(req, context);
			_music.addEventListener(IOErrorEvent.IO_ERROR, _handleIOErrorEvents, false, 0, true);

			_sndChannel = _music.play(0, 1, new SoundTransform(VOLUME));
			_sndChannel.addEventListener(Event.SOUND_COMPLETE, _onSoundDone, false, 0, true);

			_soundAnalyzer = new SoundAnalyzer();
			_soundAnalyzer.start();

			_updateSongText();
			if (_rythm) _initRythm();

		}

		private function _onSoundDone(evt:Event):void
		{
			_button.mouseEnabled = false;
			setTimeout(_nextSong, 1000);
		}

		private function _nextSong():void
		{
			_button.mouseEnabled = true;
			_button.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
		}

		private function _handleIOErrorEvents(evt:IOErrorEvent):void
		{
			if (ExternalInterface.available)
			{
				ExternalInterface.call("window.alert('" + AUDIO_FILES[_audioIndex].file + " cannot be loaded')");
			}
		}

		private function _initUI():void
		{
			_hitArea = new Sprite();
			_hitArea.graphics.beginFill(0x000,0);
			_hitArea.graphics.drawRect(0,0,580,580);
			_hitArea.graphics.endFill();
			_hitArea.addEventListener(MouseEvent.MOUSE_DOWN, _handleMouseEvents, false, 0, true);
			_hitArea.addEventListener(MouseEvent.MOUSE_UP, _handleMouseEvents, false, 0, true);
			addChild(_hitArea);

			_button = new Sprite();
			_button.graphics.beginFill(0x666666);
			_button.graphics.drawRect(0,0,100,30);
			_button.graphics.endFill();
			_button.x = 476;
			_button.y = 4;
			_button.buttonMode = true;
			_button.mouseChildren = false;
			_button.useHandCursor = true;
			_button.addEventListener(MouseEvent.CLICK, _handleButtonEvents, false, 0, true);

			var buttonFormat : TextFormat = new TextFormat(null, 14, 0xFFFFFF, true);
			var buttonText : TextField = new TextField();

				buttonText.defaultTextFormat = buttonFormat;
				buttonText.text = "NEXT RIFF";
				buttonText.height = 18;
				buttonText.y = (_button.height - buttonText.textHeight) * .5;
				buttonText.x = (_button.width - buttonText.textWidth) * .5;

			addChild(_button);

			_button.addChild(buttonText);
		}

		private function _pauseRythm():void
		{
			_rythm.stop();
		}

		private function _resumeRythm():void
		{
			_rythm.start();
		}

		private function _initRythm():void
		{
			_rythm = new SimpleRhythm(_trackRythm);
			_rythm.start(TimeType.ENTER_FRAME);
		}

		private function _initTextField():void
		{
			var textFormat : TextFormat = new TextFormat();
				textFormat.color = 0x666666;
				textFormat.align = TextFormatAlign.CENTER;
				textFormat.size = 14;

			_songText = new TextField();
			_songText.defaultTextFormat = textFormat;
			_songText.width = 1;
			_songText.text = "-- :: --";
			_songText.autoSize = TextFieldAutoSize.CENTER;
			_songText.y = (stage.stageHeight - _songText.textHeight) - 4;
			_songText.x = (stage.stageWidth - _songText.width) * 0.5;
			addChild(_songText);

			var artistText : TextField = new TextField();
				artistText.defaultTextFormat = textFormat;
				artistText.width = 1;
				artistText.text = "-- Artist :: " + ARTIST + " --";
				artistText.x = (stage.stageWidth - artistText.width) * 0.5;
				artistText.y = (_songText.y - artistText.textHeight) - 4;
				artistText.autoSize = TextFieldAutoSize.CENTER;

			addChild(artistText);

			_textField = new TextField();
			_textField.width = 1;
			_textField.defaultTextFormat = textFormat;
			_textField.text = "-- Click and drag to rotate sphere --";
			_textField.x = (stage.stageWidth - _textField.width) * 0.5;
			_textField.y = artistText.y - _textField.textHeight - 5;
			_textField.autoSize = TextFieldAutoSize.CENTER;

			addChild(_textField);

		}

		private function _updateSongText():void
		{
			_songText.text = "-- Song :: " + AUDIO_FILES[_audioIndex].title + " --";
			_songText.x = (stage.stageWidth - _songText.width) * 0.5;
		}

		private function _handleButtonEvents(evt:MouseEvent):void
		{
			_sndChannel.removeEventListener(Event.SOUND_COMPLETE, _onSoundDone);
			if (_audioIndex &lt; AUDIO_FILES.length-2)
			{
				_audioIndex++;
			} else {
				_audioIndex = 0;
			}

			_loadSound();
		}

		private function _trackRythm(rythm : SimpleRhythm):void
		{
			for (var i:int = 1;i &lt; _sphere.geometry.vertices.length + 1;++i)
			{
				_freq[i-1] = _soundAnalyzer.getFrequencyIndex(i, 400, 100);
			}

			_view.moveParticles(_freq);

			// Rotates camera around sphere depending on mouse position
			if (_mouseDown)
			{
				_xDist = mouseX - stage.stageWidth * 0.5;
				_yDist = mouseY - stage.stageHeight * 0.5;

				_cameraPitch = _yDist * _rotationX + 90;
				_cameraYaw = _xDist * _rotationY + 270;

				_view.camera.orbit(_cameraPitch, _cameraYaw);
			}

		}
	}
}</pre>
ApplicationView.as (extends PV3D's BasicView class):
<pre lang="actionscript3">package com.almerblanklabs.view
{
	import __AS3__.vec.Vector;
	
	import com.greensock.OverwriteManager;
	import com.greensock.TweenMax;
	import com.greensock.easing.Elastic;
	import com.greensock.plugins.MotionBlurPlugin;
	import com.greensock.plugins.TweenPlugin;
	
	import flash.events.Event;
	
	import org.papervision3d.core.geom.Particles;
	import org.papervision3d.core.geom.renderables.Particle;
	import org.papervision3d.core.geom.renderables.Vertex3D;
	import org.papervision3d.materials.special.ParticleMaterial;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.primitives.Sphere;
	import org.papervision3d.view.BasicView;
	
	//import com.greensock.plugins.

	public class ApplicationView extends BasicView
	{
		private var _object3D : DisplayObject3D;
		private var _origVertices : Vector.<Object>;
		private var _displayObj : DisplayObject3D;
		private var _satellites : Vector.<Particle>;
		private var _particles : Particles;
		
		public function ApplicationView()
		{
			super(580, 580);	
			//TweenPlugin.activate([MotionBlurPlugin]);		
		}
		
		override protected function onRenderTick(event:Event=null):void
		{
			super.onRenderTick();
		}
		
		public function set object3D(aValue : DisplayObject3D):void
		{
			_object3D = aValue;
			_setObjectVertices();
		}
		
		private function _setObjectVertices():void
		{
			_origVertices = new Vector.<Object>;
			for each(var vert : Vertex3D in _object3D.geometry.vertices)
			{
				var vertObj : Object = {x:vert.x, y:vert.y, z:vert.z};
				_origVertices.push(vertObj);
			}
			
			_initParticles();
		}
		
		private function _initParticles():void
		{			
			var material : ParticleMaterial = new ParticleMaterial(0xff0000, 1, ParticleMaterial.SHAPE_CIRCLE, 10);
			
			_satellites = new Vector.<Particle>();			
			_particles = new Particles();			
			_displayObj = new DisplayObject3D();
			
			scene.addChild(_particles);
			scene.addChild(_displayObj);
			
			_displayObj.addChild(_particles);
			
			for each(var vert : Vertex3D in _object3D.geometry.vertices)
			{					
				var particle : Particle = new Particle(material);
					particle.x = vert.x;
					particle.y = vert.y;
					particle.z = vert.z;
					
				_particles.addParticle(particle);
				
				_satellites.push(particle);
			}
		}
		
		public function moveParticles(aValue:Vector.<Number>):void
		{
				var i : int = 0;
				var j : int = 0;
				var t : int = 0;
				
				// This ensures even distribution among all vertices.
				var divisor : Number = Math.floor(_satellites.length / 256);
				
				for each (var sat : Particle in _satellites)
				{
					// The values used in the x,y,z calculations were achieved through trial and error...
					TweenMax.to(_satellites[i], .2, {
														x: _origVertices[i].x * ((400 / aValue[i]) * 1.2),
														y: _origVertices[i].y * ((400 / aValue[i]) * 1.2),
														z: _origVertices[i].z * ((400 / aValue[i]) * 1.2),
														overwrite: OverwriteManager.PREEXISTING
													} );
					
					
					if (i < (_satellites.length - (divisor - 1))) {
						i += divisor;
					}
					
					
				}
				
			
			_displayObj.localRotationZ += .3;
			_displayObj.localRotationY += .1;			
		}
		
		private function _renderScene():void
		{
			renderer.renderScene(scene, camera, viewport);
		}
	}
}</pre>
Enjoy ;)]]></content:encoded>
			<wfw:commentRss>http://labs.almerblank.com/2009/11/hypepapervision3d-demo/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Organizing PureMVC Notifications</title>
		<link>http://labs.almerblank.com/2009/11/organizing-puremvc-notifications/</link>
		<comments>http://labs.almerblank.com/2009/11/organizing-puremvc-notifications/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 09:33:28 +0000</pubDate>
		<dc:creator>Omar Gonzalez</dc:creator>
				<category><![CDATA[Code & Samples]]></category>
		<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[pmvc]]></category>
		<category><![CDATA[PureMVC]]></category>
		<category><![CDATA[standards]]></category>

		<guid isPermaLink="false">http://labs.almerblank.com/?p=1071</guid>
		<description><![CDATA[One of my favorite things about using PureMVC as my application framework are the standards established for organizing application code.  For notification names the common ways that I have seen these organized is by declaring constants on the concrete Facade, or by externalizing them to external classes.  I have tried both approaches, but my preferred [...]]]></description>
			<content:encoded><![CDATA[<p>One of my favorite things about using PureMVC as my application framework are the standards established for organizing application code.  For notification names the common ways that I have seen these organized is by declaring constants on the concrete Facade, or by externalizing them to external classes.  I have tried both approaches, but my preferred method is to externalize the constants to notification classes.  Not only do I feel like its more organized because the notification names for a section of the application are centralized to different notification classes.  But, it is also a good way to clean up the amount of imports in the concrete Facade and centralize the Command registrations to these notification classes.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.project.controller.notifications
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com.project.controller.commands.LoginCommand;
	<span style="color: #0033ff; font-weight: bold;">import</span> com.project.controller.commands.LogoutCommand;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> org.puremvc.as3.interfaces.IFacade;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> LoginNotifications
	<span style="color: #000000;">&#123;</span>
		static <span style="color: #0033ff; font-weight: bold;">public</span> const LOGIN<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;LOGIN_NOTIFICATION&quot;</span>;
&nbsp;
		static <span style="color: #0033ff; font-weight: bold;">public</span> const LOGOUT<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;LOGOUT_NOTIFICATION&quot;</span>;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> LoginNotifications<span style="color: #000000;">&#40;</span> facade<span style="color: #000000; font-weight: bold;">:</span>IFacade <span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			facade.registerCommand<span style="color: #000000;">&#40;</span> LOGIN, LoginCommand <span style="color: #000000;">&#41;</span>;
			facade.registerCommand<span style="color: #000000;">&#40;</span> LOGOUT, LogoutCommand <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Above is an example of a notification class.  The constructor requires an IFacade object that it uses in the constructor to map notifications to commands using the IFacade object that is passed into the constructor.  You can see how a bigger group of commands can be nicely organized into this class.  Below is an example concrete Facade.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.project
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com.project.controller.notifications.LoginNotifications;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> org.puremvc.as3.patterns.facade.Facade;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> ProjectFacade extends Facade
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> ProjectFacade<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		static <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> getInstance<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span>ProjectFacade
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span>instance<span style="color: #000000;">&#41;</span> instance = <span style="color: #0033ff; font-weight: bold;">new</span> ProjectFacade<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">return</span> instance;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		override <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> initializeController<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;">super</span>.initializeController<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">new</span> LoginNotifications<span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">this</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></pre></div></div>

<p>In the example above we can see the usage example for the notifications class for the login group.  In the override for the initializeController() method, after initializing the controller, a LoginNotifications object is started with a reference to the IFacade instance that is the concrete facade, or simply &#034;this&#034;.  The amount of imports is reduced in the concrete facade, and there are less lines required in the initializeController() method, creating a neater, shorter concrete facade class.</p>
<p>This kind of organization is almost always based on personal preference, this just happens to be mine. =)</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.almerblank.com/2009/11/organizing-puremvc-notifications/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>ActionScript 3 Display List Event Flow</title>
		<link>http://labs.almerblank.com/2009/11/actionscript-3-display-list-event-flow/</link>
		<comments>http://labs.almerblank.com/2009/11/actionscript-3-display-list-event-flow/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 04:26:39 +0000</pubDate>
		<dc:creator>rblank</dc:creator>
				<category><![CDATA[Code & Samples]]></category>
		<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[display list]]></category>
		<category><![CDATA[event flow]]></category>
		<category><![CDATA[EventListener]]></category>

		<guid isPermaLink="false">http://www.rblank.com/?p=459</guid>
		<description><![CDATA[I've <em>*finally*</em> completed and posted a version of my <a href="http://richmediainstitute.com/ondemand/actionscript3events_and_broadcaster" target="_blank"> Unlocking ActionScript 3 Fluency: Events and the Broadcaster</a> workshop to the Rich Media Institute Online. 

I gave this name to the course because I believe (and argue in the course) that events really are the glue that bind everything together, and understanding events is vital to achieving fluency in ActionScript 3. Understanding how to reduce the potential for errors in your code makes you a <em>better</em> coder; understanding how to work with and around events makes you a <em>fluent</em> coder.

Fortunately, events in AS3 are not that hard to work with -- in fact, they are incredibly consistent and pretty darn easy. They do have some pretty key limitations, but there are several ways around them, and my course teaches a CustomEvent and a CustomEvent Broadcaster as two such solutions.

But before we get that far, there is one very most important aspect of working with events in ActionScript 3, a concept that many users of Flash do not understand when walking into my course. This concept of <strong><em>Display List Event Flow</em></strong> can be stated in two simple bullets. 

Events in Flash:
<ul>
<li>are objects</li>
<li>that can travel</li>
</ul>[...]]]></description>
			<content:encoded><![CDATA[<a href="http://www.rblank.com/wp-content/uploads/2009/11/AS3EventTracers.zip"><strong>Download the Flash CS3/AS3/FP9 Source Files for this post</strong></a>

I've <em>*finally*</em> completed and posted a version of my <a href="http://richmediainstitute.com/ondemand/actionscript3events_and_broadcaster">ActionScript 3 Events</a> workshop to the Rich Media Institute Online. I wrote the first full draft of this course almost a year ago, and I first taught it live in Los Angeles in May -- and now I've finally completed a version for online entitled, <em><strong>Unlocking ActionScript 3 Fluency: Events and the Broadcaster</strong></em> (see <a href="http://www.rblank.com/2009/11/02/actionscript-3-display-list-event-flow/#youtubeextract">below for an extended excerpt</a> of that course).

I gave this name to the course because I believe (and argue in the course) that events really are the glue that bind everything together, and understanding events is vital to achieving fluency in ActionScript 3. Understanding how to reduce the potential for errors in your code makes you a <em>better</em> coder; understanding how to work with and around events makes you a <em>fluent</em> coder.

Stated another way: everything in Flash is an object. There are two ways to make your objects communicate:
<ol>
	<li>Direct references: which even your grandmother knows not to use if possible, since direct references create less maintainable, less reusable, and more spaghetti-ish code.</li>
	<li>Events: which are dispatched and heard, and are like butter to work with</li>
</ol>
So, since objects need to communicate to do anything cool or complex, and since events are really the only clean way to have objects communicate (until you get into advanced stuff, like frameworks), well it looks like you need to understand events if you want to do anything fun, cool or sexy!

Fortunately, events in AS3 are not that hard to work with -- in fact, they are incredibly consistent and pretty darn easy. They do have some pretty key limitations, but there are several ways around them, and my course teaches a CustomEvent and a CustomEvent Broadcaster as two such solutions.

But before we get that far, there is one very most important aspect of working with events in ActionScript 3, a concept that many users of Flash do not understand when walking into my course. This concept of <strong><em>Display List Event Flow</em></strong> can be stated in two simple bullets.

Events in Flash:
<ul>
	<li>are objects</li>
	<li>that can travel</li>
</ul>
Unlike in real life, where an 'event' is likely not tangible (try touching a party), events in Flash are as real and tangible as anything else, such as a MovieClip. Events have properties and methods, and they exist and occupy memory -- just like any other type of object. And these events have a lifespan -- they are born, they travel (or 'flow') and they die.

Because Flash is an inherently visual platform, it is not surprising that the native event flow in Flash is inherently tied to the Display List -- the tree formed by the relationships of the display objects on our stage -- which can change each frame (since the MovieClip that's on my stage on this frame, might not be there on the next frame). To help you visualize what we're talking about when we say 'display list', here is a simple example display list:
<a href="http://www.rblank.com/wp-content/uploads/2009/11/displayList.png"><img class="alignleft size-full wp-image-460" title="displayList" src="http://www.rblank.com/wp-content/uploads/2009/11/displayList.png" alt="displayList" width="429" height="302" /></a>

Many events in AS3 (especially MouseEvents and KeyboardEvents, as well as any bubbling events of our own that we might dispatch in our movies) travel around the display list, in three phases:
<ol>
	<li><strong>the capture phase</strong>: the event is heard down from the stage to the 'target' or source of the event</li>
	<li><strong>the target phase</strong>: the event is heard on the target itself</li>
	<li><strong>the bubbling phase</strong>: the event is heard back up the display list, from the target to the stage</li>
</ol>
So, looking back at our sample display list, let's say the user clicks on sub1a, whose full path is: <em>stage.mc1.mc1_a.sub1a</em>. In that case, the event (in our case, a MouseEvent) would be created and dispatched first on the stage, and then down to the <em>target</em> (or source, in our case, sub1a) of the event, in the <em><strong>capture phase</strong></em>.
<a href="http://www.rblank.com/wp-content/uploads/2009/11/capture.png"><img class="alignleft size-full wp-image-463" title="capture" src="http://www.rblank.com/wp-content/uploads/2009/11/capture.png" alt="capture" width="435" height="304" /></a>

The event (again, in our case, a MouseEvent) is heard on the target (again, in our case, sub1a), in the <em><strong>target phase</strong></em>.
<a href="http://www.rblank.com/wp-content/uploads/2009/11/target.png"><img class="alignleft size-full wp-image-464" title="target" src="http://www.rblank.com/wp-content/uploads/2009/11/target.png" alt="target" width="429" height="300" /></a>

And finally, the event will be dispatched up the display list, from the target, to the stage, in the <em><strong>bubbling phase</strong></em>.
<a href="http://www.rblank.com/wp-content/uploads/2009/11/bubble.png"><img class="alignleft size-full wp-image-465" title="bubble" src="http://www.rblank.com/wp-content/uploads/2009/11/bubble.png" alt="bubble" width="428" height="300" /></a>

So, the full flow -- the complete lifespan of an event in the display list -- looks something like this:
<a href="http://www.rblank.com/wp-content/uploads/2009/11/fullFlow.png"><img class="alignleft size-full wp-image-467" title="fullFlow" src="http://www.rblank.com/wp-content/uploads/2009/11/fullFlow.png" alt="fullFlow" width="434" height="359" /></a>

So, to be clear, in this very, very simple example of the user clicking on sub1a, that MouseEvent can be heard in <strong>four</strong> separate locations, at <strong>seven</strong> separate occasions (3 in capture phase, 1 in target phase, and three again in the bubbles phase).

<strong>Remember!</strong> The display list event flow not only tells us which parts of the display list will hear an event, but also which parts <strong>CAN NOT</strong> hear events (this limitation gets to why it can be so difficult, with the native AS3 event flow, to have different objects hear events from different parts of your movies).

By default, when you write <em>addEventListener</em> in AS3, you will listen for events in the target and bubbles phases. If you use the 'useCapture' property of addEventListener, you can listen for events in the capture phase instead, as in:
<pre class="actionscript">addEventListener <span style="color: #66cc66;">(</span> MouseEvent.<span style="color: #006600;">CLICK</span> , _onClick , <span style="color: #000000; font-weight: bold;">true</span> <span style="color: #66cc66;">)</span> ;</pre>
Why would you ever want to hear an event in the capture phase? Well, honestly, it's rare, but we had to use it today at work to suppress keyboard input from being heard in parts of our movie in certain specific instances, so there are times when it can come in handy. But it's still useful to know about, because 'capture' makes 'bubbling' make a whole lot more sense!

I've prepared <a href="http://www.rblank.com/wp-content/uploads/2009/11/AS3EventTracers.zip">two Flash CS3/AS3/FP9 samples (including source)</a> that hopefully help demonstrate the concept. The first is intended to provide visual indication of the actual event flow, including the phases, and which branches of the display list can hear an event. The second provides a more accurate estimation of the timing of the event flow -- which lasts milliseconds -- by tracing messages to a textarea. I'm embedding the visual one at 50% so you can get a sense of it here.

<strong>Visual Display List Event Flow Tracer</strong>
<object id="captureTargetAndBubble" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="392" height="308" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="align" value="middle" /><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="false" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><param name="src" value="http://www.rblank.com/wp-content/uploads/2009/11/captureTargetAndBubble.swf" /><param name="name" value="captureTargetAndBubble" /><param name="allowfullscreen" value="false" /><embed id="captureTargetAndBubble" type="application/x-shockwave-flash" width="392" height="308" src="http://www.rblank.com/wp-content/uploads/2009/11/captureTargetAndBubble.swf" name="captureTargetAndBubble" bgcolor="#ffffff" quality="high" allowfullscreen="false" allowscriptaccess="sameDomain" align="middle"></embed></object>

<a name="youtubeextract"></a>
<strong>Preview from R's AS3 Events Course</strong>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/C99TchxTSF0&amp;hl=en&amp;fs=1&amp;" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/C99TchxTSF0&amp;hl=en&amp;fs=1&amp;" allowscriptaccess="always" allowfullscreen="true"></embed></object>

Share and enjoy!

-r]]></content:encoded>
			<wfw:commentRss>http://labs.almerblank.com/2009/11/actionscript-3-display-list-event-flow/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Moving rotated objects, the getBounds() bug, and how to fix it : Part One</title>
		<link>http://labs.almerblank.com/2009/11/moving-rotated-objects-the-getbounds-bug-and-how-to-fix-it-part-one/</link>
		<comments>http://labs.almerblank.com/2009/11/moving-rotated-objects-the-getbounds-bug-and-how-to-fix-it-part-one/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 03:07:08 +0000</pubDate>
		<dc:creator>Omar Gonzalez</dc:creator>
				<category><![CDATA[Code & Samples]]></category>
		<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[code examples]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[getBounds]]></category>
		<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://labs.almerblank.com/?p=997</guid>
		<description><![CDATA[Recently I was working on some bug fixes for a client project when I came across a bug with getBounds().  The issue that needed to be fixed had to do with an application that has an alignment feature.  Originally I had coded the alignment command to examine the x/y coordinates and the dimensions of the [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I was working on some bug fixes for a client project when I came across a bug with getBounds().  The issue that needed to be fixed had to do with an application that has an alignment feature.  Originally I had coded the alignment command to examine the x/y coordinates and the dimensions of the objects in order to figure out which coordinates to move the items.  This approach works correctly as long as the objects being aligned do not have any rotation set.</p>
<p>Throwing rotation into the mix no longer guarantees that the registration point is the top left coordinate of the item being aligned, which renders the first approach incorrect.  The first part of this blog post will go into the getBounds() method, what the bug is, and how to get the accurate bounds.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="550" height="400" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://labs.almerblank.com/wp-content/uploads/2009/11/getBoundsBug.swf" /><embed type="application/x-shockwave-flash" width="550" height="400" src="http://labs.almerblank.com/wp-content/uploads/2009/11/getBoundsBug.swf"></embed></object></p>
<p>This SWF above demonstrates the issues with the getBounds() method.  On the stage is a MovieClip instance with a triangle shape in it, the MovieClip&#039;s rotation is set to 0 at start up.  Pressing the &#034;Toggle MC Border&#034; button draws a 1 pixel red line around the border of the MovieClip that has the triangle.  Pressing the &#034;Toggle Unrotated getBounds()&#034; displays the rectangle returned by the getBounds() method before the MovieClip has been rotated.  Before explaining the last two buttons, lets shift focus to the Rotation input at the top.  The first two buttons show the border and the unrotated bounds border.  The Rotation input lets us modify the rotation of the MovieClip.  If the object is rotated to 45 degrees by typing in 45 and clicking the &#034;Set Rotation&#034; button the first two buttons still perform the same function.  Except that now that the MovieClip is rotated the unrotated bounds rectangle now longer contains the shape inside of it.  If you turn off both the MC Border and the Unrotated getBounds(), and click on &#034;Toggle Rotated getBounds()&#034;, you will see that the red border does not accurately draw to the expected size.  The top and right borders are further away from the right edge, which should meet at the top right of the shape.  If you click on &#034;Toggle MC Border&#034;, you can visually see why.  The getBounds() method calculates the bounds Rectangle object by using the actual borders of the MovieClip, instead of actual graphical space that the MovieClip occupies.  If you now click on the fourth button, &#034;Toggle getAccurateBounds()&#034;, you will see the blue rectangle drawn to the expected shape.  If the MovieClip&#039;s border is still on, the blue rectangle will be the same size as the red rectangle as seen in the screenshot below.</p>
<p><img class="alignnone size-full wp-image-1050" title="Screen shot 2009-11-02 at 6.32.32 PM" src="http://labs.almerblank.com/wp-content/uploads/2009/11/Screen-shot-2009-11-02-at-6.32.32-PM.png" alt="Screen shot 2009-11-02 at 6.32.32 PM" width="547" height="397" /></p>
<p>This is because the red 1 pixel border showing the MovieClip&#039;s border is taken into account, accurately, by the getAccurateBounds() method that I wrote.  That results in the bounds rectangle to do the same thing that getBounds() does.  If you press &#034;Toggle MC Border&#034; and turn off the MovieClip&#039;s border, and then turn the accurate border off and back on, you will see the difference in how the new actual bounds is actually wrapping the rotated triangle accurately.</p>
<p><img class="alignnone size-full wp-image-1050" title="Screen shot 2009-11-02 at 6.32.16 PM" src="http://labs.almerblank.com/wp-content/uploads/2009/11/Screen-shot-2009-11-02-at-6.32.16-PM.png" alt="Screen shot 2009-11-02 at 6.32.16 PM" width="547" height="397" /></p>
<p>Below is the _getAccurateBounds() method that is calculating the blue rectangle we see above.  This method demonstrates the technique to find the accurate bounds, but would likely need to be slightly altered to fit within real implementations depending on the actual architecture of the application its going to be used in because of the fact that it currently requires me to remove it from the stage to draw it independently of any other display objects.  It can probably also be accomplished by looping through the children of the clip&#039;s parent to turn off any visible items and turn them back on after the drawing process, but for the sake of simplicity in this example I will simply attach it to my placeholder bounds clip and then put it back.</p>
<p>Anyhow, the way that I accomplished this was by isolating the MovieClip that I want an accurate bounds Rectangle object from.  In my example I place it in a Sprite called boundsClip.  Next I set up a ColorTransform object with a color of blue (0&#215;0000FF).  This ColorTransform object is used in the next step, where I create a BitmapData object sized to the clip&#039;s parent&#039;s dimensions, in this case the SWF&#039;s stage.  I then draw the boundsClip into the BitmapData object.  That is why I place the clip into a placeholder Sprite, so it can be drawn into the BitmapData in the correct position using its x,y coordinates.  In the draw() method, I use the colorTransform object to tint the bitmap blue.  This is crucial to the last step.  Before returning the accurate bounds, I place the clip back onto the stage.  And finally, I get the accurate bounds of the clip by using the getColorBoundsRect() method on the BitmapData object.  In the example application above I use this Rectangle object to accurately draw the blue rectangle, which shows the accurate bounds.</p>
<p>In my next post I will go into how to use the bounds rectangle to actually move the objects to a desired position.</p>
<p>You can download the FLA for the example application here: <a href="http://labs.almerblank.com/wp-content/uploads/2009/11/getBoundsBug.fla.zip">getBoundsBug.fla</a></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #339966; font-weight: bold;">function</span> _getAccurateBounds<span style="color: #000000;">&#40;</span> clip<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;">Rectangle</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #009900;">// Make a placeholder clip to draw the clip isolated from anything else</span>
        <span style="color: #009900;">// that is on stage.</span>
        <span style="color: #6699cc; font-weight: bold;">var</span> boundsClip<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>;
            boundsClip.<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span> clip <span style="color: #000000;">&#41;</span>;
&nbsp;
        <span style="color: #009900;">// Make a ColorTransform object to tint the bitmap that is going to be</span>
        <span style="color: #009900;">// drawn based on the clip passed into _getAccurateBounds()</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> boundsColorTint<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = 0x0000FF;
	<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">colorTransform</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">ColorTransform</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">ColorTransform</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #004993;">colorTransform</span>.<span style="color: #004993;">color</span> = boundsColorTint;
&nbsp;
	<span style="color: #009900;">// Draw a BitmapData object with the clip passed into _getAccurateBounds()</span>
        <span style="color: #009900;">// and tint the BitmapData to a color, I use blue.</span>
        <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">bitmapData</span><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;">stage</span>.<span style="color: #004993;">stageWidth</span>,
                                                    <span style="color: #004993;">stage</span>.<span style="color: #004993;">stageHeight</span>,
                                                    <span style="color: #0033ff; font-weight: bold;">true</span>,
                                                    0xFF000000 <span style="color: #000000;">&#41;</span>;
            <span style="color: #004993;">bitmapData</span>.<span style="color: #004993;">draw</span><span style="color: #000000;">&#40;</span> boundsClip, <span style="color: #0033ff; font-weight: bold;">null</span>, <span style="color: #004993;">colorTransform</span> <span style="color: #000000;">&#41;</span>;
&nbsp;
        <span style="color: #009900;">// Place the mc back onto the stage after drawing it.</span>
        <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span> clip <span style="color: #000000;">&#41;</span>;
&nbsp;
        <span style="color: #009900;">// Return the Rectangle object from the getColorBoundsRect() method on</span>
        <span style="color: #009900;">// the BitmapData object.  This Rectangle object will contain the</span>
        <span style="color: #009900;">// correct bounds of the item you want the bounds of rotated or not.</span>
        <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #004993;">bitmapData</span>.<span style="color: #004993;">getColorBoundsRect</span><span style="color: #000000;">&#40;</span> 0xFFFFFF, boundsColorTint, <span style="color: #0033ff; font-weight: bold;">false</span> <span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://labs.almerblank.com/2009/11/moving-rotated-objects-the-getbounds-bug-and-how-to-fix-it-part-one/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash CS4/AS3 SnapshotRectangle class</title>
		<link>http://labs.almerblank.com/2009/11/flash-cs4as3-snapshotrectangle-class/</link>
		<comments>http://labs.almerblank.com/2009/11/flash-cs4as3-snapshotrectangle-class/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 02:46:03 +0000</pubDate>
		<dc:creator>rblank</dc:creator>
				<category><![CDATA[Code & Samples]]></category>
		<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[as3corelib]]></category>
		<category><![CDATA[bitmap]]></category>
		<category><![CDATA[bitmapdata]]></category>
		<category><![CDATA[filereference]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.rblank.com/?p=442</guid>
		<description><![CDATA[A few nights ago, as I was at my folks house in New Jersey, and had a touch of the jet lag. So, checking Facebook, and one of my friends, Bram, had posted a challenge to his wall. He was looking for a Flash guy to create a Flash app to:

<ul>
<li> load any Flash video from your hard-drive</li>
<li> select the frame/location</li>
<li> drag-resize/reposition a marquee selection</li>
<li> save a JPG of the selected area to your hard-drive</li>
</ul>

I realized that this was possible in Flash Player 10 (no AIR required) because of the changes to the FileReference API[...]]]></description>
			<content:encoded><![CDATA[<strong><a href="http://www.rblank.com/wp-content/uploads/2009/11/SnapshotRectangle.zip">Source files for this posting&gt;&gt;</a></strong>

<strong>Try me here!</strong>
<object id="snapper" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="200" height="150" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="align" value="middle" /><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="false" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><param name="src" value="http://www.rblank.com/wp-content/uploads/2009/11/snapper.swf" /><param name="name" value="snapper" /><param name="allowfullscreen" value="false" /><embed id="snapper" type="application/x-shockwave-flash" width="200" height="150" src="http://www.rblank.com/wp-content/uploads/2009/11/snapper.swf" name="snapper" bgcolor="#ffffff" quality="high" allowfullscreen="false" allowscriptaccess="sameDomain" align="middle"></embed></object>

A few nights ago, as I was at my folks' house in New Jersey, and had a touch of the jet lag. So, checking Facebook, and one of my friends, Bram, had posted a challenge to his wall. He was looking for a Flash guy to create a Flash app to:
<ul>
	<li> load any Flash video from your hard-drive</li>
	<li> select the frame/location</li>
	<li> drag-resize/reposition a marquee selection</li>
	<li> save a JPG of the selected area to your hard-drive</li>
</ul>
I realized that this was possible in Flash Player 10 (no AIR required) because of the changes to the FileReference API (summarized by Lee Brimelow <a href="http://theflashblog.com/?p=423">here</a>), and that I actually already had all the code for it across several separate project files for courses I teach at the <a href="http://www.richmediainstitute.com/ondemand/practicalas3">Rich Media Institute</a>. The one limitation is that, with Flash video, you can only seek to keyframes (so, with this video snapshot tool, you can pause it at any time, but if you want to seek, you can only seek to keyframes), but Bram signed off on that proviso and so, in about two hours, I combined all the code snippets to make it work and got it to Bram before I went to bed.

The next day, I realized it would actually be more useful if I encapsulated all of the code that handles the snapshot to a single, reusable class file / library symbol. So that's what I did. And I'm attaching the results <a href="http://www.rblank.com/wp-content/uploads/2009/11/SnapshotRectangle.zip">here</a>. Full disclaimer: This was just a goof and is not fool-proof code, but does demonstrate the concept nicely.

So, what's included:
<ul>
	<li><strong>snapper.fla</strong> which includes the SnapshotRectangle MovieClip (on top of a sample image of my gorgeous golden, Lelia)</li>
	<li><strong>com.rblank.snapper.SnapshotRectangle.as</strong>, to which the SnapshotRectangle MovieClip symbol is linked, and which contains all of the custom code I've written for this sample</li>
	<li><strong><a href="http://code.google.com/p/as3corelib/">ActionScript 3 Core Libraries</a></strong>, created by the uber-scripters at Adobe, which I use here for JPEGEncoding (not inherent to the Flash Player 10 AS3 API). I'm including it in the download so it will work 'out-of-the-box' but you should of course download and use the most recent from their repository site</li>
</ul>
As you can see in the sample file (embedded and attached) the SnapshotRectangle has a:
<ul>
	<li>Textfield instance, <em>tf_dims</em>, to display dimensions of the image that will be created</li>
	<li>A MovieClip instance, named <em>bg</em>, that visually indicates the size of the image that will be created</li>
	<li>A MovieClip instance, named <em>nub</em>, that will be used to resize the snapshot area</li>
	<li>A NumericStepper instance, named <em>ns_quality</em>, that will be used to determine JPG quality</li>
	<li>A Button instance, named <em>btn_snap</em>, that will be the trigger for saving the JPG</li>
</ul>
The code is fully commented, so check it out. But essentially, you:
<ol>
	<li>Create a BitmapData object and draw into it</li>
	<li>Encode the BitmapData into a ByteArray, using the <em>JPGEncoder</em> class</li>
	<li>Save the ByteArray (representing a JPG) to the user's computer, using the <em>FileReference</em> class</li>
</ol>
That's the pseudo-code. The actionscript is:
<pre class="actionscript">
<ol>
	<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">//create a BitmapData instance, sized to match the width and height of the bg MovieClip instance</span></div></li>
	<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">_bitmapData =<span style="color: #000000; font-weight: bold;">new</span> BitmapData <span style="color: #66cc66;">(</span> bg.<span style="color: #0066CC;">width</span> , bg.<span style="color: #0066CC;">height</span> <span style="color: #66cc66;">)</span>;</div></li>
	<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">//draw the entire stage into the BitmapData instance, clipping by the _matrix</span></div></li>
	<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">_bitmapData.<span style="color: #006600;">draw</span><span style="color: #66cc66;">(</span> <span style="color: #0066CC;">stage</span> <span style="color: #66cc66;">)</span>;</div></li>
	<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">//create a new JPGEncoder instance (an AS3CoreLib class)</span></div></li>
	<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">//and pass in the current value of the ns_quality NumericStepper instance as the JPG quality</span></div></li>
	<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">_jpg= <span style="color: #000000; font-weight: bold;">new</span> JPGEncoder<span style="color: #66cc66;">(</span>ns_quality.<span style="color: #006600;">value</span><span style="color: #66cc66;">)</span>;</div></li>
	<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">//encode the _bitmapData into JPG data, stored in the _byteArray</span></div></li>
	<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">_byteArray=_jpg.<span style="color: #006600;">encode</span><span style="color: #66cc66;">(</span>_bitmapData<span style="color: #66cc66;">)</span>;</div></li>
	<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">//create the new FileReference instance through which to save the JPG data to the user's machine</span></div></li>
	<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">_fileRef_save = <span style="color: #000000; font-weight: bold;">new</span> FileReference <span style="color: #66cc66;">(</span> <span style="color: #66cc66;">)</span>;</div></li>
	<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">//save the _byteArray to the users computer, with a default name of 'RBlankSnapshot.jpg',</span></div></li>
	<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">//which the user will have a chance to rename before saving</span></div></li>
	<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">_fileRef_save.<span style="color: #006600;">save</span><span style="color: #66cc66;">(</span> _byteArray , <span style="color: #ff0000;">"RBlankSnapshot.jpg"</span> <span style="color: #66cc66;">)</span>;</div></li>
</ol>
</pre>
You'll note that in the actual code, since this single MovieClip encapsulates all the drawing logic (meaning, it has no idea which specific display objects will actually be visible in the rendered image), so you have to hide this MovieClip while drawing into the bitmap data (otherwise, this SnapshotRectangle GUI will be in the JPG).

Share and enjoy!

-r

<strong><a href="http://www.rblank.com/wp-content/uploads/2009/11/SnapshotRectangle.zip">Source files for this posting&gt;&gt;</a></strong>]]></content:encoded>
			<wfw:commentRss>http://labs.almerblank.com/2009/11/flash-cs4as3-snapshotrectangle-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
