<?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>Thumbleaf</title>
	<atom:link href="http://www.thumbleaf.com/journal/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.thumbleaf.com/journal</link>
	<description>sampling flash &#38; creativity</description>
	<lastBuildDate>Sat, 07 Aug 2010 20:46:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>EventCurb.as , removeAllListeners(object)</title>
		<link>http://www.thumbleaf.com/journal/?p=268</link>
		<comments>http://www.thumbleaf.com/journal/?p=268#comments</comments>
		<pubDate>Sun, 01 Aug 2010 02:51:38 +0000</pubDate>
		<dc:creator>Thomas</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[EventManagement]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Event Management]]></category>

		<guid isPermaLink="false">http://www.thumbleaf.com/journal/?p=268</guid>
		<description><![CDATA[In AS3 we can check if an object has listeners, as in: <tt>if( object.hasEventListener( type ))</tt>. 
But there is no method for getting all the listeners of an object. Or more importantly for removing all of them.]]></description>
			<content:encoded><![CDATA[<p>In AS3 we can check if an object has listeners, as in: <tt>if( object.hasEventListener( type ))</tt>.<br />
But there is no method for getting all the listeners of an object. Or more importantly for removing all of them. Doh.</p>
<p>The hackish approach to this is to subclass EventDispatcher and write some short code that keeps a reference to each listener.</p>
<p>Which is what my class EventCurb does. &#8211; I should say it&#8217;s written overnight so anyone that likes can go ahead and try break their application&#8230;</p>
<p>Usage is as Singleton:</p>
<div class="codecolorer-container actionscript3 mac-classic" style="border: 1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #6699cc; font-weight: bold;">var</span> _ev<span style="color: #000066; font-weight: bold;">:</span> EventCurb = EventCurb<span style="color: #000066; font-weight: bold;">.</span>getInstance<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></td></tr></tbody></table></div>
<p>To add listener:</p>
<div class="codecolorer-container actionscript3 mac-classic" style="border: 1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_ev<span style="color: #000066; font-weight: bold;">.</span>addListener<span style="color: #000000;">&#40;</span>obj<span style="color: #000066; font-weight: bold;">,</span> <a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_DOWN</span><span style="color: #000066; font-weight: bold;">,</span> someFunc<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_ev<span style="color: #000066; font-weight: bold;">.</span>addListener<span style="color: #000000;">&#40;</span>obj<span style="color: #000066; font-weight: bold;">,</span> <a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_UP</span><span style="color: #000066; font-weight: bold;">,</span> someFunc<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></td></tr></tbody></table></div>
<p>If you try to add the same listener twice you will get a trace telling you that listener is already added, and no addition occurs.</p>
<p>                         To get all listeners of an object:</p>
<div class="codecolorer-container actionscript3 mac-classic" style="border: 1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_ev<span style="color: #000066; font-weight: bold;">.</span>getListeners<span style="color: #000000;">&#40;</span>obj<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></td></tr></tbody></table></div>
<p>This returns an Array of all listeners assigned to object which can be traversed as <tt>arr[index].type, arr[index].listener</tt>.</p>
<p>                         To remove listener of object:</p>
<div class="codecolorer-container actionscript3 mac-classic" style="border: 1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_ev<span style="color: #000066; font-weight: bold;">.</span>removeListener<span style="color: #000000;">&#40;</span>obj<span style="color: #000066; font-weight: bold;">,</span> <a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_DOWN</span><span style="color: #000066; font-weight: bold;">,</span> someFunc<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_ev<span style="color: #000066; font-weight: bold;">.</span>removeListener<span style="color: #000000;">&#40;</span>obj<span style="color: #000066; font-weight: bold;">,</span> <a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_UP</span><span style="color: #000066; font-weight: bold;">,</span> someFunc<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></td></tr></tbody></table></div>
<p>And finally to remove All listeners of an object:</p>
<div class="codecolorer-container actionscript3 mac-classic" style="border: 1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_ev<span style="color: #000066; font-weight: bold;">.</span>removeAllListeners<span style="color: #000000;">&#40;</span>obj<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></td></tr></tbody></table></div>
<p>You can copy the class from below or download it from <a href="http://thumbleaf.com/blogassets/zip/EventCurb.zip">here</a>. Feel free to rewrite or improve upon as you so wish.</p>
<p><strong>EventCurb.as</strong></p>
<div class="codecolorer-container actionscript3 mac-classic" style="border: 1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><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.events</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=eventdispatcher%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:eventdispatcher.html"><span style="color: #004993;">EventDispatcher</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp;<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.utils</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=dictionary%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:dictionary.html"><span style="color: #004993;">Dictionary</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp;<span style="color: #3f5fbf;">/**<br />
&nbsp; &nbsp; * ...<br />
&nbsp; &nbsp; * @author Thomas James Thorstensson<br />
&nbsp; &nbsp; * @version 1.0.1<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp;<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> EventCurb <span style="color: #0033ff; font-weight: bold;">extends</span> <a href="http://www.google.com/search?q=eventdispatcher%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:eventdispatcher.html"><span style="color: #004993;">EventDispatcher</span></a><br />
&nbsp; &nbsp;<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> static <span style="color: #6699cc; font-weight: bold;">var</span> instance<span style="color: #000066; font-weight: bold;">:</span>EventCurb= <span style="color: #0033ff; font-weight: bold;">new</span> EventCurb<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> objDict<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=dictionary%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:dictionary.html"><span style="color: #004993;">Dictionary</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=dictionary%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:dictionary.html"><span style="color: #004993;">Dictionary</span></a><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _listener<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=function%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:function.html"><span style="color: #004993;">Function</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> objArr<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><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> obj<span style="color: #000066; font-weight: bold;">:</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><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> EventCurb<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> instance <span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">throw</span> <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=error%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:error.html"><span style="color: #004993;">Error</span></a><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;Singleton and can only be accessed through Singleton.getInstance()&quot;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> getInstance<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span>EventCurb <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0033ff; font-weight: bold;">return</span> instance<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; override <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">type</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000066; font-weight: bold;">,</span> listener<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=function%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:function.html"><span style="color: #004993;">Function</span></a><span style="color: #000066; font-weight: bold;">,</span> useCapture<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=boolean%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:boolean.html"><span style="color: #004993;">Boolean</span></a> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> priority<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> = 0<span style="color: #000066; font-weight: bold;">,</span> useWeakReference<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=boolean%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:boolean.html"><span style="color: #004993;">Boolean</span></a> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">type</span><span style="color: #000066; font-weight: bold;">,</span> listener<span style="color: #000066; font-weight: bold;">,</span> useCapture<span style="color: #000066; font-weight: bold;">,</span> priority<span style="color: #000066; font-weight: bold;">,</span> useWeakReference<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; override <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">type</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000066; font-weight: bold;">,</span> listener<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=function%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:function.html"><span style="color: #004993;">Function</span></a><span style="color: #000066; font-weight: bold;">,</span> useCapture<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=boolean%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:boolean.html"><span style="color: #004993;">Boolean</span></a> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">type</span><span style="color: #000066; font-weight: bold;">,</span> listener<span style="color: #000066; font-weight: bold;">,</span> useCapture<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> addListener<span style="color: #000000;">&#40;</span>o<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=eventdispatcher%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:eventdispatcher.html"><span style="color: #004993;">EventDispatcher</span></a><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">type</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000066; font-weight: bold;">,</span> listener<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=function%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:function.html"><span style="color: #004993;">Function</span></a><span style="color: #000066; font-weight: bold;">,</span> useCapture<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=boolean%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:boolean.html"><span style="color: #004993;">Boolean</span></a> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> priority<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> = 0<span style="color: #000066; font-weight: bold;">,</span> useWeakReference<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=boolean%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:boolean.html"><span style="color: #004993;">Boolean</span></a> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900; font-style: italic;">// the object as key for an array of its event types</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>objDict<span style="color: #000000;">&#91;</span>o<span style="color: #000000;">&#93;</span> == <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> &nbsp;objArr = objDict<span style="color: #000000;">&#91;</span>o<span style="color: #000000;">&#93;</span> = <span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &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;">0</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&lt;</span> &nbsp;objArr<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <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> objArr<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;">type</span> == <span style="color: #004993;">type</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;_______object already has this listener not adding!&quot;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;obj = <span style="color: #000000;">&#123;</span> <span style="color: #004993;">type</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">type</span><span style="color: #000066; font-weight: bold;">,</span> listener<span style="color: #000066; font-weight: bold;">:</span>listener <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;objArr<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>obj<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;o<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">type</span><span style="color: #000066; font-weight: bold;">,</span> listener<span style="color: #000066; font-weight: bold;">,</span> useCapture<span style="color: #000066; font-weight: bold;">,</span> priority<span style="color: #000066; font-weight: bold;">,</span> useWeakReference<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> removeListener<span style="color: #000000;">&#40;</span>o<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=eventdispatcher%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:eventdispatcher.html"><span style="color: #004993;">EventDispatcher</span></a><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">type</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000066; font-weight: bold;">,</span> listener<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=function%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:function.html"><span style="color: #004993;">Function</span></a><span style="color: #000066; font-weight: bold;">,</span> useCapture<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=boolean%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:boolean.html"><span style="color: #004993;">Boolean</span></a> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900; font-style: italic;">// if the object has listeners (ie exists in dictionary)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>objDict<span style="color: #000000;">&#91;</span>o<span style="color: #000000;">&#93;</span> <span style="color: #0033ff; font-weight: bold;">as</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: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> tmpArr<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;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tmpArr = objDict<span style="color: #000000;">&#91;</span>o<span style="color: #000000;">&#93;</span> <span style="color: #0033ff; font-weight: bold;">as</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><br />
&nbsp; &nbsp; &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;">0</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&lt;</span> tmpArr<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>tmpArr<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;">type</span> == <span style="color: #004993;">type</span><span style="color: #000000;">&#41;</span> objArr<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">splice</span><span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; o<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">type</span><span style="color: #000066; font-weight: bold;">,</span> listener<span style="color: #000066; font-weight: bold;">,</span> useCapture<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;">if</span> <span style="color: #000000;">&#40;</span>tmpArr<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> == 0<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0033ff; font-weight: bold;">delete</span> objDict<span style="color: #000000;">&#91;</span>o<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;_______object has no listeners&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp;* If object has listeners, returns an Array which can be accessed<br />
&nbsp; &nbsp; &nbsp; &nbsp;* as array[index].type,array[index].listeners<br />
&nbsp; &nbsp; &nbsp; &nbsp;* @param &nbsp; o<br />
&nbsp; &nbsp; &nbsp; &nbsp;* @return Array<br />
&nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> getListeners<span style="color: #000000;">&#40;</span>o<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=eventdispatcher%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:eventdispatcher.html"><span style="color: #004993;">EventDispatcher</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><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>objDict<span style="color: #000000;">&#91;</span>o<span style="color: #000000;">&#93;</span> <span style="color: #0033ff; font-weight: bold;">as</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: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> tmpArr<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;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tmpArr = objDict<span style="color: #000000;">&#91;</span>o<span style="color: #000000;">&#93;</span> <span style="color: #0033ff; font-weight: bold;">as</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><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// forget trying to trace out the function name we use the function literal...</span><br />
&nbsp; &nbsp; &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;">0</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&lt;</span> tmpArr<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;_______object &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> o <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot; has event types: &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> tmpArr<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;">type</span> <span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot; with listener: &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> tmpArr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>listener<span style="color: #000000;">&#41;</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;">return</span> tmpArr<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;_______object has no listeners&quot;</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;">return</span> <span style="color: #0033ff; font-weight: bold;">null</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> removeAllListeners<span style="color: #000000;">&#40;</span>o<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=eventdispatcher%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:eventdispatcher.html"><span style="color: #004993;">EventDispatcher</span></a><span style="color: #000066; font-weight: bold;">,</span> cap<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=boolean%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:boolean.html"><span style="color: #004993;">Boolean</span></a> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>objDict<span style="color: #000000;">&#91;</span>o<span style="color: #000000;">&#93;</span> <span style="color: #0033ff; font-weight: bold;">as</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: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> tmpArr<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;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tmpArr = objDict<span style="color: #000000;">&#91;</span>o<span style="color: #000000;">&#93;</span> <span style="color: #0033ff; font-weight: bold;">as</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><br />
&nbsp; &nbsp; &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;">0</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&lt;</span> tmpArr<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;o<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span>tmpArr<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;">type</span><span style="color: #000066; font-weight: bold;">,</span> tmpArr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>listener<span style="color: #000066; font-weight: bold;">,</span> cap<span style="color: #000000;">&#41;</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;">for</span> <span style="color: #000000;">&#40;</span><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=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;">0</span><span style="color: #000066; font-weight: bold;">;</span> p <span style="color: #000066; font-weight: bold;">&lt;</span> tmpArr<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span> p<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;objArr<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">splice</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; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>tmpArr<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> == 0<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0033ff; font-weight: bold;">delete</span> objDict<span style="color: #000000;">&#91;</span>o<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;_______object has no listeners&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<div class="add-comments-link"><center><b><a href="http://www.thumbleaf.com/journal/?p=268#respond" title=""></a></b></center></div>]]></content:encoded>
			<wfw:commentRss>http://www.thumbleaf.com/journal/?feed=rss2&amp;p=268</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Flash Builder 4 : vertical+horizontal centeringof swf in ActionScript projects</title>
		<link>http://www.thumbleaf.com/journal/?p=239</link>
		<comments>http://www.thumbleaf.com/journal/?p=239#comments</comments>
		<pubDate>Mon, 31 May 2010 16:28:30 +0000</pubDate>
		<dc:creator>Thomas</dc:creator>
				<category><![CDATA[Coding tools]]></category>
		<category><![CDATA[Flashbuilder]]></category>
		<category><![CDATA[ActionScript]]></category>

		<guid isPermaLink="false">http://www.thumbleaf.com/journal/?p=239</guid>
		<description><![CDATA[It&#8217;s possible to edit the html wrapper that Flash Builder generates for the output swf &#8211; so that it centres any swf both horizontally and vertically without Flashbuilders default and slightly strange scaling. The hack comes from how I&#8217;ve had this setup in Flashdevelop with SWFObject and only requires a few lines of CSS: 1234567891011&#60;style&#62; [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.thumbleaf.com/blogassets/img/fb4.png" width="50" height="50" alt="Flashdevelop" style="border: 0; float: left; margin: 0px 10px;" /> It&#8217;s possible to edit the html wrapper that Flash Builder generates for the output swf &#8211; so that it centres any swf both horizontally and vertically without Flashbuilders default and slightly strange scaling.</p>
<p>The hack comes from how I&#8217;ve had this setup in Flashdevelop with SWFObject and only requires a few lines of CSS:</p>
<div class="codecolorer-container css mac-classic" style="border: 1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;style<span style="color: #00AA00;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #cc00cc;">#divFloat</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;"><span style="color: #cc66cc;">50</span>%</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;"><span style="color: #cc66cc;">50</span>%</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">:</span><span style="color: #933;"><span style="color: #cc66cc;">50</span>%</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;"><span style="color: #cc66cc;">50</span>%</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">-300px</span><span style="color: #00AA00;">;</span> &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* Half the height of your SWF*/</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">-400px</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* Half the width of your SWF*/</span><br />
&nbsp; &nbsp;<span style="color: #00AA00;">&#125;</span><br />
&nbsp; &nbsp;&lt;/style<span style="color: #00AA00;">&gt;</span></div></td></tr></tbody></table></div>
<p>To get this to work all that is needed is a div with the matching id &#8216;divFloat&#8217; added to the html body of the html page that acts as a wrapper for the swf; and this will centre the swf vertically and horizontally.</p>
<p>Based on the CSS above we can device a similar approach and apply it to Flash Builder&#8217;s publishing method. The part to figure out is how to insert it into Flash Builders template based creation of the html wrapper.</p>
<p>To do so we must edit the index.template.html in the html-template folder in the Flash Builder project directory: which is the blueprint for the html file generated in the bin-debug folder.</p>
<p>In Flash Builder our html wrapper and swf will be based on what name we choose for our main application file (the one that initializes our application). This value is held by the variable <tt>${application}</tt> in index.template.html. It is also the id of our embedded content in the html page that results in bin-debug, based on our index.template.</p>
<p>So we can write in index.template.html:</p>
<div class="codecolorer-container css mac-classic" style="border: 1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;style<span style="color: #00AA00;">&gt;</span><br />
body <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span><br />
#$<span style="color: #00AA00;">&#123;</span>application<span style="color: #00AA00;">&#125;</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;"><span style="color: #cc66cc;">50</span>%</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;"><span style="color: #cc66cc;">50</span>%</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">:</span><span style="color: #933;"><span style="color: #cc66cc;">50</span>%</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;"><span style="color: #cc66cc;">50</span>%</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">-300px</span><span style="color: #00AA00;">;</span> &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* Half the height of your SWF*/</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">-400px</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* Half the width of your SWF*/</span><br />
&nbsp; &nbsp;<span style="color: #00AA00;">&#125;</span><br />
&lt;/style<span style="color: #00AA00;">&gt;</span></div></td></tr></tbody></table></div>
<p>If the application class has the name &#8216;OrangeApp.as&#8217; that will translate into <tt>#OrangeApp{</tt> in the resulting html file in the bin-debug folder and target the id of the embedded swf so that the CSS is applied to centre it.</p>
<p>Of course the swf still needs to have the following code in it&#8217;s application class:</p>
<div class="codecolorer-container actionscript3 mac-classic" style="border: 1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">scaleMode</span> = <a href="http://www.google.com/search?q=stagescalemode%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:stagescalemode.html"><span style="color: #004993;">StageScaleMode</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">NO_SCALE</span><br />
<span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">align</span> = <a href="http://www.google.com/search?q=stagealign%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:stagealign.html"><span style="color: #004993;">StageAlign</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TOP_LEFT</span></div></td></tr></tbody></table></div>
<p>Also specify the width and height of the swf in the index.template.html as usual by just replacing &#8216;width&#8217; and &#8216;height&#8217; with the real width and height of our swf. That will center html the swf in Flash Builder; and remove the pesky default &#8216;Flex scaling&#8217; without too much work!</p>
<div class="add-comments-link"><center><b><a href="http://www.thumbleaf.com/journal/?p=239#respond" title=""></a></b></center></div>]]></content:encoded>
			<wfw:commentRss>http://www.thumbleaf.com/journal/?feed=rss2&amp;p=239</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Formatting XML text with html tags +the TextFormat class</title>
		<link>http://www.thumbleaf.com/journal/?p=210</link>
		<comments>http://www.thumbleaf.com/journal/?p=210#comments</comments>
		<pubDate>Tue, 25 May 2010 18:21:03 +0000</pubDate>
		<dc:creator>Thomas</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Assets]]></category>

		<guid isPermaLink="false">http://www.thumbleaf.com/journal/?p=210</guid>
		<description><![CDATA[Recently I wrongly came to the conclusion that you can&#8217;t apply a TextFormat to dynamic textfield set to htmlText = “My text” without that the TextFormat overwrites the formatting done with html tags in the XML. It turns out that the issue I was having had more to do with not being read up on [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I wrongly came to the conclusion that you can&#8217;t apply a TextFormat to dynamic textfield set to <tt>htmlText = “My text”</tt> without that the TextFormat overwrites the formatting done with html tags in the XML.</p>
<p>It turns out that the issue I was having had more to do with not being read up on the defaultTextFormat setter.</p>
<p>Let us take Arial as an example. To embed it in AS3 in bold, italic, and normal formatting we would like so:</p>
<div class="codecolorer-container actionscript3 mac-classic" style="border: 1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><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.display</span><span style="color: #000066; font-weight: bold;">.*;</span><br />
&nbsp; &nbsp;<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.*;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #3f5fbf;">/**<br />
&nbsp; &nbsp; * ...<br />
&nbsp; &nbsp; * @author Thomas James Thorstensson<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp;<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> TextFmt <span style="color: #0033ff; font-weight: bold;">extends</span> <a href="http://www.google.com/search?q=sprite%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:sprite.html"><span style="color: #004993;">Sprite</span></a><br />
&nbsp; &nbsp;<span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span>=<span style="color: #990000;">'C:/Windows/Fonts/arial.ttf'</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">,</span>fontFamily =<span style="color: #990000;">'arialNormal'</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">,</span><span style="color: #004993;">fontStyle</span> =<span style="color: #990000;">'normal'</span> <span style="color: #009900; font-style: italic;">// normal|italic</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">,</span>fontWeight =<span style="color: #990000;">'normal'</span> <span style="color: #009900; font-style: italic;">// normal|bold</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">,</span>unicodeRange=<span style="color: #990000;">'U+0020-U+002F,U+0030-U+0039,U+003A-U+0040,U+0041-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E'</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//,cff='false'</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static const arialNormal<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=class%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:class.html"><span style="color: #004993;">Class</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span>=<span style="color: #990000;">'C:/Windows/Fonts/arialbd.ttf'</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">,</span>fontFamily =<span style="color: #990000;">'arialBold'</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">,</span><span style="color: #004993;">fontStyle</span> =<span style="color: #990000;">'normal'</span> <span style="color: #009900; font-style: italic;">// normal|italic</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">,</span>fontWeight =<span style="color: #990000;">'bold'</span> <span style="color: #009900; font-style: italic;">// normal|bold</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">,</span>unicodeRange=<span style="color: #990000;">'U+0020-U+002F,U+0030-U+0039,U+003A-U+0040,U+0041-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E'</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//,cff='false'</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static const arialBold<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=class%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:class.html"><span style="color: #004993;">Class</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span>=<span style="color: #990000;">'C:/Windows/Fonts/ariali.ttf'</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">,</span>fontFamily =<span style="color: #990000;">'arialItalic'</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">,</span><span style="color: #004993;">fontStyle</span> =<span style="color: #990000;">'italic'</span> <span style="color: #009900; font-style: italic;">// normal|italic</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">,</span>fontWeight =<span style="color: #990000;">'normal'</span> <span style="color: #009900; font-style: italic;">// normal|bold</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">,</span>unicodeRange=<span style="color: #990000;">'U+0020-U+002F,U+0030-U+0039,U+003A-U+0040,U+0041-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E'</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//,cff='false'</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static const arialItalic<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=class%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:class.html"><span style="color: #004993;">Class</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> TextFmt<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://www.google.com/search?q=font%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:font.html"><span style="color: #004993;">Font</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">registerFont</span><span style="color: #000000;">&#40;</span>arialNormal<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://www.google.com/search?q=font%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:font.html"><span style="color: #004993;">Font</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">registerFont</span><span style="color: #000000;">&#40;</span>arialBold<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://www.google.com/search?q=font%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:font.html"><span style="color: #004993;">Font</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">registerFont</span><span style="color: #000000;">&#40;</span>arialItalic<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>In our XML we can then directly refer to one of the versions of the font like so:</p>
<div class="codecolorer-container xml mac-classic" style="border: 1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xmlnode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Lorem ipsum<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;font</span> <span style="color: #000066;">face</span>=<span style="color: #ff0000;">&quot;arialItalic&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span> and some italic text<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/font<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> and end.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xmlnode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></td></tr></tbody></table></div>
<p>If we set a dynamic textfield to the above content, we can still apply additional formatting to it<br />
with a regular TextFormat as long as we use defaultTextFormat rather than setTextFormat :</p>
<div class="codecolorer-container actionscript3 mac-classic" style="border: 1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">arialNormal = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=textformat%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:textformat.html"><span style="color: #004993;">TextFormat</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
arialNormal<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">font</span> = <span style="color: #990000;">'arialNormal'</span><span style="color: #000066; font-weight: bold;">;</span><br />
arialNormal<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">size</span> = <span style="color: #000000; font-weight:bold;">11</span><span style="color: #000066; font-weight: bold;">;</span><br />
arialNormal<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">color</span> = 0xCCCCCC<span style="color: #000066; font-weight: bold;">;</span><br />
myText<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">defaultTextFormat</span> = arialNormal<span style="color: #000066; font-weight: bold;">;</span><br />
myText<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">htmlText</span>= xmlnode<span style="color: #000066; font-weight: bold;">;</span></div></td></tr></tbody></table></div>
<p>The dynamic textfield will take the &#8216;arialNormal&#8217; format without the arialItalic format being overwritten. The italic style will so to speak take on the arialItalic and the arialNormal.</p>
<p>If we instead would use setTextFormat after <tt>myText.htmlText= xmlnode</tt>; it would be the case that the formatting in the html would be overwritten by the TextFormat.</p>
<div class="add-comments-link"><center><b><a href="http://www.thumbleaf.com/journal/?p=210#respond" title=""></a></b></center></div>]]></content:encoded>
			<wfw:commentRss>http://www.thumbleaf.com/journal/?feed=rss2&amp;p=210</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Augmented reality, lab 1</title>
		<link>http://www.thumbleaf.com/journal/?p=188</link>
		<comments>http://www.thumbleaf.com/journal/?p=188#comments</comments>
		<pubDate>Fri, 02 Apr 2010 17:31:57 +0000</pubDate>
		<dc:creator>Thomas</dc:creator>
				<category><![CDATA[Papervision]]></category>
		<category><![CDATA[Visual API]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[FlarToolkit]]></category>

		<guid isPermaLink="false">http://www.thumbleaf.com/journal/?p=188</guid>
		<description><![CDATA[[See post to watch QuickTime movie] Better late than never as I&#8217;ve began to delve into Augmented Reality. There&#8217;s so much inspiring work going on in the AR community. The QT movie above is just a brief demo based on the start toolkit for FLAR over at http://saqoosha.net/en/flartoolkit/start-up-guide/ &#8211; slimmed down by me for Flashdevelop. [...]]]></description>
			<content:encoded><![CDATA[[See post to watch QuickTime movie]
<p>Better late than never as I&#8217;ve began to delve into Augmented Reality. </p>
<p>There&#8217;s so much inspiring work going on in the AR community. The QT movie above is just a brief demo based on the start toolkit for FLAR over at <a href="http://saqoosha.net/en/flartoolkit/start-up-guide/" target='_blank'>http://saqoosha.net/en/flartoolkit/start-up-guide/</a> &#8211; slimmed down by me for Flashdevelop. The bitmap material is from Scuba&#8217;s latest album, Triangulation&#8230;</p>
<p>I&#8217;m currently looking at learning more about markers; and it&#8217;s been pointed out to me that there&#8217;s a useful marker generation tool here: <a href="http://flash.tarotaro.org/blog/2009/07/12/mgo2/" target='_blank'>http://flash.tarotaro.org/blog/2009/07/12/mgo2/</a>. </p>
<p>-I aim to post more frequently now and will keep you updated on my digs.</p>
<div class="add-comments-link"><center><b><a href="http://www.thumbleaf.com/journal/?p=188#respond" title=""></a></b></center></div>]]></content:encoded>
			<wfw:commentRss>http://www.thumbleaf.com/journal/?feed=rss2&amp;p=188</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New dubstep track written</title>
		<link>http://www.thumbleaf.com/journal/?p=185</link>
		<comments>http://www.thumbleaf.com/journal/?p=185#comments</comments>
		<pubDate>Tue, 16 Mar 2010 07:49:21 +0000</pubDate>
		<dc:creator>Thomas</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[Music]]></category>

		<guid isPermaLink="false">http://www.thumbleaf.com/journal/?p=185</guid>
		<description><![CDATA[&#8216;Bow&#8217; listen @ http://www.myspace.com/thomasjamest]]></description>
			<content:encoded><![CDATA[<p>&#8216;Bow&#8217; listen @ <a href="http://www.myspace.com/thomasjamest">http://www.myspace.com/thomasjamest</a></p>
<div class="add-comments-link"><center><b><a href="http://www.thumbleaf.com/journal/?p=185#respond" title=""></a></b></center></div>]]></content:encoded>
			<wfw:commentRss>http://www.thumbleaf.com/journal/?feed=rss2&amp;p=185</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Papervision3D, FlashDevelop template</title>
		<link>http://www.thumbleaf.com/journal/?p=165</link>
		<comments>http://www.thumbleaf.com/journal/?p=165#comments</comments>
		<pubDate>Fri, 27 Nov 2009 21:22:55 +0000</pubDate>
		<dc:creator>Thomas</dc:creator>
				<category><![CDATA[Coding tools]]></category>
		<category><![CDATA[Flashdevelop]]></category>
		<category><![CDATA[Papervision]]></category>
		<category><![CDATA[Visual API]]></category>
		<category><![CDATA[FlashDevelop]]></category>
		<category><![CDATA[Tweetable]]></category>

		<guid isPermaLink="false">http://www.thumbleaf.com/journal/?p=165</guid>
		<description><![CDATA[A nifty FlashDevelop template to simplify the creation of a 3D render class in Papervison 3D 2.0.]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.thumbleaf.com/blogassets/img/flashdevelop.jpg" width="50" height="50" alt="Flashdevelop" style="border: 0; float: left; margin: 0px 10px;" /> Here&#8217;s a simple FlashDevelop template to speed up the creation of a 3D render in Papervision3D 2.0. Download the template from <a href="http://www.thumbleaf.com/blogassets/zip/BasicView.zip" target="_blank">here</a> or copy the code below and save it as View3D.as.fdt.</p>
<p>In FlashDevelop go to Tools &#8211;> Application files. This will open your Explorer: Now go into the folder Templates > ProjectFiles > AS3Project and drop the template in there.</p>
<p>You will now if you left click on your src package and go to Add > see the option &#8216;BasicView&#8217; in the menu that pops up.</p>
<p>The custom arguments available for template creation are listed at <a href="http://www.flashdevelop.org/community/viewtopic.php?t=1521" target="_blank">http://www.flashdevelop.org/community/viewtopic.php?t=1521</a></p>
<p>Here&#8217;s the template:</p>
<div class="codecolorer-container actionscript3 mac-classic" style="border: 1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #9900cc; font-weight: bold;">package</span> $<span style="color: #000000;">&#40;</span>Package<span style="color: #000000;">&#41;</span> $<span style="color: #000000;">&#40;</span>CSLB<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp;<span style="color: #0033ff; font-weight: bold;">import</span> org<span style="color: #000066; font-weight: bold;">.</span>papervision3d<span style="color: #000066; font-weight: bold;">.</span>view<span style="color: #000066; font-weight: bold;">.</span>BasicView<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> $<span style="color: #000000;">&#40;</span>FileName<span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">extends</span> BasicView <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; $<span style="color: #000000;">&#40;</span>EntryPoint<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/** <br />
&nbsp; &nbsp; &nbsp; * $(FileName)<br />
&nbsp; &nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> $<span style="color: #000000;">&#40;</span>FileName<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">init</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;startRendering<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; override <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> onRenderTick<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a>=<span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000066; font-weight: bold;">.</span>onRenderTick<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Lastly, a good set of templates can be found over at <a href="http://www.actionscriptdeveloper.co.uk/puremvc-first-thoughts-flashdevelop-templates/" target="_blank">http://www.actionscriptdeveloper.co.uk/puremvc-first-thoughts-flashdevelop-templates/</a></p>
<div class="add-comments-link"><center><b><a href="http://www.thumbleaf.com/journal/?p=165#respond" title=""></a></b></center></div>]]></content:encoded>
			<wfw:commentRss>http://www.thumbleaf.com/journal/?feed=rss2&amp;p=165</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Greensock v11</title>
		<link>http://www.thumbleaf.com/journal/?p=150</link>
		<comments>http://www.thumbleaf.com/journal/?p=150#comments</comments>
		<pubDate>Sun, 25 Oct 2009 12:59:57 +0000</pubDate>
		<dc:creator>Thomas</dc:creator>
				<category><![CDATA[Greensock]]></category>
		<category><![CDATA[Visual API]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Tweetable]]></category>

		<guid isPermaLink="false">http://www.thumbleaf.com/journal/?p=150</guid>
		<description><![CDATA[Greensock v11 is out!]]></description>
			<content:encoded><![CDATA[<p>The new Greensock engine is out and looking great performance wise! Check out the new features <a href="http://blog.greensock.com/v11/" target="_blank">here</a>. What the point of my below example is I don&#8217;t know but it runs smooth,</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_ParticlesTweenLite11_1385555862"
			class="flashmovie"
			width="400"
			height="400">
	<param name="movie" value="../../blogassets/swf/particlesGreensock11/ParticlesTweenLite11.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="../../blogassets/swf/particlesGreensock11/ParticlesTweenLite11.swf"
			name="fm_ParticlesTweenLite11_1385555862"
			width="400"
			height="400">
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<div class="add-comments-link"><center><b><a href="http://www.thumbleaf.com/journal/?p=150#respond" title=""></a></b></center></div>]]></content:encoded>
			<wfw:commentRss>http://www.thumbleaf.com/journal/?feed=rss2&amp;p=150</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Papervision3D, interactive material</title>
		<link>http://www.thumbleaf.com/journal/?p=79</link>
		<comments>http://www.thumbleaf.com/journal/?p=79#comments</comments>
		<pubDate>Sat, 17 Oct 2009 19:12:20 +0000</pubDate>
		<dc:creator>Thomas</dc:creator>
				<category><![CDATA[Papervision]]></category>
		<category><![CDATA[Visual API]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Tweetable]]></category>

		<guid isPermaLink="false">http://www.thumbleaf.com/journal/?p=79</guid>
		<description><![CDATA[In papervision3D it's easy to add interactivity to a primitive such as a Cube.]]></description>
			<content:encoded><![CDATA[<p>With the aid of the Papervision3D class <tt>org.papervision3d.events.InteractiveScene3DEvent</tt> it&#8217;s easy to create an interactive papervision 3D primitive such as this Cube (click on it&#8217;s sides):</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_interactiveCube_739987804"
			class="flashmovie"
			width="400"
			height="400">
	<param name="movie" value="../../blogassets/swf/interactiveMaterial/interactiveCube.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="../../blogassets/swf/interactiveMaterial/interactiveCube.swf"
			name="fm_interactiveCube_739987804"
			width="400"
			height="400">
	<!--<![endif]-->
		<br />
<a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a><br />

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>The cube uses the BitmapMaterial class (the sides are embedded jpg&#8217;s) and all we need to do to make them interactive is to remember to set interactive to true:</p>
<div class="codecolorer-container actionscript3 mac-classic" style="border: 1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">bitmapMaterial6<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span> = <span style="color: #990000;">&quot;6&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
bitmapMaterial6<span style="color: #000066; font-weight: bold;">.</span>interactive = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span></div></td></tr></tbody></table></div>
<p>Once we created our cube the last bit is just to add the event listener to the <tt>InteractiveScene3DEvent</tt> which is dispatched by the Cube. And we can use the event property <tt>evt.face3d.material.name</tt> of the current material side clicked to retrieve the name of the same:</p>
<div class="codecolorer-container actionscript3 mac-classic" style="border: 1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900; font-style: italic;">// create a cube based on the list</span><br />
primitive = <span style="color: #0033ff; font-weight: bold;">new</span> Cube<span style="color: #000000;">&#40;</span>materiallist<span style="color: #000066; font-weight: bold;">,</span> 400<span style="color: #000066; font-weight: bold;">,</span> 400<span style="color: #000066; font-weight: bold;">,</span> 400<span style="color: #000066; font-weight: bold;">,</span> 3<span style="color: #000066; font-weight: bold;">,</span> 3<span style="color: #000066; font-weight: bold;">,</span> 3<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
primitive<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>InteractiveScene3DEvent<span style="color: #000066; font-weight: bold;">.</span>OBJECT_CLICK<span style="color: #000066; font-weight: bold;">,</span> handleClick<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #009900; font-style: italic;">//.../</span><br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> handleClick <span style="color: #000000;">&#40;</span>evt<span style="color: #000066; font-weight: bold;">:</span>InteractiveScene3DEvent<span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
testText<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;__side clicked : &quot;</span> <span style="color: #000066; font-weight: bold;">+</span>evt<span style="color: #000066; font-weight: bold;">.</span>face3d<span style="color: #000066; font-weight: bold;">.</span>material<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>The InteractiveScene3DEvent is not limited to click events however, the documentation at<a href=" http://papervision3d.googlecode.com/svn/trunk/as3/trunk/docs/org/papervision3d/events/InteractiveScene3DEvent.html" target="_blank"> http://papervision3d.googlecode.com/svn/trunk/as3/trunk/docs/org/papervision3d/events/InteractiveScene3DEvent.html</a> &#8211; shows that we can also listen for MOVE, OVER, OUT, etc. Nice.</p>
<p>If you would like to get hold of the full code for this example then you can download it <a href="http://www.thumbleaf.com/blogassets/zip/interactiveMaterial.zip">here</a> (Flashdevelop project).</p>
<p>Theres some great Papervision tutorials over at <a href="http://www.madvertices.com" target="_blank">http://www.madvertices.com</a> where I&#8217;ve taken several myself!</p>
<div class="add-comments-link"><center><b><a href="http://www.thumbleaf.com/journal/?p=79#respond" title=""></a></b></center></div>]]></content:encoded>
			<wfw:commentRss>http://www.thumbleaf.com/journal/?feed=rss2&amp;p=79</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AS 3 Dictionary Object:  a way to map instances of sealed Classes</title>
		<link>http://www.thumbleaf.com/journal/?p=4</link>
		<comments>http://www.thumbleaf.com/journal/?p=4#comments</comments>
		<pubDate>Fri, 16 Oct 2009 09:28:05 +0000</pubDate>
		<dc:creator>Thomas</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Dictionary Object]]></category>
		<category><![CDATA[Properties]]></category>
		<category><![CDATA[Tweetable]]></category>

		<guid isPermaLink="false">http://www.thumbleaf.com/journal/?p=4</guid>
		<description><![CDATA[The Dictionary Object provides us with a handy way of assigning properties also to instances which are part of sealed classes...]]></description>
			<content:encoded><![CDATA[<p>In Action Script 3 most classes are sealed. This means that for most Objects we are not able to create new properties run time beyond those that where available compile time.  This is not the case with Array and Object though which are both dynamic and regularly come in handy to us for example in the creation of an associative array (or sometimes called a &#8216;hash&#8217;) :</p>
<div class="codecolorer-container actionscript3 mac-classic" style="border: 1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6699cc; font-weight: bold;">var</span> myAssoc<span style="color: #000066; font-weight: bold;">:</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> = <span style="color: #0033ff; font-weight: bold;">new</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><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
myAssoc<span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;oranges&quot;</span><span style="color: #000000;">&#93;</span> = <span style="color: #000000; font-weight:bold;">101</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;number of oranges &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> myAssoc<span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;oranges&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span></div></td></tr></tbody></table></div>
<p>But what to do if you&#8217;re in need of creating properties upon an instance that belongs to a sealed class. For example say that we with <tt>flash.display.SimpleButton</tt> would like to add the property counter which tells us how what time interval to start a timer with. We could not:</p>
<div class="codecolorer-container actionscript3 mac-classic" style="border: 1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000;">&#40;</span><span style="color: #009900; font-style: italic;">//import flash.display.SimpleButton etc...)</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> myBtn<span style="color: #000066; font-weight: bold;">:</span>Simple Button = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=simplebutton%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:simplebutton.html"><span style="color: #004993;">SimpleButton</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
myBtn<span style="color: #000066; font-weight: bold;">.</span>timestamp = <span style="color: #000000; font-weight:bold;">1000</span><span style="color: #000066; font-weight: bold;">;</span></div></td></tr></tbody></table></div>
<p>The above would throw an error as SimpleButton like most classes in ActionScript 3 are sealed. The solution would be to extend SimpleButton with a dynamic class like so :</p>
<div class="codecolorer-container actionscript3 mac-classic" style="border: 1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #9900cc; font-weight: bold;">package</span> &nbsp;<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=simplebutton%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:simplebutton.html"><span style="color: #004993;">SimpleButton</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp;<span style="color: #0033ff; font-weight: bold;">public</span> dynamic <span style="color: #9900cc; font-weight: bold;">class</span> DynamicButton <span style="color: #0033ff; font-weight: bold;">extends</span> <a href="http://www.google.com/search?q=simplebutton%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:simplebutton.html"><span style="color: #004993;">SimpleButton</span></a><br />
&nbsp; &nbsp;<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> DynamicButton<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Making use of our dynamic button we could now :</p>
<div class="codecolorer-container actionscript3 mac-classic" style="border: 1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6699cc; font-weight: bold;">var</span> dynBtn<span style="color: #000066; font-weight: bold;">:</span>DynamicButton = <span style="color: #0033ff; font-weight: bold;">new</span> DynamicButton<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
dynBtn<span style="color: #000066; font-weight: bold;">.</span>timestamp = <span style="color: #000000; font-weight:bold;">1000</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;dynamic button timestamp value &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> dynBtn<span style="color: #000066; font-weight: bold;">.</span>timestamp<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></td></tr></tbody></table></div>
<p>And this would compile without errors and work nicely. However there is an other approach to this which comes very handy as a way of creating dynamic properties and referring to them. Here enters the Dictionary Object. This object is a bit like our associative array above but with the big difference that it can take an object itself as lookup key to find a value. For our oranges we get:</p>
<div class="codecolorer-container actionscript3 mac-classic" style="border: 1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6699cc; font-weight: bold;">var</span> dict<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=dictionary%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:dictionary.html"><span style="color: #004993;">Dictionary</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=dictionary%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:dictionary.html"><span style="color: #004993;">Dictionary</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> myOrange<span style="color: #000066; font-weight: bold;">:</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> = <span style="color: #0033ff; font-weight: bold;">new</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><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
dict<span style="color: #000000;">&#91;</span>myOrange<span style="color: #000000;">&#93;</span> = <span style="color: #000000; font-weight:bold;">101</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;number of oranges dictionary approach &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> dict<span style="color: #000000;">&#91;</span>myOrange<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></td></tr></tbody></table></div>
<p>Using a Dictionary Object we thus have a way to lookup properties using the objects themselwes rather than using the variable names to refer to properties. This also works for instances of sealed classes such as our button example. We can write:</p>
<div class="codecolorer-container actionscript3 mac-classic" style="border: 1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">dict = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=dictionary%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:dictionary.html"><span style="color: #004993;">Dictionary</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> myButton<span style="color: #000066; font-weight: bold;">:</span> <a href="http://www.google.com/search?q=simplebutton%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:simplebutton.html"><span style="color: #004993;">SimpleButton</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=simplebutton%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:simplebutton.html"><span style="color: #004993;">SimpleButton</span></a> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
dict<span style="color: #000000;">&#91;</span>myButton<span style="color: #000000;">&#93;</span> = <span style="color: #000000; font-weight:bold;">1001</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;dictionary button counter value &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> dict<span style="color: #000000;">&#91;</span>myButton<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></td></tr></tbody></table></div>
<p>Since the button is the key, it does not matter that SimpleButton is a sealed class. We are not trying to assign a new property to the SimpleButton instance by using a variable name. Instead we use the instance itself and thus we here have a handy way of assigning values also to instances that don&#8217;t take new dynamic properties.</p>
<p>Some further readings:<br />
<a href="http://www.gskinner.com/blog/archives/2006/07/as3_dictionary.html" target="_blank">http://www.gskinner.com/blog/archives/2006/07/as3_dictionary.html</a><br />
<a href="http://www.zombieflambe.com/actionscript-3/as3-dictionary-class-array-object-benchmark/" target="_blank">http://www.zombieflambe.com/actionscript-3/as3-dictionary-class-array-object-benchmark/</a><br />
<a href="http://pixelwelders.com/blog/best-practices/2008/speed-tests-objects-vs-arrays-vs-dictionaries/" target="_blank">http://pixelwelders.com/blog/best-practices/2008/speed-tests-objects-vs-arrays-vs-dictionaries/</a></p>
<div class="add-comments-link"><center><b><a href="http://www.thumbleaf.com/journal/?p=4#respond" title=""></a></b></center></div>]]></content:encoded>
			<wfw:commentRss>http://www.thumbleaf.com/journal/?feed=rss2&amp;p=4</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
