<?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>The efnx code blog. &#187; AS3</title>
	<atom:link href="http://efnx.com/topics/as3/feed/" rel="self" type="application/rss+xml" />
	<link>http://efnx.com</link>
	<description>code. blog.</description>
	<lastBuildDate>Sat, 03 Jul 2010 18:02:12 +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>Game Progress 1</title>
		<link>http://efnx.com/game-progress-1/</link>
		<comments>http://efnx.com/game-progress-1/#comments</comments>
		<pubDate>Sat, 11 Jul 2009 16:41:08 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[machinista]]></category>

		<guid isPermaLink="false">http://blog.efnx.com/?p=207</guid>
		<description><![CDATA[I&#8217;ve been working on another game lately, it&#8217;s called Machinista &#8211; it&#8217;s a game where you control motors in a 2D physics simulation. The entire thing is built around Box2D, which is a great physics system. Last night I worked on using Brownian Bridge fractals for explosions &#8211; check it out! Use keys W, A, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on another game lately, it&#8217;s called Machinista &#8211; it&#8217;s a game where you control motors in a 2D physics simulation. The entire thing is built around Box2D, which is a great physics system. Last night I worked on using Brownian Bridge fractals for explosions &#8211; <a href="http://slaughterballoon.com/Machinista">check it out</a>! Use keys W, A, S, D and shift+click to control the tank and make explosions, respectively. </p>
]]></content:encoded>
			<wfw:commentRss>http://efnx.com/game-progress-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>AS3 &#8211; Drawing Circles With IGraphicsData</title>
		<link>http://efnx.com/as3-drawing-circles-with-igraphicsdata/</link>
		<comments>http://efnx.com/as3-drawing-circles-with-igraphicsdata/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 16:20:06 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[fp10]]></category>
		<category><![CDATA[graphics]]></category>

		<guid isPermaLink="false">http://blog.efnx.com/?p=195</guid>
		<description><![CDATA[Drawing circles with Flash 10's new IGraphicsData API is easy. Here is a function that will populate a GraphicsPath object with points and commands for drawing a circle approximation.]]></description>
			<content:encoded><![CDATA[<p>Lately I&#8217;ve been working on a game  with some of my free time. It&#8217;s a slow process made a little bit faster through the use of <a href="http://www.box2d.org/">Box2D</a>, which is a great 2D physics lib. In my game the user controls a robot that wheels around and smashes other robots. I decided that I would write some functions for drawing geometric primitives, and that I would draw everything into one sprite, or two, depending on how many layers I&#8217;d need. In an attempt to squeeze out some more frames per second I switched these functions over to use flash 10+ IGraphicsData API. It&#8217;s interesting, to say the least. When using the new API we loose the ability to easily draw rectangles and circles. We can still use familiar functions like moveTo, lineTo and curveTo &#8211; so I&#8217;ve written a function that draws a circle using these. It uses some fun almost calculus [parametrization of a curve in so many points] minus any derivatives or integrals. Is that still calculus? Meh. Here&#8217;s what happens:</p>
<p>We create a new GraphicsStroke [the line], a new GraphicsSolidFill [the fill], a new GraphicsPath [the path] and an IGraphicsData Vector to store them all in.</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">var</span> _stroke :GraphicsStroke &nbsp; &nbsp; &nbsp; &nbsp; = <span style="color: #000000; font-weight: bold;">new</span> GraphicsStroke<span style="color: #66cc66;">&#40;</span>1<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; _stroke.<span style="color: #006600;">fill</span> = <span style="color: #000000; font-weight: bold;">new</span> GraphicsSolidFill<span style="color: #66cc66;">&#40;</span>0xFF00FF, 1<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> _fill &nbsp; :GraphicsSolidFill &nbsp;&nbsp; &nbsp; = <span style="color: #000000; font-weight: bold;">new</span> GraphicsSolidFill<span style="color: #66cc66;">&#40;</span>0xF0F0F0, 1<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> _path &nbsp; :GraphicsPath &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = <span style="color: #000000; font-weight: bold;">new</span> GraphicsPath<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> _graph&nbsp; :Vector.<span style="color: #66cc66;">&lt;</span>IGraphicsData<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>IGraphicsData<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></div></div>
<p>Now what we&#8217;ll need to do is populate the path with some commands and some points. To do this, we can use GraphicsPath&#8217;s familiar functions moveTo, lineTo and curveTo. These functions will fill path.command and path.data with commands and data, respectively. The parameters to each command are stored in the data array, where as a number representing each command are stored in the command array. You can read more about it <a href="http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS749610B4-4709-4f75-BBA0-650BF52623CA.html">here</a>. So here is a function that will fill your path with points and commands to form a circle.</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> r_addCircle<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">_x</span>:<span style="color: #0066CC;">Number</span>, <span style="color: #0066CC;">_y</span>:<span style="color: #0066CC;">Number</span>, r:<span style="color: #0066CC;">Number</span>, path:GraphicsPath, numPoints:<span style="color: #0066CC;">int</span> = 8<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> twoPI:<span style="color: #0066CC;">Number</span> = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">2</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> curve:<span style="color: #0066CC;">Number</span> = 1 + 1<span style="color: #66cc66;">/</span><span style="color: #66cc66;">&#40;</span>numPoints<span style="color: #66cc66;">*</span>1.75<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; path.<span style="color: #0066CC;">moveTo</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">_x</span> + r<span style="color: #66cc66;">&#41;</span>, <span style="color: #0066CC;">_y</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">1</span>; i <span style="color: #66cc66;">&lt;</span>= numPoints; i++<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> th&nbsp; :<span style="color: #0066CC;">Number</span> = twoPI <span style="color: #66cc66;">*</span> i<span style="color: #66cc66;">/</span>numPoints;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> thm :<span style="color: #0066CC;">Number</span> = twoPI <span style="color: #66cc66;">*</span> <span style="color: #66cc66;">&#40;</span>i-0.5<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">/</span>numPoints;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> px:<span style="color: #0066CC;">Number</span> = <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">_x</span> + r <span style="color: #66cc66;">*</span> <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">cos</span><span style="color: #66cc66;">&#40;</span>th<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> py:<span style="color: #0066CC;">Number</span> = <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">_y</span> + r <span style="color: #66cc66;">*</span> <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span>th<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> hx:<span style="color: #0066CC;">Number</span> = <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">_x</span> + r <span style="color: #66cc66;">*</span> curve <span style="color: #66cc66;">*</span> <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">cos</span><span style="color: #66cc66;">&#40;</span>thm<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> hy:<span style="color: #0066CC;">Number</span> = <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">_y</span> + r <span style="color: #66cc66;">*</span> curve <span style="color: #66cc66;">*</span> <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span>thm<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; path.<span style="color: #0066CC;">curveTo</span><span style="color: #66cc66;">&#40;</span>hx, hy, px, py<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>In this function _x and _y represent the center of the circle, r is the radius and path is your GraphicsPath. numPoints refers to the number of points you&#8217;d like to use for approximating your circle. The more points, the more &#8220;perfect&#8221; the circle will look, although more points will tax your frameRate. We can get a pretty nice looking circle with 8 points. 4 looks a little boxy, but around 8 is nice. Experiment. Here&#8217;s the next step &#8211; we&#8217;ll add the points to our path and then add the stroke, fill and path to our Vector and then have a sprite draw our graphics data:</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">r_addCircle<span style="color: #66cc66;">&#40;</span>50, 50, 50, _path, 2<span style="color: #66cc66;">&#41;</span>;<br />
r_addCircle<span style="color: #66cc66;">&#40;</span>150, 50, 50, _path, 4<span style="color: #66cc66;">&#41;</span>;<br />
r_addCircle<span style="color: #66cc66;">&#40;</span>250, 50, 50, _path, 6<span style="color: #66cc66;">&#41;</span>;<br />
r_addCircle<span style="color: #66cc66;">&#40;</span>350, 50, 50, _path, 8<span style="color: #66cc66;">&#41;</span>;<br />
<br />
_graph.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>_stroke, _fill, _path<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
<span style="color: #000000; font-weight: bold;">var</span> sprite:Sprite = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
addChild<span style="color: #66cc66;">&#40;</span>sprite<span style="color: #66cc66;">&#41;</span>; &nbsp; <br />
<br />
sprite.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawGraphicsData</span><span style="color: #66cc66;">&#40;</span>_graph<span style="color: #66cc66;">&#41;</span>;</div></div>
<p>This should draw 4 circle approximations of different resolution. This is what it looks like:<br />
<div id="attachment_197" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.efnx.com/wp-content/uploads/2009/06/Picture-1.png" rel="lightbox"><img src="http://blog.efnx.com/wp-content/uploads/2009/06/Picture-1-300x206.png" alt="approximated circles" title="approximated circles" width="300" height="206" class="size-medium wp-image-197" /></a><p class="wp-caption-text">approximated circles</p></div></p>
<p>You can see that as n [numPoints] increases, the closer to an actual circle our object becomes. I hope this entry helps some of you out there save a little time.</p>
]]></content:encoded>
			<wfw:commentRss>http://efnx.com/as3-drawing-circles-with-igraphicsdata/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Flash Actionscript 3 Waveform Generation Class</title>
		<link>http://efnx.com/flash-actionscript-3-waveform-generation-class/</link>
		<comments>http://efnx.com/flash-actionscript-3-waveform-generation-class/#comments</comments>
		<pubDate>Fri, 24 Oct 2008 22:45:35 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Music]]></category>
		<category><![CDATA[Sound]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[Audio]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[Wave]]></category>
		<category><![CDATA[waveform]]></category>

		<guid isPermaLink="false">http://blog.efnx.com/?p=90</guid>
		<description><![CDATA[In my last post, Plotting a Sound Wave in Flash AS3 I detailed a method to use when displaying audio data. The method itself works great, but due to Flash&#8217;s frame-based code execution and event processing the user looses input capabilities while the flash player chugs through millions of numbers adding, rounding and comparing. In [...]]]></description>
			<content:encoded><![CDATA[<p>In my last post, <a href="http://blog.efnx.com/?p=75">Plotting a Sound Wave in Flash AS3</a> I detailed a method to use when displaying audio data. The method itself works great, but due to Flash&#8217;s frame-based code execution and event processing the user looses input capabilities while the flash player chugs through millions of numbers adding, rounding and comparing. In order to make displaying an audio waveform easier on both the programmer and the user I wrote a class that analyzes a Sound object progressively, and dispatches a special event containing the analyzed data. The class will construct a left and right channel Vector, each containing one data point [a number between 0 and 1] for a given number of <a href="http://en.wikipedia.org/wiki/Window_function">windows</a>, between two positions in the sound. The left and right position are measured in samples and two types of analyzation are offered. Here is a demo of the class in action:<br />
<div class="wp-caption aligncenter" style="width: 578px"><a href="http://efnx.com/lab/WavePlotter/"><img alt="Screen Capture of Waveform Plot" src="http://efnx.com/lab/WavePlotter/waveform_screen.png" title="Waveform Plot" width="568" height="237" /></a><p class="wp-caption-text">Screen Capture of Waveform Plot</p></div><br />
The calculated data can be reached incrementally through the WaveformEvent object which is dispatched every frame, or at the end of all analyzation in the Waveform object&#8217;s leftChannel and rightChannel properties. The details are listed in the documentation below.</p>
<p>Thanks to the <a href="http://summitprojectsflashblog.wordpress.com/2008/07/31/wave-theory-in-actionscript-3/">Summit Projects Flash Blog</a> and <a href="http://www.bytearray.org/?p=329">Thibault Imbert at ByteArray</a> for their posts on the different techniques that went into my class.</p>
<p><a name="source"><strong>Source</strong></a><br />
Here is the source for my TextMate project: <a href="http://efnx.com/lab/WavePlotter/src/WavePlotter_Main_081024.src.tar.gz">Sources</a><br />
Documentation: <a href="http://efnx.com/docs/efnx/sound/Waveform.html">class</a> and <a href="http://efnx.com/docs/efnx/events/WaveformEvent.html">event</a></p>
<p>And here is a Flex version (made in windows): // Thanks dem!<br />
<a href='http://blog.efnx.com/wp-content/uploads/2009/11/WavePlotter_Main.zip'>Sources (Flex version)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://efnx.com/flash-actionscript-3-waveform-generation-class/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>Plotting a Sound Wave in Flash AS3</title>
		<link>http://efnx.com/plotting-a-sound-wave-in-flash-as3/</link>
		<comments>http://efnx.com/plotting-a-sound-wave-in-flash-as3/#comments</comments>
		<pubDate>Fri, 26 Sep 2008 09:24:59 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Music]]></category>
		<category><![CDATA[Sound]]></category>
		<category><![CDATA[data points]]></category>
		<category><![CDATA[plotting]]></category>
		<category><![CDATA[waveform]]></category>

		<guid isPermaLink="false">http://blog.efnx.com/?p=75</guid>
		<description><![CDATA[I&#8217;ve always been really into wave editors. I used to make songs in Amadeus by piecing together samples from other songs. Tedious but very rewarding. In a post I made not a long time ago I detailed a little Theremin project which included some wave data visualization. In this post I&#8221;ll be going further into [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve always been really into wave editors. I used to make songs in <a href="http://www.hairersoft.com/Amadeus.html">Amadeus</a> by piecing together samples from other songs. Tedious but very rewarding. In a post I made not a long time ago I detailed a little Theremin project which included some wave data visualization. In this post I&#8221;ll be going further into detail about plotting sound data. </p>
<p>Digital audio in it&#8217;s rawest form [PCM wave data] is a long list of numbers from 1 to -1, which represent the sound&#8217;s amplitude. Another way of thinking about this is that each number represents your speaker&#8217;s distance away from it&#8217;s rest position. At 1 the speaker is fully extended, blowing out your ears and scaring your cats, while at -1 it is fully retracted, blowing out your ears and scaring your cats. To make a meaningful visual out of this we just set up a graph where time is plotted on the horizontal axis and amplitude on the vertical. So at a really high resolution, that might look like this:<br />
<a href="http://ocw.mit.edu/ans7870/SP/SP.764/imagegallery/lab5/images/3.jpg" rel="lightbox" title="80's!"><img src="http://ocw.mit.edu/ans7870/SP/SP.764/imagegallery/lab5/images/3.jpg" width="100" height="100" alt="80's Oscilloscope" /></a><br />
Okay, maybe it would look like that if you were living in the 80&#8217;s. Or if you were really into oscilloscopes. In reality with most popular songs being two to five minutes long, we&#8217;d be looking at HUGE graphs. One three minute song sampled at 44.1kHz/s comes out to be eight million samples per channel. Per channel. Since most modern music is in stereo, we&#8217;re looking at two graphs now. So how do we compress this data and view it in a meaningful way? We cheat a little. We kinda scrap the whole graph/function thing. Well kinda. Let&#8217;s say you have a window 1000 pixels wide and a sound 3 minutes long. We have to compress enough samples together in order to represent them using each pixel [about 7,938 samples per pixel]. Averaging doesn&#8217;t work because with values oscillating between -1 and 1 the mean is usually zero. We could take one sample every so often to represent an entire chunk and plot that, but that&#8217;s just resampling at a much lower resolution, which results in aliasing and all sorts of bogus stuff. Take this video for instance:<br />
<object width="464" height="392"><param name="movie" value="http://embed.break.com/Mjk1OTQ4"></param><param name="allowScriptAccess" value="never"></param><embed src="http://embed.break.com/Mjk1OTQ4" type="application/x-shockwave-flash" allowScriptAccess=always width="464" height="392"></embed></object></p>
<p>Just instead of helicopter blades not moving, it&#8217;ll be your data points. No, instead what we do is we scan every single sample and pick out the largest and the smallest numbers from the chunk, which in our case means running through every 7,938 samples and picking the biggest and smallest ones. Then we plot them on top of each other, maybe with a line connecting them. Flash gets a little slow working with lists and arrays this big, but I&#8217;m sure we&#8217;ll figure out some neat tricks to get this stuff working fast. That said, here&#8217;s a little demo. If you can figure out the song I&#8217;ll give you a million bucks. [Let it chug for a while, Flash is a slow beast]:<br />
<div id="attachment_77" class="wp-caption alignnone" style="width: 310px"><a href="http://www.efnx.com/lab/SoundWavePlotting/"><img src="http://blog.efnx.com/wp-content/uploads/2008/09/waveform.png" alt="pcm wave data plotted in flash" title="waveform" width="300" height="157" class="size-medium wp-image-77" /></a><p class="wp-caption-text">pcm wave data plotted in flash</p></div></p>
<p><a href='http://blog.efnx.com/wp-content/uploads/2008/09/soundwaveplotting_080926srctar.gz'>Project Source</a></p>
<p>ps &#8211; don&#8217;t cheat, guess the song before you download the source, goofball.</p>
]]></content:encoded>
			<wfw:commentRss>http://efnx.com/plotting-a-sound-wave-in-flash-as3/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>New Updated Tools/Classes For Actionscript 3</title>
		<link>http://efnx.com/new-updated-toolsclasses-for-actionscript-3/</link>
		<comments>http://efnx.com/new-updated-toolsclasses-for-actionscript-3/#comments</comments>
		<pubDate>Mon, 18 Aug 2008 19:08:04 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[button]]></category>
		<category><![CDATA[FPS]]></category>
		<category><![CDATA[MultiLoader]]></category>

		<guid isPermaLink="false">http://blog.efnx.com/?p=55</guid>
		<description><![CDATA[Button
Calculating Frames Per Second [and memory usage]
MultiLoader
Example and Project Source
I&#8217;ve created a number of tools for people to use in the past, most of which I update regularly. In this post I&#8217;d like to revisit some of my old classes and post new updated code for those classes, as in their current form they don&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p><a href="#button">Button</a><br />
<a href="#fps">Calculating Frames Per Second [and memory usage]</a><br />
<a href="#multiloader">MultiLoader</a><br />
<a href="#example">Example and Project Source</a></p>
<p>I&#8217;ve created a number of tools for people to use in the past, most of which I update regularly. In this post I&#8217;d like to revisit some of my old classes and post new updated code for those classes, as in their current form they don&#8217;t much represent my coding style. Please note that my class hierarchy has also changed, so make sure to update your includes if you are using these in your projects.</p>
<p><a name="button"><strong>Button</strong></a><br />
I posted code for a button class here <a href="http://blog.efnx.com/?p=32">->here</a> about a year ago, since then I&#8217;ve changed things and really cleaned up that class. It&#8217;s simpler than before and faster. Given one to three images this class will create a clickable button that has the option to trigger up to four functions [on roll over, mouse down, mouse up and roll out]. Here is a snippet showing its use:</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:300px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">button</span>:<span style="color: #0066CC;">Button</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Button</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// bitmapData of buttons &quot;up&quot; state</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> bmd_up:BitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span>50, 20, <span style="color: #000000; font-weight: bold;">true</span>, 0xFFBDE052<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// bitmapData of buttons &quot;over&quot; state</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> bmd_over:BitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span>50, 20, <span style="color: #000000; font-weight: bold;">true</span>, 0xFF52C4E0<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// bitmapData of buttons &quot;down&quot; state</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> bmd_down:BitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span>50, 20, <span style="color: #000000; font-weight: bold;">true</span>, 0xFFFFAF1A<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">button</span>.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">20</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">button</span>.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">20</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// we pass our bitmapData to the button, one for each state. if only one bitmapData is supplied, it will be</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// copied to each state, after which each new bitmapData supplied will replace the first for the state </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// specified. </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">button</span>.<span style="color: #0066CC;">up</span> = bmd_up;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">button</span>.<span style="color: #006600;">over</span> = bmd_over;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">button</span>.<span style="color: #0066CC;">down</span> = bmd_down;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// we supply functions to the buttons function references, if no functions are supplied, no functions will be called.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">button</span>.<span style="color: #006600;">overFunction</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;UpdatedTools::UpdatedTools()&quot;</span>, <span style="color: #ff0000;">&quot;button over&quot;</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #66cc66;">&#125;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">button</span>.<span style="color: #006600;">downFunction</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;UpdatedTools::UpdatedTools()&quot;</span>, <span style="color: #ff0000;">&quot;button down&quot;</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #66cc66;">&#125;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">button</span>.<span style="color: #006600;">upFunction</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;UpdatedTools::UpdatedTools()&quot;</span>, <span style="color: #ff0000;">&quot;button up&quot;</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #66cc66;">&#125;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">button</span>.<span style="color: #006600;">outFunction</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;UpdatedTools::UpdatedTools()&quot;</span>, <span style="color: #ff0000;">&quot;button out&quot;</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #66cc66;">&#125;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; addChild<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">button</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// adding a label is as simple as creating a textfield and adding it to the button.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> label:<span style="color: #0066CC;">TextField</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextField</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label.<span style="color: #0066CC;">textColor</span> = 0xDDD4F7;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label.<span style="color: #006600;">mouseEnabled</span> = <span style="color: #000000; font-weight: bold;">false</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;Button&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label.<span style="color: #0066CC;">autoSize</span> = <span style="color: #ff0000;">&quot;left&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label.<span style="color: #006600;">x</span> = <span style="color: #0066CC;">button</span>.<span style="color: #0066CC;">width</span><span style="color: #66cc66;">/</span>2 - label.<span style="color: #0066CC;">width</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label.<span style="color: #006600;">y</span> = <span style="color: #0066CC;">button</span>.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">/</span>2 - label.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">button</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>label<span style="color: #66cc66;">&#41;</span>;</div></div>
<p><a name="fps"><strong>Calculating Frames Per Second</strong></a><br />
The next class I&#8217;d like to revisit is my FPS counter. It&#8217;s basically a textfield that displays an instantaneous fps count, and an averaged count. I have now removed the average frames per second and included a display of used memory in MB. Before I had used a timer to calculate the fps, which wasn&#8217;t quite accurate enough. Now the class uses flash.utils.getTimer() and is very precise and accurate. The class extends TextField so custom coloring, etc is very straightforward:</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">fps</span>:FPSBox = <span style="color: #000000; font-weight: bold;">new</span> FPSBox<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; addChild<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">fps</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<p><a name="multiloader"><strong>MultiLoader</strong> and MultiLoaderEvent</a><br />
The next entry is a class created for downloading and importing files from your server or local file system into your flash application. It is what I use in place of my <a href="http://blog.efnx.com/?p=30">Multiple Bitmap Loader</a> and my <a href="http://blog.efnx.com/?p=35">Bitmap Resource Handler</a>. MultiLoader extends Loader to support multiple asynchronous downloads of images/swfs. They trigger specific (read &#8220;specially named&#8221;) ProgressEvents based on the names of entries supplied by you in their load functions. Alternatively, they also trigger a MultiLoaderEvent for every ProgressEvent or complete Event dispatched. One can access the bytesLoaded and bytesTotal for each event, as well as the entry name of the event (which matches the entry name given to MultiLoader). For example, to load a gif and listen to progress and complete events, code the following:</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:300px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> multiLoader:MultiLoader = <span style="color: #000000; font-weight: bold;">new</span> MultiLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; multiLoader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://www.efnx.com/images/experiment.gif&quot;</span>, <span style="color: #ff0000;">&quot;efnx&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;multiLoader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://www.efnx.com/images/experiment.gif&quot;</span>, <span style="color: #ff0000;">&quot;efnx&quot;</span>, <span style="color: #ff0000;">&quot;Bitmap&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; multiLoader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;efnx_Progress&quot;</span>, efnxProgress, <span style="color: #000000; font-weight: bold;">false</span>, 0, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// specially named</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; multiLoader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;efnx_Complete&quot;</span>, efnxComplete, <span style="color: #000000; font-weight: bold;">false</span>, 0, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// specially named</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;multiLoader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;progress&quot;</span>, progress, <span style="color: #000000; font-weight: bold;">false</span>, 0, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">// will trigger a MultiLoaderEvent with an entry member for identification</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;multiLoader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;complete&quot;</span>, complete, <span style="color: #000000; font-weight: bold;">false</span>, 0, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> efnxProgress<span style="color: #66cc66;">&#40;</span>event:ProgressEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;UpdatedTools::efnxProgress()&quot;</span>, <span style="color: #66cc66;">&#40;</span>event.<span style="color: #0066CC;">bytesLoaded</span><span style="color: #66cc66;">/</span>event.<span style="color: #0066CC;">bytesTotal</span><span style="color: #66cc66;">*</span>100<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> efnxComplete<span style="color: #66cc66;">&#40;</span>event:ProgressEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;UpdatedTools::efnxComplete()&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> progress<span style="color: #66cc66;">&#40;</span>event:MultiLoaderEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;UpdatedTools::progress()&quot;</span>, event.<span style="color: #006600;">entry</span>, <span style="color: #66cc66;">&#40;</span>event.<span style="color: #0066CC;">bytesLoaded</span><span style="color: #66cc66;">/</span>event.<span style="color: #0066CC;">bytesTotal</span><span style="color: #66cc66;">*</span>100<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> complete<span style="color: #66cc66;">&#40;</span>event:MultiLoaderEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;UpdatedTools::complete()&quot;</span>, event.<span style="color: #006600;">entry</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div></div>
<p>In this example my entry name is &#8220;efnx&#8221; and so MultiLoader triggers events of type &#8220;efnx_Progress&#8221; and &#8220;efnx_Complete&#8221;. By listening for these events, we can get updated information about our downloads. Another option is to listen for &#8220;progress&#8221; and &#8220;complete,&#8221; which will trigger an event of type MultiLoaderEvent, which extends ProgressEvent to include an &#8220;entry&#8221; member. The value of event.entry will be the name of the entry triggering the event, in this case &#8220;efnx.&#8221; Now to use our images we &#8220;get&#8221; the resource from MultiLoader, which has been storing it for us. A great feature of this class is being able to specify what the return type of your loaded object when calling the &#8220;get&#8221; function. Here I&#8217;m going to want to return a Bitmap object, so for the third parameter of the &#8220;load&#8221; function I&#8217;ll pass the string &#8220;Bitmap&#8221;. Here&#8217;s an example:</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">multiLoader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://www.efnx.com/images/experiment.gif&quot;</span>, <span style="color: #ff0000;">&quot;efnx&quot;</span>, <span style="color: #ff0000;">&quot;Bitmap&quot;</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<p>Now inside my efnxComplete function I&#8217;ll add the get function to get my Bitmap and display it.</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// if we are listening for &quot;efnx_Complete&quot;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> efnxComplete<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;UpdatedTools::efnxComplete()&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> efnxBitmap:Bitmap = multiLoader.<span style="color: #0066CC;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;efnx&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; efnxBitmap.<span style="color: #006600;">x</span> = <span style="color: #0066CC;">button</span>.<span style="color: #006600;">x</span> + <span style="color: #0066CC;">button</span>.<span style="color: #0066CC;">width</span> + <span style="color: #cc66cc;">10</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; efnxBitmap.<span style="color: #006600;">y</span> = <span style="color: #0066CC;">button</span>.<span style="color: #006600;">y</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; addChild<span style="color: #66cc66;">&#40;</span>efnxBitmap<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// or if we are listening for &quot;complete&quot;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> complete<span style="color: #66cc66;">&#40;</span>event:MultiLoaderEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;UpdatedTools::complete()&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> efnxBitmap:Bitmap = multiLoader.<span style="color: #0066CC;">get</span><span style="color: #66cc66;">&#40;</span>event.<span style="color: #006600;">entry</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; efnxBitmap.<span style="color: #006600;">x</span> = <span style="color: #0066CC;">button</span>.<span style="color: #006600;">x</span> + <span style="color: #0066CC;">button</span>.<span style="color: #0066CC;">width</span> + <span style="color: #cc66cc;">10</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; efnxBitmap.<span style="color: #006600;">y</span> = <span style="color: #0066CC;">button</span>.<span style="color: #006600;">y</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; addChild<span style="color: #66cc66;">&#40;</span>efnxBitmap<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div></div>
<p>Using the third parameter of the load() function is optional and if omitted Multiloader will by default choose an appropriate return type, here is a list of the valid strings to pass as a return type:</p>
<p>MovieClip<br />
Sprite<br />
Bitmap<br />
BitmapData</p>
<p>If no third parameter is supplied, MultiLoader will return a type it thinks is appropriate, given the extension of the loaded material. For example loading a .swf will return a MovieClip, where as loading a .jpeg, .png or .gif will return a BitmapData. </p>
<p><a name="example"><strong>Example App and Project Source</strong></a><br />
Here is a project that shows all three updated classes being used:</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:300px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">package <span style="color: #66cc66;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">ProgressEvent</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Bitmap</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">BitmapData</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #0066CC;">TextField</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> efnx.<span style="color: #006600;">gui</span>.<span style="color: #0066CC;">Button</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> efnx.<span style="color: #0066CC;">time</span>.<span style="color: #006600;">FPSBox</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> efnx.<span style="color: #006600;">net</span>.<span style="color: #006600;">MultiLoader</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> efnx.<span style="color: #006600;">events</span>.<span style="color: #006600;">MultiLoaderEvent</span>;<br />
&nbsp; &nbsp; <br />
<span style="color: #808080; font-style: italic;">/**<br />
&nbsp;*&nbsp; Application entry point for UpdatedTools post.<br />
&nbsp;*<br />
&nbsp;*&nbsp; @langversion ActionScript 3.0<br />
&nbsp;*&nbsp; @playerversion Flash 9.0<br />
&nbsp;*<br />
&nbsp;*&nbsp; @author Schell Scivally<br />
&nbsp;*&nbsp; @since 18.08.2008<br />
&nbsp;*/</span><br />
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> UpdatedTools <span style="color: #0066CC;">extends</span> Sprite <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const testing:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">button</span>:<span style="color: #0066CC;">Button</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Button</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> multiLoader:MultiLoader = <span style="color: #000000; font-weight: bold;">new</span> MultiLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp;*&nbsp; @constructor<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> UpdatedTools<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">frameRate</span> = <span style="color: #cc66cc;">30</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">stage</span>.<span style="color: #0066CC;">scaleMode</span> = <span style="color: #ff0000;">&quot;noScale&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">stage</span>.<span style="color: #0066CC;">align</span> = <span style="color: #ff0000;">&quot;TL&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;resize&quot;</span>, resize, <span style="color: #000000; font-weight: bold;">false</span>, 0, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// bitmapData of buttons &quot;up&quot; state</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> bmd_up:BitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span>50, 20, <span style="color: #000000; font-weight: bold;">true</span>, 0xFFBDE052<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// bitmapData of buttons &quot;over&quot; state</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> bmd_over:BitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span>50, 20, <span style="color: #000000; font-weight: bold;">true</span>, 0xFF52C4E0<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// bitmapData of buttons &quot;down&quot; state</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> bmd_down:BitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span>50, 20, <span style="color: #000000; font-weight: bold;">true</span>, 0xFFFFAF1A<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">button</span>.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">20</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">button</span>.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">20</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// we pass our bitmapData to the button, one for each state. if only one bitmapData is supplied, it will be</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// copied to each state, after which each new bitmapData supplied will replace the first for the state </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// specified. </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">button</span>.<span style="color: #0066CC;">up</span> = bmd_up;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">button</span>.<span style="color: #006600;">over</span> = bmd_over;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">button</span>.<span style="color: #0066CC;">down</span> = bmd_down;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// we supply functions to the buttons function references, if no functions are supplied, no functions will be called.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">button</span>.<span style="color: #006600;">overFunction</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;UpdatedTools::UpdatedTools()&quot;</span>, <span style="color: #ff0000;">&quot;button over&quot;</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #66cc66;">&#125;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">button</span>.<span style="color: #006600;">downFunction</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;UpdatedTools::UpdatedTools()&quot;</span>, <span style="color: #ff0000;">&quot;button down&quot;</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #66cc66;">&#125;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">button</span>.<span style="color: #006600;">upFunction</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;UpdatedTools::UpdatedTools()&quot;</span>, <span style="color: #ff0000;">&quot;button up&quot;</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #66cc66;">&#125;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">button</span>.<span style="color: #006600;">outFunction</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;UpdatedTools::UpdatedTools()&quot;</span>, <span style="color: #ff0000;">&quot;button out&quot;</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #66cc66;">&#125;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; addChild<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">button</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// adding a label is as simple as creating a textfield and adding it to the button.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> label:<span style="color: #0066CC;">TextField</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextField</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label.<span style="color: #0066CC;">textColor</span> = 0xDDD4F7;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label.<span style="color: #006600;">mouseEnabled</span> = <span style="color: #000000; font-weight: bold;">false</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;Button&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label.<span style="color: #0066CC;">autoSize</span> = <span style="color: #ff0000;">&quot;left&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label.<span style="color: #006600;">x</span> = <span style="color: #0066CC;">button</span>.<span style="color: #0066CC;">width</span><span style="color: #66cc66;">/</span>2 - label.<span style="color: #0066CC;">width</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label.<span style="color: #006600;">y</span> = <span style="color: #0066CC;">button</span>.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">/</span>2 - label.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">button</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>label<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">fps</span>:FPSBox = <span style="color: #000000; font-weight: bold;">new</span> FPSBox<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; addChild<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">fps</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; MultiLoader.<span style="color: #006600;">testing</span> = <span style="color: #000000; font-weight: bold;">true</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; MultiLoader.<span style="color: #006600;">usingContext</span> = <span style="color: #000000; font-weight: bold;">true</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; multiLoader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://www.efnx.com/images/experiment.gif&quot;</span>, <span style="color: #ff0000;">&quot;efnx&quot;</span>, <span style="color: #ff0000;">&quot;Bitmap&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; multiLoader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://www.efnx.com/images/808.jpg&quot;</span>, <span style="color: #ff0000;">&quot;808&quot;</span>, <span style="color: #ff0000;">&quot;Sprite&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; multiLoader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;progress&quot;</span>, progress, <span style="color: #000000; font-weight: bold;">false</span>, 0, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; multiLoader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;complete&quot;</span>, complete, <span style="color: #000000; font-weight: bold;">false</span>, 0, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> progress<span style="color: #66cc66;">&#40;</span>event:MultiLoaderEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;UpdatedTools::progress()&quot;</span>, event.<span style="color: #006600;">entry</span>, <span style="color: #ff0000;">&quot;: &quot;</span>, <span style="color: #66cc66;">&#40;</span>event.<span style="color: #0066CC;">bytesLoaded</span><span style="color: #66cc66;">/</span>event.<span style="color: #0066CC;">bytesTotal</span><span style="color: #66cc66;">*</span>100<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> complete<span style="color: #66cc66;">&#40;</span>event:MultiLoaderEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;UpdatedTools::complete()&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">switch</span><span style="color: #66cc66;">&#40;</span>event.<span style="color: #006600;">entry</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;efnx&quot;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> efnxBitmap:Bitmap = multiLoader.<span style="color: #0066CC;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;efnx&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; efnxBitmap.<span style="color: #006600;">x</span> = <span style="color: #0066CC;">button</span>.<span style="color: #006600;">x</span> + <span style="color: #0066CC;">button</span>.<span style="color: #0066CC;">width</span> + <span style="color: #cc66cc;">10</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; efnxBitmap.<span style="color: #006600;">y</span> = <span style="color: #0066CC;">button</span>.<span style="color: #006600;">y</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addChild<span style="color: #66cc66;">&#40;</span>efnxBitmap<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">break</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;808&quot;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> sprite808:Sprite = multiLoader.<span style="color: #0066CC;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;808&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sprite808.<span style="color: #006600;">x</span> = <span style="color: #0066CC;">button</span>.<span style="color: #006600;">x</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sprite808.<span style="color: #006600;">y</span> = <span style="color: #0066CC;">button</span>.<span style="color: #006600;">y</span> + <span style="color: #0066CC;">button</span>.<span style="color: #0066CC;">height</span> + <span style="color: #cc66cc;">20</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addChild<span style="color: #66cc66;">&#40;</span>sprite808<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">break</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">default</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp;*&nbsp; Resize stub.<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> resize<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>testing<span style="color: #66cc66;">&#41;</span> <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;UpdatedTools::resize()&quot;</span> <span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>And here is the source to my classes:<br />
<a href='http://blog.efnx.com/wp-content/uploads/2008/08/UpdatedTools_081113.src.tar.gz' title='updatedSource'>Example Project and Source [includes classes]</a></p>
<p>Here is a little example:<br />
<a href='http://blog.efnx.com/wp-content/uploads/2008/08/UpdatedTools.swf' title='updatedExample'>updatedExample</a></p>
<p>And as always you can find the classes by themselves [along with all my other classes] here <a href="http://efnx.com/classes">efnx AS3 classes</a>, as well as some limited documentation <a href="http://efnx.com/docs">efnx Class Documentation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://efnx.com/new-updated-toolsclasses-for-actionscript-3/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Actionscript 3 Browser Theremin / Wave Data Visualization</title>
		<link>http://efnx.com/browser-theremin-wave-data-visualization/</link>
		<comments>http://efnx.com/browser-theremin-wave-data-visualization/#comments</comments>
		<pubDate>Sat, 02 Aug 2008 22:02:38 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Sound]]></category>
		<category><![CDATA[Browser]]></category>
		<category><![CDATA[Theremin]]></category>

		<guid isPermaLink="false">http://blog.efnx.com/?p=52</guid>
		<description><![CDATA[Yesterday I started fooling around with FP10&#8217;s sound generation capabilities and I got the idea to code a little Theremin. It came out pretty good, but was bland in aesthetics. I decided to try my hand at coding a visualization algorithm similar to the type of visualization one would see while using Amadeus or Digital [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I started fooling around with FP10&#8217;s sound generation capabilities and I got the idea to code a little Theremin. It came out pretty good, but was bland in aesthetics. I decided to try my hand at coding a visualization algorithm similar to the type of visualization one would see while using <a href="http://www.hairersoft.com/Amadeus.html">Amadeus</a> or Digital Performer, etc. I wanted to plot the wave form on the stage. Taking a copy of the sound buffer and selecting equally spaced samples I plotted them on the bitmapData of a Bitmap object and drew lines between data points. This is what it looks like:<br />
<a href="http://www.efnx.com/lab/Theremin/"><img src="http://www.efnx.com/lab/Theremin/_assets/images/Theramin.png" alt="Theremin Wave Data" /></a></p>
<p>The mouse position in x controls the frequency of a sine wave [from 220Hz to 440Hz or A3 to A4], while the y position controls volume. There&#8217;s some tearing that occurs when modulating volume, I haven&#8217;t figured that out how to fix that yet.  As you move your mouse the wave that is generated is plotted on the stage. The pink dots represent sampled data points [which correspond to speaker movement] while the purple lines are approximations of the in-betweens [just lines drawn from point to point]. After playing with that for a while I wrote a class that matches note names to frequencies and drew markers indicating where on the x-axis of the stage one would have to place the cursor to generate a given note between A3 and A4. This is just a small example of the possibilities of sound in flash, and one way to interact with it. I&#8217;m looking forward to building on the classes I made for this example. I&#8217;ve included my entire TextMate project and source below [which will be the foundation of many more experiments], you can chop it up and use it however you want, although I didn&#8217;t copy any license to it, but trust me I won&#8217;t sue. </p>
<p>src -> <a href='http://blog.efnx.com/wp-content/uploads/2008/08/theremin.tar.gz' title='Theremin Project'>Theremin Project/Visualizing Wave Data</a></p>
]]></content:encoded>
			<wfw:commentRss>http://efnx.com/browser-theremin-wave-data-visualization/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Flash 10 [Astro] Debug Install</title>
		<link>http://efnx.com/flash-10-astro-debug-install/</link>
		<comments>http://efnx.com/flash-10-astro-debug-install/#comments</comments>
		<pubDate>Thu, 31 Jul 2008 01:05:46 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Astro]]></category>
		<category><![CDATA[fix]]></category>
		<category><![CDATA[workaround]]></category>

		<guid isPermaLink="false">http://blog.efnx.com/?p=51</guid>
		<description><![CDATA[I had some problems installing the under-the-radar Flash 10 Debug version mentioned in a couple blogs in the past months. So here is my work around just in case anyone else can&#8217;t seem to get Flash 10 to trace to their flashlog.txt.
1. Download installer from Adobe&#8217;s svn repository and select your OS [the rest of [...]]]></description>
			<content:encoded><![CDATA[<p>I had some problems installing the under-the-radar Flash 10 Debug version mentioned in a couple blogs in the past months. So here is my work around just in case anyone else can&#8217;t seem to get Flash 10 to trace to their flashlog.txt.</p>
<p>1. Download installer from <a href="http://opensource.adobe.com/svn/opensource/flex/sdk/tags/trunk_4.0.0.2432/in/player/10/" target="_blank">Adobe&#8217;s svn repository</a> and select your OS [the rest of these steps are for mac, mind you, but you'll get the idea].<br />
2. Unarchive and mount &#8220;Install Flash Player 10 UB.dmg&#8221;<br />
3. Here&#8217;s the funny part, I couldn&#8217;t install the package. I got an error saying &#8220;nothing to install&#8221;, so instead, right click on &#8220;Adobe Flash Player.pkg&#8221; and choose &#8220;Show Package Contents&#8221;. It should show two archives, a plist, pkginfo and a resources folder.<br />
4. Unarchive &#8220;Archive.pax.gz&#8221; to your desktop.<br />
5. Inside you&#8217;ll find &#8220;Flash Player.plugin,&#8221; &#8220;flashplayer.xpt&#8221; and &#8220;version.txt.&#8221; The version.txt file says the player is version 9.0.45.0, but after looking at the info for &#8220;Flash Player.plugin&#8221; you&#8217;ll see it&#8217;s version 10.0.0.525, which isn&#8217;t the newest, but it traces and that&#8217;s what I need it for.<br />
6. Copy &#8220;Flash Player.plugin&#8221; and &#8220;flashplayer.xpt&#8221; to your internet plugin folder, on my machine that&#8217;s /Library/Internet Plug-Ins<br />
7. Restart FireFox/Safari/whatever.</p>
<p>That&#8217;s it!</p>
<p>I&#8217;m sorry if this info is un-needed, I definitely needed it, maybe everyone else can simply install that package, but I couldn&#8217;t, so that&#8217;s the fix. Happy coding.</p>
]]></content:encoded>
			<wfw:commentRss>http://efnx.com/flash-10-astro-debug-install/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Merging Layered BitmapData in AS3</title>
		<link>http://efnx.com/merging-layered-bitmapdata-in-as3/</link>
		<comments>http://efnx.com/merging-layered-bitmapdata-in-as3/#comments</comments>
		<pubDate>Fri, 15 Feb 2008 02:55:27 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[bitmapData]]></category>
		<category><![CDATA[bitwise]]></category>
		<category><![CDATA[layers]]></category>
		<category><![CDATA[merge]]></category>
		<category><![CDATA[pixels]]></category>

		<guid isPermaLink="false">http://blog.efnx.com/?p=45</guid>
		<description><![CDATA[This tutorial is for those of your who might have to write your own Photo-shop-a-like applications or anyone who has to merge [flatten] two BitmapData together at pixel-level, without using BitmapData.copyPixels or BitmapData.merge. Furthermore this tutorial deals with bitwise operations, which are super fast and rad for color computation. Boom. Color. If you&#8217;re not familiar [...]]]></description>
			<content:encoded><![CDATA[<p>This tutorial is for those of your who might have to write your own Photo-shop-a-like applications or anyone who has to merge [flatten] two BitmapData together at pixel-level, without using BitmapData.copyPixels or BitmapData.merge. Furthermore this tutorial deals with bitwise operations, which are super fast and rad for color computation. Boom. Color. If you&#8217;re not familiar with bitwise operators I suggest you check out Polygonal Labs&#8217; <a href="http://lab.polygonal.de/2007/05/10/bitwise-gems-fast-integer-math/">Bitwise Gems: Fast Integer Math</a>. Done? Great. Okay, on with our discussion. I hope this stuff makes sense because this is my first tutorial. Ever&#8230;. &#8230;so first let&#8217;s create some colored Bitmaps on the page.</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">var</span> bmd1:BitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span>100, 100, <span style="color: #000000; font-weight: bold;">true</span>, 0xFF00FF00<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> bm1:Bitmap = <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span>bmd1<span style="color: #66cc66;">&#41;</span>;<br />
addChild<span style="color: #66cc66;">&#40;</span>bm1<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> bmd2:BitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span>100, 100, <span style="color: #000000; font-weight: bold;">true</span>, 0xFFFF0000<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> bm2:Bitmap = <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span>bmd2<span style="color: #66cc66;">&#41;</span>;<br />
bm2.<span style="color: #006600;">y</span> = bm1.<span style="color: #0066CC;">height</span>;<br />
addChild<span style="color: #66cc66;">&#40;</span>bm2<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> bmd3:BitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span>100, 100, <span style="color: #000000; font-weight: bold;">true</span>, 0x7F0000FF<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> bm3:Bitmap = <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span>bmd3<span style="color: #66cc66;">&#41;</span>;<br />
bm3.<span style="color: #006600;">x</span> = bm1.<span style="color: #0066CC;">width</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>;<br />
bm3.<span style="color: #006600;">y</span> = bm1.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>;<br />
addChild<span style="color: #66cc66;">&#40;</span>bm3<span style="color: #66cc66;">&#41;</span>;</div></div>
<p>Building our project we should see somethin like this:<br />
<img src='http://blog.efnx.com/wp-content/uploads/2008/02/mergebmdstep1.jpg' alt='MergingLayeredBitmapDataStep1' /><br />
As you can see we&#8217;ve created a super green bmd, a bloody red bmd and a half-hearted (half-opaque) blue bmd. When the half-opaque blue bitmap is placed over the green and red bitmaps it filters the green and red bitmaps, altering the percieved colors. Our goal is to be able to calculate those percieved colors given two 32 bit colors in order to merge them onto a new BitmapData.</p>
<p>Now let&#8217;s begin our pixel layering function. We can start by outlining what the function is going to do. Let&#8217;s give it two 32 bit colors, (like the red and blue or the green and blue) and let&#8217;s make it give us back a 32 bit color that represents the two colors layered on top of each other.</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> layerColor32<span style="color: #66cc66;">&#40;</span>topColor:uint, bottomColor:uint<span style="color: #66cc66;">&#41;</span>:uint<br />
<span style="color: #66cc66;">&#123;</span><br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>Now let&#8217;s extract each color&#8217;s ARGB channels. Traditionally the method would look like this:</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> layerColor32<span style="color: #66cc66;">&#40;</span>topColor:uint, bottomColor:uint<span style="color: #66cc66;">&#41;</span>:uint<br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> aB:uint = bottomColor <span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #cc66cc;">24</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> rB:uint = bottomColor <span style="color: #66cc66;">&gt;&gt;&gt;</span> 16 <span style="color: #66cc66;">&amp;</span> 0xFF;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> gB:uint = bottomColor <span style="color: #66cc66;">&gt;&gt;&gt;</span> 8 <span style="color: #66cc66;">&amp;</span> 0xFF;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> bB:uint = bottomColor &nbsp;<span style="color: #66cc66;">&amp;</span> 0xFF;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> aT:uint = topColor <span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #cc66cc;">24</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> rT:uint = topColor <span style="color: #66cc66;">&gt;&gt;&gt;</span> 16 <span style="color: #66cc66;">&amp;</span> 0xFF;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> gT:uint = topColor <span style="color: #66cc66;">&gt;&gt;&gt;</span> 8 <span style="color: #66cc66;">&amp;</span> 0xFF;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> bT:uint = topColor &nbsp;<span style="color: #66cc66;">&amp;</span> 0xFF;<br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>But since we&#8217;re working with what the colors *should* look like when layered, we have to figure out how much each channel actually shows through, according to the alpha channel. To do this we&#8217;ll multiply each channel by the color&#8217;s alpha channel&#8217;s opacity. The opacity is simply the alpha channel value divided by 255. So 100% opacity (255 or 0xFF) would turn out as 1, and 1 times each channel means 100% of each channel will show. 50% opacity (127 or 0&#215;7F-0&#215;80) would turn out as .5 and .5 times each channel shows 50% of each channel. Thus:</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> layerColor32<span style="color: #66cc66;">&#40;</span>topColor:uint, bottomColor:uint<span style="color: #66cc66;">&#41;</span>:uint<br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> aB:uint = bottomColor <span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #cc66cc;">24</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> rB:uint = <span style="color: #66cc66;">&#40;</span>bottomColor <span style="color: #66cc66;">&gt;&gt;&gt;</span> 16 <span style="color: #66cc66;">&amp;</span> 0xFF<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#40;</span>aB<span style="color: #66cc66;">/</span>0xFF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> gB:uint = <span style="color: #66cc66;">&#40;</span>bottomColor <span style="color: #66cc66;">&gt;&gt;&gt;</span> 8 <span style="color: #66cc66;">&amp;</span> 0xFF<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#40;</span>aB<span style="color: #66cc66;">/</span>0xFF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> bB:uint = <span style="color: #66cc66;">&#40;</span>bottomColor &nbsp;<span style="color: #66cc66;">&amp;</span> 0xFF<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#40;</span>aB<span style="color: #66cc66;">/</span>0xFF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> aT:uint = topColor <span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #cc66cc;">24</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> rT:uint = <span style="color: #66cc66;">&#40;</span>topColor <span style="color: #66cc66;">&gt;&gt;&gt;</span> 16 <span style="color: #66cc66;">&amp;</span> 0xFF<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#40;</span>aT<span style="color: #66cc66;">/</span>0xFF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> gT:uint = <span style="color: #66cc66;">&#40;</span>topColor <span style="color: #66cc66;">&gt;&gt;&gt;</span> 8 <span style="color: #66cc66;">&amp;</span> 0xFF<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#40;</span>aT<span style="color: #66cc66;">/</span>0xFF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> bT:uint = <span style="color: #66cc66;">&#40;</span>topColor &nbsp;<span style="color: #66cc66;">&amp;</span> 0xFF<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#40;</span>aT<span style="color: #66cc66;">/</span>0xFF<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>Now that we have our individual channel values we can begin to calculate our new color. Remember that the maximum color value is 255 (0xFF) so we&#8217;ll be constraining our channel additions to 255.</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> layerColor32<span style="color: #66cc66;">&#40;</span>topColor:uint, bottomColor:uint<span style="color: #66cc66;">&#41;</span>:uint<br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> aB:uint = bottomColor <span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #cc66cc;">24</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> rB:uint = <span style="color: #66cc66;">&#40;</span>bottomColor <span style="color: #66cc66;">&gt;&gt;&gt;</span> 16 <span style="color: #66cc66;">&amp;</span> 0xFF<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#40;</span>aB<span style="color: #66cc66;">/</span>0xFF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> gB:uint = <span style="color: #66cc66;">&#40;</span>bottomColor <span style="color: #66cc66;">&gt;&gt;&gt;</span> 8 <span style="color: #66cc66;">&amp;</span> 0xFF<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#40;</span>aB<span style="color: #66cc66;">/</span>0xFF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> bB:uint = <span style="color: #66cc66;">&#40;</span>bottomColor &nbsp;<span style="color: #66cc66;">&amp;</span> 0xFF<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#40;</span>aB<span style="color: #66cc66;">/</span>0xFF<span style="color: #66cc66;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> aT:uint = topColor <span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #cc66cc;">24</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> rT:uint = <span style="color: #66cc66;">&#40;</span>topColor <span style="color: #66cc66;">&gt;&gt;&gt;</span> 16 <span style="color: #66cc66;">&amp;</span> 0xFF<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#40;</span>aT<span style="color: #66cc66;">/</span>0xFF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> gT:uint = <span style="color: #66cc66;">&#40;</span>topColor <span style="color: #66cc66;">&gt;&gt;&gt;</span> 8 <span style="color: #66cc66;">&amp;</span> 0xFF<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#40;</span>aT<span style="color: #66cc66;">/</span>0xFF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> bT:uint = <span style="color: #66cc66;">&#40;</span>topColor &nbsp;<span style="color: #66cc66;">&amp;</span> 0xFF<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#40;</span>aT<span style="color: #66cc66;">/</span>0xFF<span style="color: #66cc66;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> aN:uint = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">min</span><span style="color: #66cc66;">&#40;</span>aB + aT, 0xFF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> rN:uint = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">min</span><span style="color: #66cc66;">&#40;</span>rB + rT, 0xFF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> gN:uint = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">min</span><span style="color: #66cc66;">&#40;</span>gB + gT, 0xFF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> bN:uint = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">min</span><span style="color: #66cc66;">&#40;</span>bB + bT, 0xFF<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>If you combine our channels and return the new color you&#8217;ll get something much brighter than what we should see. We&#8217;re going to have to filter the bottom color through the top color to fix this. You might be saying &#8220;ah man, I&#8217;ll just use BitmapData.copyPixels,&#8221; but don&#8217;t worry, we&#8217;re almost done. It&#8217;ll be so much more satisfying to figure out this stuff in the end, believe me. You&#8217;ll be a color scientist. So, all we need to do is multiply each channel of the bottom color by a number that represents how much light penetrates the top layer. So, if our top layer alpha channel is 0&#215;7F, our &#8217;show through&#8217; variable is going to be 50% (0&#215;7F) and if our top alpha channel is 0&#215;40 (25%) then 75% of the bottom channel will show through. To do this we&#8217;ll create our &#8217;show through&#8217; var and multiply the bottom channels by it.</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> layerColor32<span style="color: #66cc66;">&#40;</span>topColor:uint, bottomColor:uint<span style="color: #66cc66;">&#41;</span>:uint<br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> aB:uint = bottomColor <span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #cc66cc;">24</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> rB:uint = <span style="color: #66cc66;">&#40;</span>bottomColor <span style="color: #66cc66;">&gt;&gt;&gt;</span> 16 <span style="color: #66cc66;">&amp;</span> 0xFF<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#40;</span>aB<span style="color: #66cc66;">/</span>0xFF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> gB:uint = <span style="color: #66cc66;">&#40;</span>bottomColor <span style="color: #66cc66;">&gt;&gt;&gt;</span> 8 <span style="color: #66cc66;">&amp;</span> 0xFF<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#40;</span>aB<span style="color: #66cc66;">/</span>0xFF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> bB:uint = <span style="color: #66cc66;">&#40;</span>bottomColor &nbsp;<span style="color: #66cc66;">&amp;</span> 0xFF<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#40;</span>aB<span style="color: #66cc66;">/</span>0xFF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> aT:uint = topColor <span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #cc66cc;">24</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> rT:uint = <span style="color: #66cc66;">&#40;</span>topColor <span style="color: #66cc66;">&gt;&gt;&gt;</span> 16 <span style="color: #66cc66;">&amp;</span> 0xFF<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#40;</span>aT<span style="color: #66cc66;">/</span>0xFF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> gT:uint = <span style="color: #66cc66;">&#40;</span>topColor <span style="color: #66cc66;">&gt;&gt;&gt;</span> 8 <span style="color: #66cc66;">&amp;</span> 0xFF<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#40;</span>aT<span style="color: #66cc66;">/</span>0xFF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> bT:uint = <span style="color: #66cc66;">&#40;</span>topColor &nbsp;<span style="color: #66cc66;">&amp;</span> 0xFF<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#40;</span>aT<span style="color: #66cc66;">/</span>0xFF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/*this determines how much of our lower layer shows through*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> showThru:<span style="color: #0066CC;">Number</span> = <span style="color: #66cc66;">&#40;</span>0xFF - aT<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">/</span>0xFF;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;laryerColor32:showThru: (255 - &quot;</span>+aT+<span style="color: #ff0000;">&quot;)/255 = &quot;</span>+showThru<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**********************************************************************/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> aN:uint = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">min</span><span style="color: #66cc66;">&#40;</span>aB + aT, 0xFF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> rN:uint = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">min</span><span style="color: #66cc66;">&#40;</span>rB<span style="color: #66cc66;">*</span>showThru + rT, 0xFF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> gN:uint = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">min</span><span style="color: #66cc66;">&#40;</span>gB<span style="color: #66cc66;">*</span>showThru + gT, 0xFF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> bN:uint = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">min</span><span style="color: #66cc66;">&#40;</span>bB<span style="color: #66cc66;">*</span>showThru + bT, 0xFF<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>Now for the last bit. Let&#8217;s combine all our new channels and return that value.</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:300px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> layerColor32<span style="color: #66cc66;">&#40;</span>topColor:uint, bottomColor:uint<span style="color: #66cc66;">&#41;</span>:uint<br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> aB:uint = bottomColor <span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #cc66cc;">24</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> rB:uint = <span style="color: #66cc66;">&#40;</span>bottomColor <span style="color: #66cc66;">&gt;&gt;&gt;</span> 16 <span style="color: #66cc66;">&amp;</span> 0xFF<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#40;</span>aB<span style="color: #66cc66;">/</span>0xFF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> gB:uint = <span style="color: #66cc66;">&#40;</span>bottomColor <span style="color: #66cc66;">&gt;&gt;&gt;</span> 8 <span style="color: #66cc66;">&amp;</span> 0xFF<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#40;</span>aB<span style="color: #66cc66;">/</span>0xFF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> bB:uint = <span style="color: #66cc66;">&#40;</span>bottomColor &nbsp;<span style="color: #66cc66;">&amp;</span> 0xFF<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#40;</span>aB<span style="color: #66cc66;">/</span>0xFF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> aT:uint = topColor <span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #cc66cc;">24</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> rT:uint = <span style="color: #66cc66;">&#40;</span>topColor <span style="color: #66cc66;">&gt;&gt;&gt;</span> 16 <span style="color: #66cc66;">&amp;</span> 0xFF<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#40;</span>aT<span style="color: #66cc66;">/</span>0xFF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> gT:uint = <span style="color: #66cc66;">&#40;</span>topColor <span style="color: #66cc66;">&gt;&gt;&gt;</span> 8 <span style="color: #66cc66;">&amp;</span> 0xFF<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#40;</span>aT<span style="color: #66cc66;">/</span>0xFF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> bT:uint = <span style="color: #66cc66;">&#40;</span>topColor &nbsp;<span style="color: #66cc66;">&amp;</span> 0xFF<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#40;</span>aT<span style="color: #66cc66;">/</span>0xFF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/*this determines how much of our lower layer shows through*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> showThru:<span style="color: #0066CC;">Number</span> = <span style="color: #66cc66;">&#40;</span>0xFF - aT<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">/</span>0xFF;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;laryerColor32:showThru: (255 - &quot;</span>+aT+<span style="color: #ff0000;">&quot;)/255 = &quot;</span>+showThru<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**********************************************************************/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> aN:uint = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">min</span><span style="color: #66cc66;">&#40;</span>aB + aT, 0xFF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> rN:uint = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">min</span><span style="color: #66cc66;">&#40;</span>rB<span style="color: #66cc66;">*</span>showThru + rT, 0xFF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> gN:uint = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">min</span><span style="color: #66cc66;">&#40;</span>gB<span style="color: #66cc66;">*</span>showThru + gT, 0xFF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> bN:uint = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">min</span><span style="color: #66cc66;">&#40;</span>bB<span style="color: #66cc66;">*</span>showThru + bT, 0xFF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span><span style="color: #66cc66;">&#40;</span>aN <span style="color: #66cc66;">&lt;&lt;</span> 24 <span style="color: #66cc66;">|</span> rN <span style="color: #66cc66;">&lt;&lt;</span> 16 <span style="color: #66cc66;">|</span> gN <span style="color: #66cc66;">&lt;&lt;</span> 8 <span style="color: #66cc66;">|</span> bN<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>Awesome! Were done. Using this function, for loops and some creativity, you can compile any number of 32 bit BitmapData on top of each other. Boom. Color. So, let&#8217;s use this function and compare it to the blending that happens within DisplayObjectContainers with transparency! Let&#8217;s alter our first bitmap generating/placing code to use our new function:</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:300px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">var</span> bmd1:BitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span>100, 100, <span style="color: #000000; font-weight: bold;">true</span>, 0xFF00FF00<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> bm1:Bitmap = <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span>bmd1<span style="color: #66cc66;">&#41;</span>;<br />
addChild<span style="color: #66cc66;">&#40;</span>bm1<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> bmd2:BitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span>100, 100, <span style="color: #000000; font-weight: bold;">true</span>, 0xFFFF0000<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> bm2:Bitmap = <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span>bmd2<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; bm2.<span style="color: #006600;">y</span> = bm1.<span style="color: #0066CC;">height</span>;<br />
addChild<span style="color: #66cc66;">&#40;</span>bm2<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> bmd3:BitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span>100, 100, <span style="color: #000000; font-weight: bold;">true</span>, 0x7F0000FF<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> bm3:Bitmap = <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span>bmd3<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; bm3.<span style="color: #006600;">x</span> = bm1.<span style="color: #0066CC;">width</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>;<br />
&nbsp; &nbsp; bm3.<span style="color: #006600;">y</span> = bm1.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>;<br />
addChild<span style="color: #66cc66;">&#40;</span>bm3<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> color1:uint = bmd1.<span style="color: #006600;">getPixel32</span><span style="color: #66cc66;">&#40;</span>0, 0<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> color2:uint = bmd3.<span style="color: #006600;">getPixel32</span><span style="color: #66cc66;">&#40;</span>0, 0<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> color3:uint = layerColor32<span style="color: #66cc66;">&#40;</span>color2, color1<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> color4:uint = bmd2.<span style="color: #006600;">getPixel32</span><span style="color: #66cc66;">&#40;</span>0, 0<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> color5:uint = layerColor32<span style="color: #66cc66;">&#40;</span>color2, color4<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> bmd4:BitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span>50, 50, <span style="color: #000000; font-weight: bold;">true</span>, color3<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> bm4:Bitmap = <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span>bmd4<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; bm4.<span style="color: #006600;">x</span> = bm1.<span style="color: #0066CC;">width</span>;<br />
addChild<span style="color: #66cc66;">&#40;</span>bm4<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> bmd5:BitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span>50, 50, <span style="color: #000000; font-weight: bold;">true</span>, color5<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> bm5:Bitmap = <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span>bmd5<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; bm5.<span style="color: #006600;">x</span> = bm1.<span style="color: #0066CC;">width</span>;<br />
&nbsp; &nbsp; bm5.<span style="color: #006600;">y</span> = bm1.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">1.5</span>;<br />
addChild<span style="color: #66cc66;">&#40;</span>bm5<span style="color: #66cc66;">&#41;</span>;</div></div>
<p>Let&#8217;s take a look at it.<br />
<img src='http://blog.efnx.com/wp-content/uploads/2008/02/mergebmdstep2.jpg' alt='MergingLayeredBitmapDataStep2' /><br />
Wow, I don&#8217;t believe. Well, there you have it. Bust out your color schemer (or equivalent) and check those hex codes. Exact are they not? I hope you enjoyed this! Yay color.</p>
]]></content:encoded>
			<wfw:commentRss>http://efnx.com/merging-layered-bitmapdata-in-as3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AS3 Classes and Interfaces Quicktip</title>
		<link>http://efnx.com/as3-classes-and-interfaces-quicktip/</link>
		<comments>http://efnx.com/as3-classes-and-interfaces-quicktip/#comments</comments>
		<pubDate>Sat, 19 Jan 2008 18:37:00 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[interface]]></category>

		<guid isPermaLink="false">http://blog.efnx.com/?p=42</guid>
		<description><![CDATA[Interfaces in AS3 are super useful for requiring classes to support a set of public methods, enabling other classes to communicate through the interface thereby abstracting the class itself. AS3 doesn&#8217;t natively support abstract classes so using Interfaces is a good replacement in some cases, but if you&#8217;ve never used an Interface before you probably [...]]]></description>
			<content:encoded><![CDATA[<p>Interfaces in AS3 are super useful for requiring classes to support a set of public methods, enabling other classes to communicate through the interface thereby abstracting the class itself. AS3 doesn&#8217;t natively support abstract classes so using Interfaces is a good replacement in some cases, but if you&#8217;ve never used an Interface before you probably wouldn&#8217;t know how to implement it. The docs help a little, showing you how to instantiate a class using an interface with the &#8220;implements&#8221; keyword, but doesn&#8217;t go much further:</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> myClass <span style="color: #0066CC;">implements</span> myInterface<span style="color: #66cc66;">&#123;</span><br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>But what if you&#8217;d like to implement a class while extending another? Well, it&#8217;s simple once you know the syntax&#8230;</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> myClass <span style="color: #0066CC;">extends</span> baseClass <span style="color: #0066CC;">implements</span> myInterface <span style="color: #66cc66;">&#123;</span><br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>This is a very quick and simple tip that took me a while to find online due to the fact Adobe doesn&#8217;t mention it. Such a simple thing should be in the help docs, but I guess adobe thinks that anyone trying to use Interfaces would already know the syntax! Well now you do. </p>
]]></content:encoded>
			<wfw:commentRss>http://efnx.com/as3-classes-and-interfaces-quicktip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AS3 doLater/todo Function Queue</title>
		<link>http://efnx.com/as3-dolatertodo-function-queue/</link>
		<comments>http://efnx.com/as3-dolatertodo-function-queue/#comments</comments>
		<pubDate>Sat, 08 Dec 2007 08:31:59 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[doLater]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[queue]]></category>
		<category><![CDATA[todo]]></category>

		<guid isPermaLink="false">http://blog.efnx.com/?p=37</guid>
		<description><![CDATA[While working on my windowing system I ran into a problem. Every time I tried to set the width of my window class instance I&#8217;d get an error from my bitmap resource handler telling me the resources hadn&#8217;t been loaded. This makes it impossible to set widths for a window before it&#8217;s loaded, and since [...]]]></description>
			<content:encoded><![CDATA[<p>While working on my windowing system I ran into a problem. Every time I tried to set the width of my window class instance I&#8217;d get an error from my bitmap resource handler telling me the resources hadn&#8217;t been loaded. This makes it impossible to set widths for a window before it&#8217;s loaded, and since the entire system is supposed to be deployable online, loading time is not anything I can count on. I wrote this small class to take care of executing functions at a given time (like after loading is finished). The class is called Queue and here is some usage:</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:300px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">import</span> com.<span style="color: #006600;">efnx</span>.<span style="color: #006600;">utils</span>.<span style="color: #006600;">Queue</span>;<br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> blah<span style="color: #66cc66;">&#40;</span>val1:<span style="color: #0066CC;">int</span>, val2:<span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>val1+val2<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> blah2<span style="color: #66cc66;">&#40;</span>val1:<span style="color: #0066CC;">int</span>, val2:<span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>val1+val2<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">var</span> queue:Queue = <span style="color: #000000; font-weight: bold;">new</span> Queue<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; queue.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>blah, 1, 5<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; queue.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>blah, 2, 5<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; queue.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>blah, 4, 5<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; queue.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>blah2, 3, 5<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>queue<span style="color: #66cc66;">&#41;</span>;<br />
<br />
queue.<span style="color: #0066CC;">start</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<p>That code does this -> First we define two different functions, blah and blah2. Then we push the functions to be executed into the queue. Here&#8217;s the interesting part. <s>Since the Dictionary Object inside the class used to list functions is not weakly referenced</s> Duplicate entries cannot be made by the same function regardless of it&#8217;s parameters. In the the example above I push blah into the queue three times, but the only one that fires and traces is the third because the queue&#8217;s key is the function itself [or the "closure object (ie. the "behind the scenes" object that facilitates method closure by maintaining a reference back to the method and its scope)" as described by <a href="http://gskinner.com/blog/archives/2006/07/as3_dictionary.html">Grant Skinner</a>], so the function replaces itself in the queue. This is nice for doing things like setting widths and resizing, although not so great for things like sending different strings to some handler. As of now calling start() applies the functions asynchronously and nullifies anything left in the queue. You&#8217;ll see the output traces this:</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">object</span> <span style="color: #66cc66;">&#91;</span>Queue<span style="color: #66cc66;">&#93;</span><br />
-<span style="color: #66cc66;">&gt;</span>&nbsp; <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #000000; font-weight: bold;">Function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span> &nbsp;3,5<br />
-<span style="color: #66cc66;">&gt;</span>&nbsp; <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #000000; font-weight: bold;">Function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span> &nbsp;<span style="color: #cc66cc;">4</span>,<span style="color: #cc66cc;">5</span><br />
<span style="color: #cc66cc;">8</span><br />
<span style="color: #cc66cc;">9</span></div></div>
<p>First it traces the Queue Object which contains references to the two functions and their parameters (not in the order we gave them) then the output. Bam! Done. Oops! Not quite&#8230; &#8230;At any point you can flush the queue without executing the functions by calling abort(). There, done.</p>
<p>This class can be easily extended or modified to include directives to execute functions in a given order or multiple entries of one function, so get crackin!</p>
<p><b>Source</b><br />
<a href='http://blog.efnx.com/wp-content/uploads/2007/12/blogefnxcom-queue.zip' title='Queue Class Source Code'>Queue Class Source Code</a></p>
]]></content:encoded>
			<wfw:commentRss>http://efnx.com/as3-dolatertodo-function-queue/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
