<?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>Thanks, Mister! &#187; Flash</title>
	<atom:link href="http://www.thanksmister.com/index.php/archive/category/flash/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thanksmister.com</link>
	<description>Adobe Flex &#38; AIR Development</description>
	<lastBuildDate>Mon, 19 Jul 2010 17:28:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Garbage Collection and Event Listeners</title>
		<link>http://www.thanksmister.com/index.php/archive/be-good-clean-up-your-event-listeners/</link>
		<comments>http://www.thanksmister.com/index.php/archive/be-good-clean-up-your-event-listeners/#comments</comments>
		<pubDate>Fri, 29 May 2009 07:59:17 +0000</pubDate>
		<dc:creator>Mister</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Flex 3]]></category>
		<category><![CDATA[addEventListener]]></category>
		<category><![CDATA[DisplayObject]]></category>
		<category><![CDATA[EventDispatcher]]></category>
		<category><![CDATA[garbage collection]]></category>
		<category><![CDATA[useWeakReference]]></category>

		<guid isPermaLink="false">http://thanksmister.com/?p=575</guid>
		<description><![CDATA[On a recent AIR project I have become aware and subsequently obsessed with memory. My concerns have centered around garbage collection and event listeners, specifically how you clean up event listeners to allow Garbage Collection (GC) to clean up objects. Most DisplayObjects implement the EventDispatcher class that allows it to broadcast events. Trolling around the [...]]]></description>
			<content:encoded><![CDATA[<p>On a recent AIR project I have become aware and subsequently obsessed with memory.   My concerns have centered around garbage collection and event listeners, specifically how you clean up event listeners to allow <a href="http://www.adobe.com/devnet/flashplayer/articles/garbage_collection.html">Garbage Collection (GC)</a> to clean up objects.  Most DisplayObjects implement the <a href="http://livedocs.adobe.com/flex/2/langref/flash/events/EventDispatcher.html#addEventListener()">EventDispatcher</a> class that allows it to broadcast events.    Trolling around the googleverse I found some interesting ways to insure that you break strong references to allow clean up or manually remove event listeners on your own to make your application more memory savvy.   </p>
<p>When you use addEventListener() method and register a event listener to an object  you create reference.  By default any object that has a reference to a listener will keep that reference until it is removed using the removeEventListener() method.    Strong references will not be cleaned up by Flash player GC and remain in memory until the application is closed or the world ends, whichever comes first.   This makes for a horribly leaky AIR applications, especially those applications that may run for days on the user&#8217;s system without being restarted.    </p>
<p><strong>Use Additional Parameters of Listener</strong></p>
<p>The addEventListener() method does have some additional (and seldom used) parameters to create a weak reference when adding the listener to an object.   On of those parameters is &#8220;useWeakReference&#8221;, the 5th parameter of the method.   To utilize this parameter you need to set it from false to true:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><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 /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">addEventListener<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">type</span>:<span style="color: #0066CC;">String</span>, listener:<span style="color: #000000; font-weight: bold;">Function</span>, useCapture:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span>, priority:<span style="color: #0066CC;">int</span> = 0, useWeakReference:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>;<br />
.....<br />
<br />
<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">button</span>:<span style="color: #0066CC;">Button</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Button</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #0066CC;">button</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">click</span>, handleMouseClick, <span style="color: #000000; font-weight: bold;">false</span>, 0, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> handleMouseClick<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp;<span style="color: #808080; font-style: italic;">// handle the event</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p><span id="more-575"></span></p>
<p>This will allow the event to be cleaned up at some point by Flash garbage collection.  If you are like me and and find it annoying that the useWeakReference parameter of the addEventListener() method is false by default, you can can extend the object and make useWeakReference true by default, then use that object in your project:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><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 /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">package com.<span style="color: #006600;">custom</span>.<span style="color: #006600;">controls</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">controls</span>.<span style="color: #0066CC;">Button</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CustomButton <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">Button</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> CustomButton<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; override <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> addEventListener<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">type</span>:<span style="color: #0066CC;">String</span>, listener:<span style="color: #000000; font-weight: bold;">Function</span>, useCapture:<span style="color: #0066CC;">Boolean</span>=<span style="color: #000000; font-weight: bold;">false</span>, priority:<span style="color: #0066CC;">int</span>=0, useWeakReference:<span style="color: #0066CC;">Boolean</span>=<span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">super</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">type</span>, listener, useCapture, priority, useWeakReference<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p><strong>Explicitly Removing Listeners</strong></p>
<p>Even though setting useWeakReference=true will most likely mark an object for clean up, to be even more certain you should explicitly remove the event listener with the removeEventListener() method:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><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 /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">button</span>:<span style="color: #0066CC;">Button</span>;<br />
<br />
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">button</span>:<span style="color: #0066CC;">Button</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Button</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp;<span style="color: #0066CC;">button</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">click</span>, handleMouseClick, <span style="color: #000000; font-weight: bold;">false</span>, 0, <span style="color: #66cc66;">&lt;</span>strong<span style="color: #66cc66;">&gt;</span>true<span style="color: #66cc66;">&lt;/</span>strong<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> handleMouseClick<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #0066CC;">button</span>.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>handleMouseClick<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #0066CC;">button</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Button</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// handle the event</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>Now you are certain that you have cleaned up and removed the listener manually and the object will be removed at some point during GC since there is no longer an explicit reference to the object. </p>
<p><strong>Anonymous Functions</strong></p>
<p>Another technique that comes in handy is to removing event listeners when using anonymous functions as event handlers.  The trick to this techniques is the <a href="http://livedocs.adobe.com/flex/2/langref/arguments.html">arguments.callee</a>:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><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="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">button</span>:<span style="color: #0066CC;">Button</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Button</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #0066CC;">button</span>.<span style="color: #006600;">addEventListner</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">CLICK</span>, <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; event.<span style="color: #006600;">currentTarget</span>.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>event.<span style="color: #0066CC;">type</span>, <span style="color: #0066CC;">arguments</span>.<span style="color: #0066CC;">callee</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;</div></td></tr></tbody></table></div>
<p><strong>Bummer</strong></p>
<p>Now for the disappointment.  If you create an event listener using MXML they are always going to have strong reference by default with no way to change useWeakReference and they make it difficult to use removeEventListener() method:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><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="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> handleClickEvent<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// handle event</span><br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
<span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Button</span> click=<span style="color: #ff0000;">&quot;handleClickEvent(event)&quot;</span><span style="color: #66cc66;">/&gt;</span></div></td></tr></tbody></table></div>
<p>So these objects will not be cleaned up when created in this way unless you have some clean up method that explicitly removes the event listeners or you add the event listeners to MXML object using ActionScript instead of binding.</p>
<p>So basically you need to add objects or listeners in ActionScript rather than use MXML when using the addEventListener() method, which sort of makes MXML less valuable in some respects because binding to objects and listening to events is what drives the framework. </p>
<p><strong>Additional Links</strong></p>
<p>For a great discussion on the topic, see <a href="http://www.onflex.org/ted/2008/09/useweakreferencesboolean-false.php">Ted Patricks</a> post and be sure to read all the comments as many of the examples were taken from discussion. </p>
<p>Garbage Collection Articles:</p>
<p><a href="http://spreadingfunkyness.com/garbage-collection-with-flex-and-adobe-air/">http://spreadingfunkyness.com/garbage-collection-with-flex-and-adobe-air/</a><br />
<a href="http://blogs.adobe.com/aharui/2007/03/garbage_collection_and_memory.html">http://blogs.adobe.com/aharui/2007/03/garbage_collection_and_memory.html</a><br />
<a href="http://gskinner.com/blog/archives/2006/08/as3_resource_ma_2.html">http://gskinner.com/blog/archives/2006/08/as3_resource_ma_2.html</a><br />
<a href="http://www.adobe.com/devnet/flashplayer/articles/resource_management.html">http://www.adobe.com/devnet/flashplayer/articles/resource_management.html</a></p>
<p><map name='google_ad_map_575_1452acacd61817fb'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/575?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_575_1452acacd61817fb' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=575&amp;url= http%3A%2F%2Fwww.thanksmister.com%2Findex.php%2Farchive%2Fbe-good-clean-up-your-event-listeners%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://www.thanksmister.com/index.php/archive/be-good-clean-up-your-event-listeners/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>HTTP Status 201 causing Flex #2032 Error in IE only</title>
		<link>http://www.thanksmister.com/index.php/archive/http-status-201-causing-flex-2032-error-in-ie-only/</link>
		<comments>http://www.thanksmister.com/index.php/archive/http-status-201-causing-flex-2032-error-in-ie-only/#comments</comments>
		<pubDate>Sat, 28 Mar 2009 16:40:13 +0000</pubDate>
		<dc:creator>Mister</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[2032 Error]]></category>
		<category><![CDATA[HTTPService]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Status 201]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://thanksmister.com/?p=508</guid>
		<description><![CDATA[I ran into a problem right when we were going to launch a new Flex web-based application to production (of course) with Internet Explorer and Flex. I was calling an RESTful service that returns XML and using the built-in Flex HTTPService with either POST/GET as the method for the request. Most of the service calls [...]]]></description>
			<content:encoded><![CDATA[<p>I ran into a problem right when we were going to launch a new Flex web-based application to production (of course) with Internet Explorer and Flex.  I was calling an <a href="http://en.wikipedia.org/wiki/REST">RESTful</a> service that returns XML and using the built-in Flex HTTPService  with either POST/GET as the method for the request.   Most of the service calls either return a HTTP Status Code of 200 (OK) or they throw an error.  For one  POST request that returned a HTTP Status of  &#8220;201 Created&#8221;  Flex threw up a <a href="http://livedocs.adobe.com/flex/201/langref/runtimeErrors.html">2032 Stream Error</a> in response.   Here is a brief definition of the error: </p>
<blockquote><p>
<a href="http://editthis.info/flexerrorcodes/Main_Page">The referenced resource does not exist or the swf is trying to access a file across a restricted domain. </a>
</p></blockquote>
<p>This error causes Flex to report a fault error on the request even though it was successful.   The 201 status code  is handled fine in all other browsers except IE (6 &#038; 7).    I did some research on the issue thinking it must be something easy to fix, that many others have run across before me.    It seems the error is out there for lots of different reasons.  </p>
<p>One post reported that IE was having a caching issues, and the way to solve it was to add a random number on the end of your service calls or you have to set the response headers in your server side page to prevent caching.  This one sounds similar to a <a href="http://thanksmister.com/?p=59">FireFox issue</a> I ran into a couple years back, but didn&#8217;t effect the results:</p>
<p><span id="more-508"></span></p>
<p><a href="http://www.judahfrangipane.com/blog/?p=87">http://www.judahfrangipane.com/blog/?p=87</a></p>
<p>The overwhelming number of posts on the subject suggested that Rails and Adobe both share the responsibility for this error (depending on if you are a Rails dev or a Flex dev, the debate rages as to who is to blame).   The fix seems to be changing status returned from Rails to something other than 201.  This seems to be the legit solution since the web service I was hitting is running Rails:</p>
<p><a href="http://stackoverflow.com/questions/354936/flex-2032-stream-error-in-ie-only">http://stackoverflow.com/questions/354936/flex-2032-stream-error-in-ie-only</a><br />
<a href="http://nachbar.name/blog/2008/06/14/flex-railsprotect_from_forgery-problem-with-rails-21-produces-ioerror-2032/">http://nachbar.name/blog/2008/06/14/flex-railsprotect_from_forgery-problem-with-rails-21-produces-ioerror-2032/</a><br />
<a href="http://onrails.org/articles/2008/02/20/dealing-with-http-errors-in-a-flex-with-rails-application">http://onrails.org/articles/2008/02/20/dealing-with-http-errors-in-a-flex-with-rails-application</a><br />
<a href="http://www.manning-sandbox.com/message.jspa?messageID=64372">http://www.manning-sandbox.com/message.jspa?messageID=64372</a><br />
<a href="http://nachbar.name/blog/tag/adobe-flex-programming/">http://nachbar.name/blog/tag/adobe-flex-programming/</a></p>
<p>If you think Adobe should fix the issue (as some Rails people protest) then you can view all the other bug reports Adobe already had lined up to fix that involve a 2032 Stream Error, just type in Explorer 2032 and you will find them:</p>
<p><a href="http://bugs.adobe.com/jira/secure/QuickSearch.jspa">http://bugs.adobe.com/jira/secure/QuickSearch.jspa</a></p>
<p>The workaround we ended up implemented was totally client based.  In the fault handler of this particular service request, I look for the errorID value of the Fault event and ignore it.   It was all I could do on short notice and I wasn&#8217;t about to convince the backend dudes that we needed to change the server response from 201 to 200, pick your battles and my first battle was to get this app into the war. </p>
<p>For me the real culprit is IE (easy target).  Something that works in every other browser but IE is so friggen familiar to anyone who has done any cross-browser work.  IE sucks, it has always sucked, and it will always suck, period.  My other thought is about web services and codes in general.   As an application developer, I use a lot of different services, consuming data from many different pipes.   I couldn&#8217;t tell you as a consumer of web services and an application designer what the value of having a returned  Status of 201 has over returning a Status of 200, can you?    I make a request, and if the request is good, just tell me ok, I don&#8217;t need to know that the server returned a HTTP Status Code of 311 (the server code for &#8220;I just made you a sandwich&#8221;).  I need to know only two basic things, was the request good, or did it explode?</p>
<p>I think some API dudes and backend dudes are purists, they want server codes to bubble up to the client so we can admire them, even though in practice (meaning you actually build applications with these services) you don&#8217;t really need the extra data.  Hey, I am totally used to having to make 5 service calls to accomplish one thing with a web service, I would never ask for the service to be changed to convenience the client, but some information is superfluous and could be scaled down. </p>
<p><strong>UPDATE</strong></p>
<p>Saw another blog post about the same topic at <a href="http://userflex.wordpress.com/2009/01/08/io-stream-errors-in-air/">UserFlex</a>.    </p>
<p>- Mister</p>
<p><map name='google_ad_map_508_1452acacd61817fb'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/508?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_508_1452acacd61817fb' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=508&amp;url= http%3A%2F%2Fwww.thanksmister.com%2Findex.php%2Farchive%2Fhttp-status-201-causing-flex-2032-error-in-ie-only%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://www.thanksmister.com/index.php/archive/http-status-201-causing-flex-2032-error-in-ie-only/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Xdrive AS3 Library</title>
		<link>http://www.thanksmister.com/index.php/archive/xdrive-as3-library/</link>
		<comments>http://www.thanksmister.com/index.php/archive/xdrive-as3-library/#comments</comments>
		<pubDate>Tue, 17 Jun 2008 22:25:41 +0000</pubDate>
		<dc:creator>Mister</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[API]]></category>

		<guid isPermaLink="false">http://thanksmister.com/?p=89</guid>
		<description><![CDATA[I have not posted in a long long while it seems. That would be nice if I were just hanging out on a beach some place. However, I have been busy doing lots of things for work and working on a new AS3 library. I have been developing for the past few months an AS3 [...]]]></description>
			<content:encoded><![CDATA[<p>I have not posted in a long long while it seems. That would be nice if I were just hanging out on a beach some place. However, I have been busy doing lots of things for work and working on a new AS3 library.</p>
<p>I have been developing for the past few months an AS3 library (<a title="as3xdrivelib" href="http://code.google.com/p/as3xdrivelib/" target="_blank">as3xdrivelib</a>) wrapper for the <a href="http://dev.aol.com/api/xdrive">Open Xdrive JSON API</a>.  Xdrive is an online storage platform and they offer a free JSON API for developers to create storage and other types of applications upon their service.   With Xdrive, each user gets a 5GB account for free, with additional costs for more storage.</p>
<p>I finally got around to making an AS3 library that wraps much of the Xdrive API and abstracts the inner workings from those developing Flex, AIR, or Flash applications.  The Xdrive API is extremely rich, it offers ways for users to share folders, collaborate on shared collections (look for a later post and application on this feature), and publish assets.  However,  main part of the platform is file management. </p>
<p><span id="more-89"></span></p>
<p>I have placed the library on Google Coders and included a Flex sample application for doing some basic operations with Xdrive. You just need an Xdrive account to start using the library.  I am hoping this helps developers starts to build some cool applications using the Xdrive plaform. Along with the library, I included an example application called Xdrive SlimDrive, which demonstrates the basic functionality for doing file management and shows how to work with the library.</p>
<p>===============<br />
as3xdrivelib<br />
===============</p>
<p>The as3xdrivelib project is a wrapper for the Open Xdrive JSON API. It provides much of the client-side functionality for applications; for example, authentication, uploading files, sharing files, and basic file management.</p>
<p>Project Page: <a href="http://code.google.com/p/as3xdrivelib">http://code.google.com/p/as3xdrivelib</a><br />
Project Group: <a href="http://groups.google.com/group/as3xdrivelib">http://groups.google.com/group/as3xdrivelib</a></p>
<p>Authors: Michael Ritchie, Maria Vazquez, Lucas McGregor, Joe Provost<br />
Dependencies: corelib (<a href="http://code.google.com/p/as3corelib">http://code.google.com/p/as3corelib</a>)</p>
<p><strong>How to use the as3xdrivelib with Cairngorm.</strong></p>
<p>I didn&#8217;t get a chance to post this to the Google Code, but I wanted to show a quick login example that uses the library with Cairngorm. The following example uses a very simplistic login screen with a Cairngorm Event/Command/Delegate to login to a users Xdrive account.  The example is pretty straight forward if you know Cairngorm already.  There are some things to notice in the Delegate and Command.  In the Delegate, notice how the I setup the delegate to use the as3xdrivelib as a service and how I mapped the events back to the command.</p>
<p><div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><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 /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> login<span style="color: #66cc66;">&#40;</span>user:User<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> &nbsp;<span style="color: #66cc66;">&#123;</span> &nbsp;&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">var</span> token : XdriveAPIToken = service.<span style="color: #006600;">login</span><span style="color: #66cc66;">&#40;</span>user<span style="color: #66cc66;">&#41;</span>; &nbsp;&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp;token.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>XdriveAPIEvent.<span style="color: #006600;">API_RESULT</span>, responder.<span style="color: #006600;">result</span><span style="color: #66cc66;">&#41;</span>; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp;token.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>XdriveAPIEvent.<span style="color: #006600;">API_FAILURE</span>, responder.<span style="color: #006600;">fault</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
</p>
<p>In the Command notice how I map the payload (user) on the API result to the Model.  This is explained in the documentation for the library, but basically the payload contains a return variable(s) name on the payload event that almost always represents the object you send to the library method. </p>
<p><div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><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 /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> result<span style="color: #66cc66;">&#40;</span> event : <span style="color: #0066CC;">Object</span> <span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> &nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #66cc66;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">var</span> resultEvent : XdriveAPIEvent = XdriveAPIEvent<span style="color: #66cc66;">&#40;</span>event<span style="color: #66cc66;">&#41;</span>; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp;model.<span style="color: #006600;">user</span> = resultEvent.<span style="color: #006600;">payload</span>.<span style="color: #006600;">user</span> as User; <span style="color: #808080; font-style: italic;">// store value in model for binding &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p><a href="http://thanksmister.com/examples/xdrivelogincairngorm/main.html">Example File</a> (right-click to view source/download)</p>
<p><strong>Update</strong></p>
<p>AOL killed Xdrive and so the API is also dead, code still available but its not defunct and won&#8217;t work with Xdrive.   Thanks AOL for killing yet another good product. </p>
<p>- Mister</p>
<p><map name='google_ad_map_89_1452acacd61817fb'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/89?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_89_1452acacd61817fb' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=89&amp;url= http%3A%2F%2Fwww.thanksmister.com%2Findex.php%2Farchive%2Fxdrive-as3-library%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://www.thanksmister.com/index.php/archive/xdrive-as3-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom RichTextEditor</title>
		<link>http://www.thanksmister.com/index.php/archive/custom-richtexteditor/</link>
		<comments>http://www.thanksmister.com/index.php/archive/custom-richtexteditor/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 23:18:08 +0000</pubDate>
		<dc:creator>Mister</dc:creator>
				<category><![CDATA[Component]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[RichTextEditor]]></category>

		<guid isPermaLink="false">http://thanksmister.com/?p=88</guid>
		<description><![CDATA[One of the longest running post on my blog has been about creating XHTML output from the Flex RichTextEditor control. I always thought it would would be nice if someone took all the comments and suggestions for that post and created a customized control that outputs proper XTHML. Well, Axel Jenson has created such a [...]]]></description>
			<content:encoded><![CDATA[<p>One of the longest running <a href="http://thanksmister.com/?p=17">post on my blog</a> has been about creating XHTML output from the Flex RichTextEditor control.  I always thought it would would be nice if someone took all the comments and suggestions for that post and created a customized control that outputs proper XTHML.   Well, <a href="http://www.axelscript.com/2008/03/24/customrichtexteditor-with-xhtml-text/">Axel Jenson</a> has created such a custom control.   I want to send many thanks to all those who posted over the past year and to Axel for stepping up and creating this custom control for Flex.  Give the component a try and let Axel know what you think. </p>
<p>-Mr</p>
<p><map name='google_ad_map_88_1452acacd61817fb'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/88?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_88_1452acacd61817fb' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=88&amp;url= http%3A%2F%2Fwww.thanksmister.com%2Findex.php%2Farchive%2Fcustom-richtexteditor%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://www.thanksmister.com/index.php/archive/custom-richtexteditor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Omniture Tracking in Flash, Flex and AIR Applications</title>
		<link>http://www.thanksmister.com/index.php/archive/omniture-tracking-in-air-applications/</link>
		<comments>http://www.thanksmister.com/index.php/archive/omniture-tracking-in-air-applications/#comments</comments>
		<pubDate>Sun, 27 Jan 2008 23:01:13 +0000</pubDate>
		<dc:creator>Mister</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Omniture]]></category>
		<category><![CDATA[ActionSource]]></category>
		<category><![CDATA[HTMLLoader]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://thanksmister.com/?p=85</guid>
		<description><![CDATA[If you are developing Enterprise level applications chances are you are either used Omniture or you will be asked to integrate with Omniture tracking services. This post is not really about the specifics of Omniture tracking, but rather about the implementation methods for Flash, Flex, and AIR (with Flex). Usually, Omniture tracking events are sent [...]]]></description>
			<content:encoded><![CDATA[<p>If you are developing Enterprise level applications chances are you are either used <a href="http://en.wikipedia.org/wiki/Omniture" target="_blank">Omniture</a> or you will be asked to integrate with Omniture tracking services. This post is not really about the specifics of Omniture tracking, but rather about the implementation methods for Flash, Flex, and AIR (with Flex).    Usually, Omniture tracking events are sent using JavaScript on a web page.  An HTML page would include the Omniture JavaScript library and events in your web application would call methods in the libary.   </p>
<p>When creating RIA with Flex or Flash you have a couple of options. Ominture provides a proprietary ActionScript library, called ActionSource, for easy integration. ActionSource is a Flash MXP component library that transmits analytic data to Omniture without relying on calling JavaScript methods.  This implementation is best for situation when your have a Flash file that can not call JavaScript. <del datetime="2008-08-12T17:19:54+00:00"><a href="http://studio.brightcove.com/library/howto/actionsource/" target="_blank">Brightcove</a> has a good article describing this type of implemenation.</del> Integrating Omniture services with Flex does not require the ActionSource library.  </p>
<p>Flex has the ability to write and call JavaScript directly.  With Flex, you can use the ExternalInterface call to call JavaScript functions on the page.  So a typical call might look like this:</p>
<p><span id="more-85"></span></p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><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="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ExternalInterface.<span style="color: #0066CC;">call</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;trackOmniture&quot;</span>, omnitureType<span style="color: #66cc66;">&#41;</span>;</div></td></tr></tbody></table></div>
<p>Where the value for the omnitureType represents the information you want to transmit to Omniture for analysis and &#8220;trackOmniture&#8221; is the name of a JavaScript method on the HTML embed page for the Flex application that calls Omniture methods in the included JS library from Oniture for HTML integration.  Just setup your account information and other parameters in the Omniture JS library like you normally would for tracking Omniture in HTML-based applications.</p>
<p>Adobe AIR introdocues some new challenges and new solutions for Omniture tracking.    An AIR application does not run in a web browser, its a desktop application that can make HTTP requests.    Using ExternalInterface calls to an embed HTML page is not an option in this scenario.    Now, you can create an entire AIR application with just HTML and JavaScript.  However, in our implemenation we want to use Flex in AIR to create the application.    </p>
<p>Lets talk a little bit about the new <a href="http://labs.adobe.com/wiki/index.php/AIR:HTML_Security_FAQ" target="_blank">AIR security model</a> introduced with Beta 3.   According to Adobe :</p>
<blockquote><p><span style="font-style: italic;">One of the main threats facing HTML applications, whether desktop or web, are injection attacks which result in malicious code execution. Code is usually injected via a few common vectors such as via URL handling (â€œjavascript:â€ and other dangerous schemes), eval() and assigning external HTML content to DOM elements such as innerHTML and outerHTML.</span></p></blockquote>
<p>As a result of the security vulnerability AIR now uses two kinds of sandboxes, one is called the Application sandbox wich allows full access to AIR API&#8217;s but disables the JavaScript parser after the initial load to prevent exposure of the API to possibly harmful JavaScript calls (like eval()).   The other sandbox is the &#8220;Non-application&#8221; sandbox.  This is where you can execute JavaScript like you would in a browser, but it does not have direct access to the AIR system API&#8217;s and therefore can&#8217;t raise havoc on your application.   Now to talk between the two sandboxes you need to use Adobe&#8217;s new <a href="http://labs.adobe.com/wiki/index.php/AIR:HTML_Security_FAQ" target="_blank">SandboxBridge</a> mechanism which can expose methods in both the parentSandboxBridge (the application sandbox) and the childSandboxBridge (the non-application sandbox location).  So what does this mean for handling Omniture tracking in AIR?</p>
<p>
Well, the Omniture JavaScript file is pulled from a separate domain and contains JavaScript deemed a security risk.  This means that Omniture needs to run in the non-application sandbox, but the application reporting calls need to be made in the application sandbox.</p>
<p>This makes for an interesting implementation.  Adobe does offer a good example of <a href="http://livedocs.adobe.com/labs/air/1/devappshtml/help.html?content=security_1.html" target="_blank">scripting between content in different domains</a>. In this method, the main HTML content is loaded into the initial window of the application security sandbox, while the content from another domain is loaded into a &lt;iframe&gt; that specifies the content is placed in a non-application security sandbox.  </p>
<p>Our application is built Flex within an AIR project, so we need to change the example from Adobe just a little bit to fit our specific implementation since they are building an AIR application with HTML.  We are going to create an MXML file that loads an HTML page from a directory within our application called &#8220;omniture&#8221;.  We do this using an <a href="http://livedocs.adobe.com/labs/air/1/devappshtml/help.html?content=AboutHTMLApplications_02.html" target="_blank">HTMLLoader</a> that loads our main HTML content (track.html).  We use the instance of the HTMLoader to call a method within the loaded HTML window called &#8220;track&#8221;.  Loading HTML into an HTMLLoader control will execute the HTML code on that page.  So this page contains basic HTML and JavaScript that does not have a security risk.  This loaded HTML page is not displayed inside our application the HTMLLoader is used merely to load and execute the HTML code, and also serve as a way to reference the JS methods of the loaded content.</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:640px;"><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 /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">html</span>:HTMLLoader; <span style="color: #808080; font-style: italic;">// omniture tracker</span><br />
<span style="color: #808080; font-style: italic;">/**<br />
* @private<br />
* Create an HTML object to handle Omniture tracking within <br />
* the application. <br />
**/</span><br />
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> createHTMLTracker<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">html</span> = <span style="color: #000000; font-weight: bold;">new</span> HTMLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//html.addEventListener(Event.COMPLETE, onHTMLLoadComplete);</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">html</span>.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;omniture/tracking.html&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #808080; font-style: italic;">/**<br />
*Tracks Ominture events by callint a JavaScript function within the page<br />
*loaded into an HTML control.<br />
*@private<br />
**/</span><br />
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> omnitureHandler<span style="color: #66cc66;">&#40;</span>omnitureType<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp;<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>omnitureType <span style="color: #66cc66;">!</span>= <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp;<span style="color: #0066CC;">try</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp;<span style="color: #0066CC;">html</span>.<span style="color: #006600;">window</span>.<span style="color: #006600;">track</span><span style="color: #66cc66;">&#40;</span>omnitureType<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp;<span style="color: #66cc66;">&#125;</span> <span style="color: #0066CC;">catch</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:<span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">message</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #66cc66;">&#125;</span><br />
&nbsp;<span style="color: #66cc66;">&#125;</span><br />
&nbsp;<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>The track.html page also loads another HTML page into an &lt;iframe&gt; tag and establishses our SandboxBridge between the track.html page and the loaded HTML page.   This second HTML paged (ui.html) loaded into the iframe includes our Omniture JavaScript library. The ui.html page can contain the JS library because we specify in the properties of the iframe that the content be placed in a non-application security sandbox.   Our project includes a sub-directory called &#8220;omniture&#8221; that has two HTML pages, the tracking.html and the ui.html page.  It also includes one more file, the AIRAliases.js file, which allows us to use AIR shortcuts within the tracking.html file.   Below is the code for the tracking.html page this page does stray too far away from the example provided by Adobe, just notice the iframe tag settings for loading pages from a sub-directory within your AIR project.</p>
<p><ul>
track.html</ul>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:640px;"><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 /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&lt;</span>html<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>head<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&lt;</span>script <span style="color: #0066CC;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> src=<span style="color: #ff0000;">&quot;AIRAliases.js&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// include the AIRAlias.js file to access AIR short cuts, like air.trace</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&lt;/</span>script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&lt;</span>script <span style="color: #0066CC;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// create an object that will be used to expose AIR functionality </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// (developer functions) to the browser sandbox</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> Exposed = <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// expose the trace method</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Exposed.<span style="color: #0066CC;">trace</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>str<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; air.<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>str<span style="color: #66cc66;">&#41;</span>; &nbsp;<span style="color: #808080; font-style: italic;">// this trace shows up in debugger</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> doLoad<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// place Exposed on the parentSandboxBridge property of the browser sandbox (iframe)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> frame = document.<span style="color: #006600;">getElementById</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'child'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">contentWindow</span>.<span style="color: #006600;">parentSandboxBridge</span> = Exposed;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// get the functions exposed from the Browser Sandbox</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; window.<span style="color: #006600;">track</span> = document.<span style="color: #006600;">getElementById</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'child'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">contentWindow</span>.<span style="color: #006600;">childSandboxBridge</span>.<span style="color: #006600;">trackPage</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#125;</span> &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&lt;/</span>script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>head<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>body <span style="color: #0066CC;">onload</span>=<span style="color: #ff0000;">&quot;doLoad();&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>iframe<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; id=<span style="color: #ff0000;">&quot;child&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; src=<span style="color: #ff0000;">&quot;http://localhost/omniture/ui.html&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sandboxRoot=<span style="color: #ff0000;">&quot;http://localhost/omniture/&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; documentRoot=<span style="color: #ff0000;">&quot;app:/omniture/&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>iframe<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>body<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;/</span>html<span style="color: #66cc66;">&gt;</span></div></td></tr></tbody></table></div>
<p>The ui.html page is loaded within the iframe, who sets it to load the content in the non-application security box (sandboxRoot=&#8221;http://localhost/omniture/&#8221;).   The ui.html page uses JS to include the Omniture library (my_omniture_endpoint is specific to each client for Omniture tracking):</p>
<p>&lt;script src=&#8221;http://my_omniture_endpoint/omniunih.js&#8221; type=&#8221;text/javascript&#8221;/&gt;</p>
<p>The page also establishes our Omniture suite name:</p>
<p>var s_account = &#8220;mysuitename&#8221;;</p>
<p>The method track is exposed to the track.html window; this is in turn called from our MXML application, passing in Omniture tracking information.   The ui.html page makes all the necessary calls to Omniture within the track method.   Everything is secure and AIR is happy.  Below is the ui.html code, I commented out the client specific information.</p>
<p><ul>
ui.html</ul>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:640px;"><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 /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&lt;</span>html<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>head<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> s_account = <span style="color: #ff0000;">&quot;&quot;</span>; <span style="color: #808080; font-style: italic;">// your omniture suite name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>script <span style="color: #0066CC;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// developer function implemented in the browser sandbox</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> track<span style="color: #66cc66;">&#40;</span>pagename<span style="color: #66cc66;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Call your Omniture JS library methods here.....</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// trace out the return in the parent</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parentSandboxBridge.<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;tracked: &quot;</span> + pagename<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> doLoad<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// expose this function for the application sandbox by writing to the childSandboxBridge property of the window</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; childSandboxBridge = <span style="color: #66cc66;">&#123;</span><span style="color: #ff0000;">'trackPage'</span>: track<span style="color: #66cc66;">&#125;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&lt;</span>script src=<span style="color: #ff0000;">&quot;http://my_omniture_endpoint/omniunih.js&quot;</span> <span style="color: #0066CC;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>head<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>body <span style="color: #0066CC;">onload</span>=<span style="color: #ff0000;">&quot;doLoad();&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>body<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;/</span>html<span style="color: #66cc66;">&gt;</span></div></td></tr></tbody></table></div>
<p>With this implementation method you can perform Omniture tracking from inside your AIR applications just like you would if they were web-based applications or Flex applications using ExternalInterface calls.  The added benefit of including the Omniture JS library dynamically within the ui.html window is that the application always gets the latest version of the JS library.  We could have taken the entire JS library and wrote it to a local .js file within our project.  We could have also rewritten the JS library to exclude the extensive use of &#8220;eval()&#8221; and run it within the application security sandbox. However, I think this implementation allows the most flexibility.  The new AIR security model doesn&#8217;t prevent us from running JavaScript; it just requires us to take some extra steps to work with content from other domains, all while being secure.   </p>
<p>- Mister</p>
<p><map name='google_ad_map_85_1452acacd61817fb'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/85?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_85_1452acacd61817fb' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=85&amp;url= http%3A%2F%2Fwww.thanksmister.com%2Findex.php%2Farchive%2Fomniture-tracking-in-air-applications%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://www.thanksmister.com/index.php/archive/omniture-tracking-in-air-applications/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Better (Cooler) Flex Preloader</title>
		<link>http://www.thanksmister.com/index.php/archive/better-cooler-flex-preloader/</link>
		<comments>http://www.thanksmister.com/index.php/archive/better-cooler-flex-preloader/#comments</comments>
		<pubDate>Tue, 24 Jul 2007 18:06:54 +0000</pubDate>
		<dc:creator>Mister</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://thanksmister.com/?p=67</guid>
		<description><![CDATA[Jesse Warden has a great new article about developing a custom Flex preloader using Flash (a cooler preloader as he calls it).&#160; He also has a new look for his blog that you can now read (just kidding Jesse).&#160;&#160; Jesse&#8217;s post relates to my previous post regarding Error #2025.&#160; When I developed a custom preloader [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://jessewarden.com/2007/07/making-a-cooler-preloader-in-flex-part-1-of-3.html" target="_blank">Jesse Warden</a> has a great new article about developing a custom Flex preloader using Flash (a cooler preloader as he calls it).&nbsp; He also has a new look for his blog that you can now read (just kidding Jesse).&nbsp;&nbsp; Jesse&#8217;s post relates to my previous post regarding <a href="http://thanksmister.com/?p=64">Error #2025</a>.&nbsp; When I developed a custom preloader in Flash I made the terrible mistake of using a Flash 9 component that caused a huge error in my Flex app.&nbsp;&nbsp;&nbsp; Jesse&#8217;s post is part 1 of 3, so look forward to subsequent posts.&nbsp; </p>
<p><map name='google_ad_map_67_1452acacd61817fb'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/67?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_67_1452acacd61817fb' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=67&amp;url= http%3A%2F%2Fwww.thanksmister.com%2Findex.php%2Farchive%2Fbetter-cooler-flex-preloader%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://www.thanksmister.com/index.php/archive/better-cooler-flex-preloader/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Error #2025 &#8211; Clash between Flex 2 &amp; Flash CS3</title>
		<link>http://www.thanksmister.com/index.php/archive/error-2025-clash-between-flex-2-flash-cs3/</link>
		<comments>http://www.thanksmister.com/index.php/archive/error-2025-clash-between-flex-2-flash-cs3/#comments</comments>
		<pubDate>Tue, 26 Jun 2007 14:50:13 +0000</pubDate>
		<dc:creator>Mister</dc:creator>
				<category><![CDATA[Component]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://thanksmister.com/?p=64</guid>
		<description><![CDATA[I got my new copy of Flash CS3 and proceeded to make a new preloader for my Flex application.&#160; I made a document Class for my CS3 file and attached a CS3&#160;ProgressBar component.&#160; I had a public function in the Document Class for setting the progress of the Flex preloading.&#160;&#160; I dropped the SWF file [...]]]></description>
			<content:encoded><![CDATA[<p>I got my new copy of Flash CS3 and proceeded to make a new preloader for my Flex application.&nbsp; I made a document Class for my CS3 file and attached a CS3&nbsp;ProgressBar component.&nbsp; I had a public function in the Document Class for setting the progress of the Flex preloading.&nbsp;&nbsp; I dropped the SWF file into my Flex document and set up all the preloading code.&nbsp; If you set&nbsp;a preloader in Flex it will load that file in the first frame before it loads the rest of the Flex application.&nbsp; You can do progressive preloading the same way you would in Flash.&nbsp;&nbsp; The CS3 preloader worked like a charm because with CS3, I can now (though still not elegantly) talk to the functions inside the loaded SWF file.&nbsp;&nbsp; Here is the CS3 Document Class code:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:640px;"><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 /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">package com.<span style="color: #006600;">preloader</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> fl.<span style="color: #006600;">controls</span>.<span style="color: #006600;">ProgressBar</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> fl.<span style="color: #006600;">controls</span>.<span style="color: #006600;">ProgressBarMode</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> WelcomeScreenClass <span style="color: #0066CC;">extends</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> progressBar:ProgressBar;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> WelcomeScreenClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; progressBar = <span style="color: #000000; font-weight: bold;">new</span> ProgressBar<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; progressBar.<span style="color: #006600;">indeterminate</span> = <span style="color: #000000; font-weight: bold;">false</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; progressBar.<span style="color: #006600;">mode</span> = ProgressBarMode.<span style="color: #006600;">MANUAL</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; progressBar.<span style="color: #006600;">setSize</span><span style="color: #66cc66;">&#40;</span>150, 22<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; progressBar.<span style="color: #006600;">move</span><span style="color: #66cc66;">&#40;</span>10, 50<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; progressBar.<span style="color: #0066CC;">setStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;barPadding&quot;</span>, 3<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; progressBar.<span style="color: #006600;">setProgress</span><span style="color: #66cc66;">&#40;</span>50, 100<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addChild<span style="color: #66cc66;">&#40;</span>progressBar<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setLoaderProgress<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">loaded</span>:<span style="color: #0066CC;">Number</span>, total:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; progressBar.<span style="color: #006600;">setProgress</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">loaded</span>, total<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;loaded: &quot;</span> + <span style="color: #0066CC;">loaded</span> + <span style="color: #ff0000;">&quot; of total: &quot;</span> + total<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>This all sounds good so far, a decent marriage between Flash and Flex, weeee!!&nbsp;&nbsp; About a week later I noticed a bug in my Flex application.&nbsp; Every time you hit the Tab key on any dialog created with the PopUpManager or even the Alert, I would get the following error code:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><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="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ArgumentError: <span style="color: #0066CC;">Error</span> <span style="color: #808080; font-style: italic;">#2025: The supplied DisplayObject must be a child of the caller.</span><br />
&nbsp;at flash.<span style="color: #006600;">display</span>::DisplayObjectContainer<span style="color: #66cc66;">/</span>getChildIndex<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp;at mx.<span style="color: #006600;">core</span>::Container<span style="color: #66cc66;">/</span>getChildIndex<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp;at mx.<span style="color: #006600;">containers</span>::Panel<span style="color: #66cc66;">/</span>getChildIndex<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp;at fl.<span style="color: #006600;">managers</span>::FocusManager<span style="color: #66cc66;">/</span>::getChildIndex<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp;at fl.<span style="color: #006600;">managers</span>::FocusManager<span style="color: #66cc66;">/</span>::sortByDepth<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp;at fl.<span style="color: #006600;">managers</span>::FocusManager<span style="color: #66cc66;">/</span>::sortByTabIndex<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp;at <span style="color: #0066CC;">Array</span>$<span style="color: #66cc66;">/</span><span style="color: #0066CC;">Array</span>::_sort<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp;at <span style="color: #0066CC;">Array</span><span style="color: #66cc66;">/</span>http:<span style="color: #808080; font-style: italic;">//adobe.com/AS3/2006/builtin::sort()</span><br />
&nbsp;at fl.<span style="color: #006600;">managers</span>::FocusManager<span style="color: #66cc66;">/</span>::sortFocusableObjectsTabIndex<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp;at fl.<span style="color: #006600;">managers</span>::FocusManager<span style="color: #66cc66;">/</span>::sortFocusableObjects<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp;at fl.<span style="color: #006600;">managers</span>::FocusManager<span style="color: #66cc66;">/</span>::keyDownHandler<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></div></td></tr></tbody></table></div>
<p>This particular bug is very vague and a search of the Internet yielded nothing that seem to fit my situation.&nbsp; I am using Cairngorm with Modules and my suspicion was that I had created a shared code typology.&nbsp;&nbsp; Modules are cool because they can reduce your initial application load, but they are a real pain in the ass to manage because you run into these strange bugs that always seem related to a race condition with loading one Class or Manager into one module.&nbsp;&nbsp;&nbsp; I spent a few days tracking down this issue, testing each module, commenting out code.&nbsp; I finally created a new project without any modules, determined that it was the shared code typology issue.&nbsp; I still had the same issue.</p>
<p>Something about the error dawned on me, the &#8220;fl.managers&#8221;.&nbsp;&nbsp; This is a CS3 code package that Flex does not have.&nbsp;&nbsp; I then decided to remove my CS3 prelaoder, and guess what, the bug went away.&nbsp; I had inadvertently created my own bug by using CS3 with the new ProgressBar component.&nbsp; This component most likely extends UIComponent, which contains the FocusManager, and therefore, causes the issue with the FocusManager in Flex.&nbsp; According to shared code typology 101, the first instance of the loaded manager wins.</p>
<p>The solution was to yank out the CS3&nbsp;ProgressBar component and just create my own progress bar using the Flash drawing tools.&nbsp;&nbsp; This was a tough error, and probably not the first one that will be encountered as Flash and Flex start mingling more in the near future.&nbsp;&nbsp; </p>
<p>-mr</p>
<p><map name='google_ad_map_64_1452acacd61817fb'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/64?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_64_1452acacd61817fb' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=64&amp;url= http%3A%2F%2Fwww.thanksmister.com%2Findex.php%2Farchive%2Ferror-2025-clash-between-flex-2-flash-cs3%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://www.thanksmister.com/index.php/archive/error-2025-clash-between-flex-2-flash-cs3/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>
