<?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>Tue, 15 May 2012 17:46:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Bang Pre-Alpha</title>
		<link>http://efnx.com/bang-pre-alpha/</link>
		<comments>http://efnx.com/bang-pre-alpha/#comments</comments>
		<pubDate>Sat, 12 May 2012 20:27:21 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[WebGL]]></category>

		<guid isPermaLink="false">http://efnx.com/?p=393</guid>
		<description><![CDATA[I have a new ongoing project, it&#8217;s called Bang. It&#8217;s a canvas-tag based display list written in Javascript. I&#8217;m going to be using it in place of AS3/Flash in my web authoring tool chain. Bang on Github. There are three main elements of Bang that make it special: Modules When writing a project with Bang [...]]]></description>
			<content:encoded><![CDATA[<p>I have a new ongoing project, it&#8217;s called Bang. It&#8217;s a canvas-tag based display list written in Javascript. I&#8217;m going to be using it in place of AS3/Flash in my web authoring tool chain. <a href="http://schell.github.com/bang" title="Bang on Github" target="_blank">Bang on Github</a>. There are three main elements of Bang that make it special:</p>
<h3>Modules</h3>
<p>When writing a project with Bang you keep your code separated in modules. Each module exposes a Javascript Object, like a constructor function. The modules object is passed into each module definition, exposing your module to other modules that depend on it. Keeping your code in modules like this means you need only expose one global variable, the list of modules. Any modules loaded this way are essentially sandboxed in that modules object.<br />
You define a module in a similar manner to <a href="http://requirejs.org/" title="RequireJS" target="_blank">RequireJS</a> and the <a href="https://github.com/amdjs/amdjs-api/wiki/AMD" title="Asynchronous Module Definition" target="_blank">AMD</a>:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">mod<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">name</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">'MyObject'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; dependencies <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span> <span style="color: #3366CC;">'bang::Geometry/Rectangle.js'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'myLib::SomeFile.js'</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; init <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span> initMyObject<span style="color: #009900;">&#40;</span>modules<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">function</span> MyObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">x</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">y</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; MyObject.<span style="color: #660066;">prototype</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; MyObject.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">constructor</span> <span style="color: #339933;">=</span> MyObject<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> MyObject<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>The module system is another project of mine called <a href="http://schell.github.com/mod" title="Mod on Github" target="_blank">Mod</a>. I&#8217;ve written about it before. It&#8217;s very small and simple and it gets the job done (the job of code separation and later compilation).<br />
Bang adds support for Google&#8217;s Closure Compiler to Mod, so once your project is ready to ship you can compile (in a sense), compress, obfuscate and pack your code down into a deployable script or a neato mosquito PNG. I like the PNG method because it&#8217;s slightly more obfuscated and adds further sandboxing, but that&#8217;s a topic for a later post.</p>
<h3>It&#8217;s like Flash, but not too much like Flash&#8230;</h3>
<p>Bang is enough like Flash/AS3 to be familiar, but sacrifices some AS3 similarities in exchange for simplicity and consistency. The complexity in Bang is very small. There aren&#8217;t any tricks to make it more Flash-like than it has to be and it won&#8217;t protect you from learning canvas operations. In fact, you&#8217;ll have to learn about the <a href="https://developer.mozilla.org/en/DOM/CanvasRenderingContext2D" title="CanvasRenderingContext2D documentation at Mozilla" target="_blank">CanvasRenderingContext2D</a> to do any real drawing. I&#8217;m not aliasing those calls and hiding it in a mock <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Graphics.html" title="Graphics documentation on Adobe Labs" target="_blank">Graphics</a> object for you! <img src='http://efnx.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  And you should be learning these new technologies without crutches. Think of Bang not as a set of crutches, but as a set of wings, or at least a hammer and chisel. No one likes masonry-by-hand.</p>
<h3>It is fast.</h3>
<p>The original pre-alpha version of Bang takes <a href="https://en.wikipedia.org/wiki/Douglas_Crockford" title="Douglas Crockford on Wikipedia" target="_blank">Douglas Crockford</a>&#8216;s extremism literally. There are no uses of the keywords &#8216;this&#8217; or &#8216;new&#8217;. It accomplishes (multiple) inheritance through special constructor functions that add functions and closures to objects (or creates new ones). This, although a departure from AS3 at first, actually gives projects written in Bang an AS3++ feel. Multiple inheritance is awesome. Private variables are awesome. With <a href="http://javascript.crockford.com/prototypal.html" title="Prototypal Inheritance - Douglas Crockford" target="_blank">prototypal inheritance</a> you lose private variables so by using special constructor functions <a href="https://gist.github.com/321279" title="Private methods and variables in Javascript - Github Gist" target="_blank">we can create private variables through closures</a>. These features are awesome, but as Martin Hunt of <a href="http://gameclosure.com/" title="GameClosure" target="_blank">GameClosure</a> pointed out to me, it&#8217;s not fast. Processing time will go up linearly with the number of properties and methods created in the class. This means that if you&#8217;re creating a lot of complex game objects every frame tick, the project will likely start chugging. This is not fast. Apps have to be fast! For this reason I started <a href="https://github.com/schell/bang/tree/prototypal" title="Prototypal branch of Bang on Github" target="_blank">a new branch of Bang that uses traditional prototypal inheritance</a>. This branch will include a dirty rectangles implementation for really lazy redrawing, and I have plans for using WebGL for rendering down the line. Stay tuned!</p>
<h3>A tiny demo</h3>
<div id="bang_demo">
    Take a look at the source for this div. This is the compiled output of the main branch of Bang. It&#8217;s clean, right?!</p>
<div class="bang" data-source="http://efnx.com/wp-content/uploads/2012/05/xor.png"></div>
<p>    <br />
    <script src="http://schell.github.com/bang/bang.js" type="text/javascript" charset="utf-8" onload="bang()"></script><br />
    
</div>
</p>
<pre style="font:13px/1.4em Monaco, Lucida Console, monospace; background:#1d021d; color:#8d92f7;">
<--- __
    |  |__ ___ _ _____ _____
    |  _  |  _  |     |  _  |
    |_____|___!_|__!__|___  |
                      |_____|
    you know, for javascripts-->
</pre>
<p>
]]></content:encoded>
			<wfw:commentRss>http://efnx.com/bang-pre-alpha/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AS3 – Creating a Convex Polygon from Unordered Points</title>
		<link>http://efnx.com/as3-creating-a-convex-polygon-from-unordered-points/</link>
		<comments>http://efnx.com/as3-creating-a-convex-polygon-from-unordered-points/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 23:24:58 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[graphics]]></category>

		<guid isPermaLink="false">http://blog.efnx.com/?p=215</guid>
		<description><![CDATA[Let&#8217;s pretend you have an application that lets users create shapes to be used in a physics simulation and that the user must click on the screen to set the vertices of the shape. Many physics engines only support convex polygons, or shapes that don&#8217;t have inlets, bites, or coves, basically shapes that don&#8217;t have [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s pretend you have an application that lets users create shapes to be used in a <a href="http://www.box2d.org/">physics simulation</a> and that the user must click on the screen to set the vertices of the shape. Many physics engines only support <a href="http://en.wikipedia.org/wiki/Convex_and_concave_polygons">convex polygons</a>, or shapes that don&#8217;t have inlets, bites, or coves, basically shapes that don&#8217;t have inward facing edges. With this limitation we have to be able to restrict [read as "guide"] the user to make only convex polygons. For this we are going to need an algorithm that takes an unordered set of points and finds the <a href="http://en.wikipedia.org/wiki/Convex_hull">convex hull</a> that encloses those points. This way the user can click and add points at random, if desired, and your program will keep track of what points create a convex polygon, while the others are thrown away [or dealt with however you see fit].</p>
<p><strong><a href="http://www.cs.princeton.edu/courses/archive/spr09/cos226/demo/ah/GrahamScan.html">The Graham Scan Algorithm</a></strong> is a process of ordering a random set of points and then calculating jumps to the points in that set that constitute a convex polygon. In this algorithm there are three steps. First is to find a corner point, usually the topmost, leftmost point in the set. The second step is to order all other points by the polar angle between the corner point and the point in question. The last step is to traverse the set, taking each proceeding subset of three points (n, n-1, n-2) to determine whether the angle made by these three points is a left turn, right turn, or a straight line. If the turn made is our desired turn [which is usually left - but in Flash it's right, due to the flipped y-axis] then we add that point to the convex hull. If the turn is not our desired turn, we get rid of that point and move on. </p>
<p>Here is an example that shows first the data set drawn from point to point. Each successive line gets progressively whiter. In the second step we find the corner point, order the other points and then show the outer polygon.<br />
<div id="attachment_216" class="wp-caption aligncenter" style="width: 466px"><a href="http://blog.efnx.com/wp-content/uploads/2009/09/Screen-shot-2009-09-21-at-4.11.10-PM.png" rel="lightbox"><img src="http://blog.efnx.com/wp-content/uploads/2009/09/Screen-shot-2009-09-21-at-4.11.10-PM.png" alt="Example" title="Graham Scan Example" width="456" height="224" class="size-full wp-image-216" /></a><p class="wp-caption-text">Example</p></div></p>
<p>Here&#8217;s the code for the class:</p>
<div class="codecolorer-container actionscript3 twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #3f5fbf;">/**<br />
&nbsp;*&nbsp; Use this class freely - 2009 blog.efnx.com<br />
&nbsp;*/</span><br />
<br />
<span style="color: #9900cc; font-weight: bold;">package</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.geom</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=point%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:point.html"><span style="color: #004993;">Point</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> GrahamScan <span style="color: #0033ff; font-weight: bold;">extends</span> <a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html"><span style="color: #004993;">Object</span></a><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #3f5fbf;">/**<br />
&nbsp; &nbsp; &nbsp;*&nbsp; The Graham scan is a method of computing the convex hull of a finite set of points <br />
&nbsp; &nbsp; &nbsp;* &nbsp;in the plane with time complexity O(n log n). It is named after Ronald Graham, who <br />
&nbsp; &nbsp; &nbsp;* &nbsp;published the original algorithm in 1972. The algorithm finds all vertices of <br />
&nbsp; &nbsp; &nbsp;* &nbsp;the convex hull ordered along its boundary. It may also be easily modified to report <br />
&nbsp; &nbsp; &nbsp;* &nbsp;all input points that lie on the boundary of their convex hull.<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> GrahamScan<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #3f5fbf;">/**<br />
&nbsp; &nbsp; &nbsp;*&nbsp; Returns a convex hull given an unordered array of points.<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> convexHull<span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> findHull<span style="color: #000000;">&#40;</span> order<span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #3f5fbf;">/**<br />
&nbsp; &nbsp; &nbsp;*&nbsp; Orders an array of points counterclockwise.<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> order<span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;GrahamScan::order()&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// first run through all the points and find the upper left [lower left]</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> p<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=point%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:point.html"><span style="color: #004993;">Point</span></a> = <span style="color: #004993;">data</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> n<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a> &nbsp; = <span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a> = <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&lt;</span> n<span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//trace(&quot; &nbsp; p:&quot;,p,&quot;d:&quot;,data[i]);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">&lt;</span> p<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//trace(&quot; &nbsp; d.y &lt; p.y / d is new p.&quot;);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p = <span style="color: #004993;">data</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> == p<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">&amp;&amp;</span> <span style="color: #004993;">data</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">&lt;</span> p<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//trace(&quot; &nbsp; d.y == p.y, d.x &lt; p.x / d is new p.&quot;);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p = <span style="color: #004993;">data</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// next find all the cotangents of the angles made by the point P and the</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// other points</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> sorted&nbsp; <span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// we need arrays for positive and negative values, because Array.sort</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// will put sort the negatives backwards.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> pos &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> neg &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// add points back in order</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>i = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&lt;</span> n<span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> a &nbsp; <span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> = <span style="color: #004993;">data</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">-</span> p<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">b</span> &nbsp; <span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> = <span style="color: #004993;">data</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">-</span> p<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> cot <span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> = <span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">/</span>a<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>cot <span style="color: #000066; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; neg<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#123;</span>point<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">data</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> cotangent<span style="color: #000066; font-weight: bold;">:</span>cot<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pos<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#123;</span>point<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">data</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> cotangent<span style="color: #000066; font-weight: bold;">:</span>cot<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// sort the arrays</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pos<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sortOn</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;cotangent&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">NUMERIC</span> <span style="color: #000066; font-weight: bold;">|</span> <a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">DESCENDING</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; neg<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sortOn</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;cotangent&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">NUMERIC</span> <span style="color: #000066; font-weight: bold;">|</span> <a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">DESCENDING</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; sorted = neg<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">concat</span><span style="color: #000000;">&#40;</span>pos<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> ordered <span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ordered<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>p<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>i = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&lt;</span> n<span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>p == sorted<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>point<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">continue</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ordered<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>sorted<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>point<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> ordered<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #3f5fbf;">/**<br />
&nbsp; &nbsp; &nbsp;*&nbsp; Given an array of points ordered counterclockwise, findHull will <br />
&nbsp; &nbsp; &nbsp;* &nbsp;filter the points and return an array containing the vertices of a<br />
&nbsp; &nbsp; &nbsp;* &nbsp;convex polygon that envelopes those points.<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> findHull<span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;GrahamScan::findHull()&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> n &nbsp; <span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a> &nbsp; &nbsp;= <span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> hull<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a>&nbsp; = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hull<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// add the pivot</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hull<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// makes first vector</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a> = <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&lt;</span> n<span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">while</span><span style="color: #000000;">&#40;</span>direction<span style="color: #000000;">&#40;</span>hull<span style="color: #000000;">&#91;</span>hull<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> hull<span style="color: #000000;">&#91;</span>hull<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">data</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">&gt;</span>= <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hull<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">pop</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hull<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> hull<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #3f5fbf;">/**<br />
&nbsp; &nbsp; &nbsp;*<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> static <span style="color: #339966; font-weight: bold;">function</span> direction<span style="color: #000000;">&#40;</span>p1<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=point%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:point.html"><span style="color: #004993;">Point</span></a><span style="color: #000066; font-weight: bold;">,</span> p2<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=point%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:point.html"><span style="color: #004993;">Point</span></a><span style="color: #000066; font-weight: bold;">,</span> p3<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=point%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:point.html"><span style="color: #004993;">Point</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// &gt; 0 &nbsp;is right turn</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// == 0 is collinear</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// &lt; 0 &nbsp;is left turn</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// we only want right turns, usually we want right turns, but</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// flash's grid is flipped on y.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #000000;">&#40;</span>p2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">-</span> p1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000;">&#40;</span>p3<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">-</span> p1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000000;">&#40;</span>p2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">-</span> p1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000;">&#40;</span>p3<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">-</span> p1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #000000;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://efnx.com/as3-creating-a-convex-polygon-from-unordered-points/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<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><span style="color: #cc66cc;">1</span><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, <span style="color: #cc66cc;">1</span><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, <span style="color: #cc66cc;">1</span><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> = <span style="color: #cc66cc;">8</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: #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> = <span style="color: #cc66cc;">1</span> + <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">/</span><span style="color: #66cc66;">&#40;</span>numPoints<span style="color: #66cc66;">*</span><span style="color: #cc66cc;">1.75</span><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-<span style="color: #cc66cc;">0.5</span><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><span style="color: #cc66cc;">50</span>, <span style="color: #cc66cc;">50</span>, <span style="color: #cc66cc;">50</span>, _path, <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>;<br />
r_addCircle<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">150</span>, <span style="color: #cc66cc;">50</span>, <span style="color: #cc66cc;">50</span>, _path, <span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span>;<br />
r_addCircle<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">250</span>, <span style="color: #cc66cc;">50</span>, <span style="color: #cc66cc;">50</span>, _path, <span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span>;<br />
r_addCircle<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">350</span>, <span style="color: #cc66cc;">50</span>, <span style="color: #cc66cc;">50</span>, _path, <span style="color: #cc66cc;">8</span><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>3</slash:comments>
		</item>
		<item>
		<title>Pure Actionscript 3 Window Class</title>
		<link>http://efnx.com/pure-actionscript-3-window-class/</link>
		<comments>http://efnx.com/pure-actionscript-3-window-class/#comments</comments>
		<pubDate>Fri, 14 Nov 2008 04:01:01 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[windowing]]></category>

		<guid isPermaLink="false">http://blog.efnx.com/?p=107</guid>
		<description><![CDATA[I&#8217;ve been working on an easily skinnable windowing system, and this is what I have so far. I&#8217;ve attempted to mimic mac&#8217;s theme for Leopard. The source and documentation are in their usual spots -> My classes. I&#8217;ll be updating them pretty regularly. Here&#8217;s the source for the project itself -> project source]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on an easily skinnable windowing system, and this is what I have so far. I&#8217;ve attempted to mimic mac&#8217;s theme for Leopard.</p>
<p><center><div id="attachment_108" class="wp-caption aligncenter" style="width: 510px"><a href="http://efnx.com/lab/Windows"><img src="http://blog.efnx.com/wp-content/uploads/2008/11/windowsteaser.png" alt="Actionscript 3 Leopard GUI" title="AS3 Window Class Teaser Photo" width="500" height="239" class="size-full wp-image-108" /></a><p class="wp-caption-text">Actionscript 3 Leopard GUI</p></div></center></p>
<p>The source and documentation are in their usual spots -> <a href="http://blog.efnx.com/classes">My classes.</a> I&#8217;ll be updating them pretty regularly. Here&#8217;s the source for the project itself -> <a href="http://efnx.com/lab/Windows/Windows_Main_081113.tar.gz">project source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://efnx.com/pure-actionscript-3-window-class/feed/</wfw:commentRss>
		<slash:comments>8</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>39</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&#8242;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>9</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 [...]]]></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><span style="color: #cc66cc;">50</span>, <span style="color: #cc66cc;">20</span>, <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><span style="color: #cc66cc;">50</span>, <span style="color: #cc66cc;">20</span>, <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><span style="color: #cc66cc;">50</span>, <span style="color: #cc66cc;">20</span>, <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><span style="color: #cc66cc;">2</span> - 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><span style="color: #cc66cc;">2</span> - 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>, <span style="color: #cc66cc;">0</span>, <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>, <span style="color: #cc66cc;">0</span>, <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>, <span style="color: #cc66cc;">0</span>, <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>, <span style="color: #cc66cc;">0</span>, <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><span style="color: #cc66cc;">100</span><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><span style="color: #cc66cc;">100</span><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>, <span style="color: #cc66cc;">0</span>, <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><span style="color: #cc66cc;">50</span>, <span style="color: #cc66cc;">20</span>, <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><span style="color: #cc66cc;">50</span>, <span style="color: #cc66cc;">20</span>, <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><span style="color: #cc66cc;">50</span>, <span style="color: #cc66cc;">20</span>, <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><span style="color: #cc66cc;">2</span> - 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><span style="color: #cc66cc;">2</span> - 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>, <span style="color: #cc66cc;">0</span>, <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>, <span style="color: #cc66cc;">0</span>, <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><span style="color: #cc66cc;">100</span><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>17</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&#8242;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&#8242;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 [...]]]></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>
	</channel>
</rss>

