<?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; FPS</title>
	<atom:link href="http://efnx.com/tag/fps/feed/" rel="self" type="application/rss+xml" />
	<link>http://efnx.com</link>
	<description>code. blog.</description>
	<lastBuildDate>Wed, 18 Jan 2012 20:48:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<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>AS3 &#8211; Calculating true Frames Per Second</title>
		<link>http://efnx.com/as3-calculating-true-frames-per-second/</link>
		<comments>http://efnx.com/as3-calculating-true-frames-per-second/#comments</comments>
		<pubDate>Mon, 22 Oct 2007 19:01:36 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[com.efnx]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[FPS]]></category>
		<category><![CDATA[frames per second]]></category>
		<category><![CDATA[Stage.frameRate]]></category>

		<guid isPermaLink="false">http://blog.efnx.com/?p=13</guid>
		<description><![CDATA[I strongly recommend you look at this new version of this class. When coding for Flash based games it&#8217;s important to know how fast your project is running [even if you're not coding games it's good to know whether or not your code is slogging down the player]. Adobe&#8217;s Stage class provides a parameter called [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.efnx.com/?p=55">I strongly recommend you look at this new version of this class.</a> </p>
<p>When coding for Flash based games it&#8217;s important to know how fast your project is running [even if you're not coding games it's good to know whether or not your code is slogging down the player]. Adobe&#8217;s Stage class provides a parameter called &#8220;frameRate,&#8221; which allows you to dynamically get and set the player&#8217;s frame rate. Well, not exactly. It allows you to get and set the player&#8217;s TARGET frame rate, the fact is if the player can&#8217;t perform your code at that frame rate, it won&#8217;t! So how can you find out what the real frame rate is? </p>
<p>I wrote a simple class for this task to use in my project development. It&#8217;s super simple. My class, fpsBox, adds an eventListener to the stage [if you pass the stage as an argument when instantiating the class] or to itself, that triggers every frame and increments a value. A timer is started simultaneously with a repeat cycle of one second. Every second the number of counts counted each frame are displayed in the fpsBox and then averaged in an array of instantaneous values. Don&#8217;t worry, the array never gets past two values, the current average and the instantaneous FPS. Here&#8217;s some usage:</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;">import</span> com.<span style="color: #006600;">efnx</span>.<span style="color: #0066CC;">fps</span>.<span style="color: #006600;">fpsBox</span>;<br />
<br />
<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: #0066CC;">stage</span><span style="color: #66cc66;">&#41;</span>;<br />
&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>That&#8217;s it!</p>
<p><b>What it looks like:</b><br />
<iframe src="http://blog.efnx.com/wp-content/uploads/2007/10/fpsExample.html" width="100%"></iframe><br />
<a href='http://blog.efnx.com/wp-content/uploads/2007/10/fpsExample.swf' title='fpsBox example'>Link to SWF</a></p>
<p><b>Source Code</b><br />
<a href='http://blog.efnx.com/wp-content/uploads/2007/10/blogefnxcom-fpsbox.zip' title='fpsBox Class Source Code'>fpsBox Class Source Code</a></p>
]]></content:encoded>
			<wfw:commentRss>http://efnx.com/as3-calculating-true-frames-per-second/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>AS3 Animation class to replace MovieClip</title>
		<link>http://efnx.com/as3-animation-class-to-replace-movieclip/</link>
		<comments>http://efnx.com/as3-animation-class-to-replace-movieclip/#comments</comments>
		<pubDate>Mon, 15 Oct 2007 20:14:42 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[Animation]]></category>
		<category><![CDATA[FPS]]></category>
		<category><![CDATA[MovieClip]]></category>
		<category><![CDATA[resources]]></category>

		<guid isPermaLink="false">http://blog.efnx.com/?p=10</guid>
		<description><![CDATA[Okay, let me start by saying that I HATE importing resources into fla&#8217;s. When I first learned Flash [AS2] it wasn&#8217;t an issue. Now with AS3 and the necessity of classes my coding style has changed and I really, really like keeping things as separated into classes as possible. The Problem With MovieClips When attempting [...]]]></description>
			<content:encoded><![CDATA[<p>Okay, let me start by saying that I HATE importing resources into fla&#8217;s. When I first learned Flash [AS2] it wasn&#8217;t an issue. Now with AS3 and the necessity of classes my coding style has changed and I really, really like keeping things as separated into classes as possible. </p>
<p><strong>The Problem With MovieClips</strong><br />
When attempting to program button classes I ran into this wall: Flash&#8217;s MovieClip is the only appropriate class object to use for animation. It&#8217;s great for placing images in your timeline to form moving pictures and placing Actionscript on certain frames makes directing the clip around really easy. But what about when you have to make MovieClips dynamically and add code to certain frames inside that clip, without using the GUI? MovieClip doesn&#8217;t support dynamically adding frames, or functions or Bitmaps to certain frames. This sucks. Why Adobe did this I do not know &#8211; so I wrote a class that DOES WHAT I WANT [and maybe you too].</p>
<p><strong>Usage</strong><br />
Animation takes three parameters, which are all optional: numFrames:int = 1 width:int = 0, and height:int = 0. These params just initiate the object.</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: #808080; font-style: italic;">/*<br />
* &nbsp; &nbsp; blog.efnx.com:Animation Example<br />
*/</span><br />
<br />
<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">efnx</span>.<span style="color: #006600;">utils</span>.<span style="color: #006600;">Animation</span>; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//import the class</span><br />
<br />
<span style="color: #000000; font-weight: bold;">var</span> character:Animation = <span style="color: #000000; font-weight: bold;">new</span> Animation<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//object sets numFrames, width and height to 1, 0 and 0</span></div></div>
<p>After making the object you have to append the pictures to certain frames using the appendBitmapData function:</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">character.<span style="color: #006600;">appendBitmapData</span><span style="color: #66cc66;">&#40;</span>theFrame:<span style="color: #0066CC;">int</span>, bitmapData:BitmapData<span style="color: #66cc66;">&#41;</span>;</div></div>
<p>What this does is take the BitmapData and attach a function to the given frame that replaces the Animation&#8217;s default BitmapData with yours upon execution of that frame.<br />
Doing this achieves the same effect as dragging a bitmap onto the stage in a MovieClip keyframe.</p>
<p>I wrote the class keeping in mind that someone may want to use it not for animation but sequential code execution, so frames can be created and functions attached to each frame without any graphics associated. The function used to add [or append] other functions to a certain frame is</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;appendFrameScript<span style="color: #66cc66;">&#40;</span>theFrame:<span style="color: #0066CC;">int</span>, theFunction:<span style="color: #000000; font-weight: bold;">Function</span>, <span style="color: #66cc66;">&#91;</span>testing:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<p>theFrame is the frame you&#8217;d like to add a function to, theFunction is the function to be added and testing tells the class whether or not to print debug info.</p>
<p>After adding frames and bitmaps and all that Animation can be controlled using familiar MovieClip methods like gotoAndPlay(), gotoAndStop(), go(), stop() and properties like currentFrame and totalFrames, as well as some others &#8211; bmd [the current frames BitmapData], bmdArray [an array of all frames BitmapData] and cool functions like customFps(fps:int) which set a custom playback rate denoted in number of frames per second [fps:int] and accelerateFps(desiredFps:int, numberFrames:int) which accelerates the playback delay from the current FPS to the desired FPS in numberFrames frames. accelerateFps is still a little buggy, feel free to nice it up!</p>
<p><strong>Last Words</strong><br />
Animation doesn&#8217;t automatically loop your animation [since I usually don't need it to], so to really mimic a MovieClip you&#8217;d have to write a function incorporating gotoAndPlay(1) and then attach the function to the frame you&#8217;d like to loop your clip at:</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> character:Animation = <span style="color: #000000; font-weight: bold;">new</span> Animation<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//initiate object</span><br />
&nbsp; &nbsp; &nbsp;character.<span style="color: #006600;">appendBitmapData</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>, firstBitmapData<span style="color: #66cc66;">&#41;</span>; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//add BitmapData</span><br />
&nbsp; &nbsp; &nbsp;character.<span style="color: #006600;">appendBitmapData</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span>, secondBitmapData<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp;character.<span style="color: #006600;">appendFrameScript</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span>, repeat<span style="color: #66cc66;">&#41;</span>; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//append repeat function</span><br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> repeat<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">//repeat function</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;character.<span style="color: #0066CC;">gotoAndPlay</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>Hope this class helps some of you out. Feel free to let me know what needs improving and comment if you like it!</p>
<p><strong>Source</strong><br />
<a href='http://blog.efnx.com/wp-content/uploads/2007/10/blogefnxcom-animation.zip' title='Animation Class Source Code'>Animation Class Source Code</a></p>
]]></content:encoded>
			<wfw:commentRss>http://efnx.com/as3-animation-class-to-replace-movieclip/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

