<?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>Richard Lord &#187; Modules</title>
	<atom:link href="http://www.richardlord.net/blog/tag/modules/feed" rel="self" type="application/rss+xml" />
	<link>http://www.richardlord.net</link>
	<description>Actionscript/Flex, PHP and Java developer</description>
	<lastBuildDate>Mon, 23 Jan 2012 17:07:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>ModuleLoader ApplicationDomain</title>
		<link>http://www.richardlord.net/blog/moduleloader-applicationdomain</link>
		<comments>http://www.richardlord.net/blog/moduleloader-applicationdomain#comments</comments>
		<pubDate>Wed, 27 May 2009 10:20:49 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Modules]]></category>

		<guid isPermaLink="false">http://www.bigroom.co.uk/blog/moduleloader-applicationdomain/</guid>
		<description><![CDATA[<p>By default, the module loader loads modules in a new application domain. This means the classes in the module are not accessible to the main application, which can cause problems particularly when using reflection...</p>]]></description>
			<content:encoded><![CDATA[<p>By default, the module loader loads modules in a new application domain. This means the classes in the module are not accessible to the main application, which can cause problems particularly when using reflection (I stumbled into this when using <a href="http://code.google.com/p/smartypants-ioc/">SmartyPants</a> with modules).</p>

<p>Fortunately, the ModuleLoader component has a property for setting the application domain of the module it loads &#8211; the unsurprisingly named applicationDomain property. Setting this to ApplicationDomain.currentContext before loading the module brings the module into the same domain as the main application, and all is well.</p>

<p>Except, if you want to load the module immediately you may be tempted to do something like this.</p>

<pre class="code">&lt;mx:ModuleLoader url="module.swf"
  applicationDomain="{ApplicationDomain.currentDomain}"/&gt;</pre>

<p>Unfortunately, this won&#8217;t work because the module loader will start loading the module before the application domain has been set &#8211; setting properties to static values (as for the url in this code) happens before setting properties to bound values (as for the applicationDomain in this code) so the url is set first and triggers the load before the applicationDomain is set.</p>

<p>To solve this, you need either to load the module later or set the applicationDomain earlier.<p>

<p>To load the module later:</p>

<pre class="code">&lt;mx:ModuleLoader id="modLoader"
  applicationDomain="{ApplicationDomain.currentDomain}"
  creationComplete="modLoader.loadModule('module.swf')"/&gt;</pre>

<p>To set the applicationDomain sooner:</p>

<pre class="code">&lt;mx:ModuleLoader id="modLoader"
  url="module.swf"
  preinitialize="modLoader.applicationDomain=
    ApplicationDomain.currentDomain"/&gt;</pre>

]]></content:encoded>
			<wfw:commentRss>http://www.richardlord.net/blog/moduleloader-applicationdomain/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

