<?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/"
	xmlns:series="http://unfoldingneurons.com/"
	>

<channel>
	<title>AaronHardy.com &#187; security</title>
	<atom:link href="http://aaronhardy.com/tag/security/feed/" rel="self" type="application/rss+xml" />
	<link>http://aaronhardy.com</link>
	<description>For all your Aaron Hardy needs.</description>
	<lastBuildDate>Fri, 20 Apr 2012 14:53:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Loading a Remote Module into a Local App</title>
		<link>http://aaronhardy.com/flex/loading-a-remote-module-into-a-local-app/</link>
		<comments>http://aaronhardy.com/flex/loading-a-remote-module-into-a-local-app/#comments</comments>
		<pubDate>Sat, 15 Aug 2009 02:39:24 +0000</pubDate>
		<dc:creator>Aaron Hardy</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[crossdomain]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[font]]></category>
		<category><![CDATA[IModuleInfo]]></category>
		<category><![CDATA[loadResourceModule]]></category>
		<category><![CDATA[loadStyleDeclarations]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[ModuleInfo]]></category>
		<category><![CDATA[ModuleManager]]></category>
		<category><![CDATA[ModuleMarshaller]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[style]]></category>
		<category><![CDATA[StyleManager]]></category>
		<category><![CDATA[SWF is not a loadable module]]></category>
		<category><![CDATA[Unable to load resource module]]></category>

		<guid isPermaLink="false">http://aaronhardy.com/?p=295</guid>
		<description><![CDATA[At work, we deal a lot with loading modules residing on remote servers into our applications running locally.  By locally I mean from a local path on our hard drives (the default Flex Builder run/debug settings), not on a local web server instance (localhost).  Depending on what type of module we are loading, we would [...]]]></description>
			<content:encoded><![CDATA[<p>At work, we deal a lot with loading modules residing on remote servers into our applications running locally.  By locally I mean from a local path on our hard drives (the default Flex Builder run/debug settings), not on a local web server instance (localhost).  Depending on what type of module we are loading, we would normally use one of Flex&#8217;s built-in functions to load modules:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// Loading a language resource module:</span>
resourceManager.<span style="color: #006600;">loadResourceModule</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'http://aaronhardy.com/en_US_ResourceModule.swf'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// Loading a style module (e.g., a compiled font swf):</span>
StyleManager.<span style="color: #006600;">loadStyleDeclarations</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://aaronhardy.com/fonts/Astroid.swf&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// Loading miscellaneous modules:</span>
<span style="color: #000000; font-weight: bold;">var</span> moduleInfo:IModuleInfo = ModuleManager.<span style="color: #006600;">getModule</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'http://aaronhardy.com/MyModule.swf'</span><span style="color: #66cc66;">&#41;</span>;
moduleInfo.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>But these methods of importing modules result in errors like the following:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">Unable to <span style="color: #0066CC;">load</span> resource module from http:<span style="color: #808080; font-style: italic;">//aaronhardy.com/en_US_ResourceModule.swf</span>
<span style="color: #0066CC;">Error</span>: Unable to <span style="color: #0066CC;">load</span> style<span style="color: #66cc66;">&#40;</span>SWF is <span style="color: #0066CC;">not</span> a loadable module<span style="color: #66cc66;">&#41;</span>: http:<span style="color: #808080; font-style: italic;">//aaronhardy.com/fonts/Astroid.swf.</span></pre></div></div>

<p><span id="more-295"></span>One way to solve these issues is by <a href="http://bradywhite.net/2008/05/05/flex-3-how-to-load-a-complied-css-swf/" target="_blank">using a crossdomain policy file on the server and then using a local apache instance to run the application</a>.  In my talks with the folks at Adobe, this seems to be their standard workflow which may be why we haven&#8217;t heard more about these problems.  However, my workflow is to NOT have a local web <a href="http://www.hostingobserver.com/server-hosting.php" target="_blank">hosting server</a> running and I don&#8217;t want to have one running just to get around these errors.</p>
<p>As of Flex SDK 3.2, Adobe introduced a new parameter to IModuleInfo.load() for raw module bytes.  As a result, we can now retrieve the remote module&#8217;s raw bytes using a URLLoader and then load them directly as a module using the IModuleInfo.load() method.  The module is now part of the same security domain as the main application and no errors are thrown.</p>
<p>I&#8217;ve bundled up this logic into a class called ModuleMarshaller which is found below.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package com.<span style="color: #006600;">aaronhardy</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">ErrorEvent</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">EventDispatcher</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">IOErrorEvent</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">SecurityErrorEvent</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLLoader</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLLoaderDataFormat</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLRequest</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">ByteArray</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">events</span>.<span style="color: #006600;">ModuleEvent</span>;
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">modules</span>.<span style="color: #006600;">IModuleInfo</span>;
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">modules</span>.<span style="color: #006600;">ModuleManager</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">/**
	 * Dispatched once module loading is complete.
	 */</span>
	<span style="color: #66cc66;">&#91;</span>Event<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;ready&quot;</span>, <span style="color: #0066CC;">type</span>=<span style="color: #ff0000;">&quot;mx.events.ModuleEvent&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">/**
	 * Dispatched if an error is encountered while loading the module.
	 */</span>
	<span style="color: #66cc66;">&#91;</span>Event<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;error&quot;</span>, <span style="color: #0066CC;">type</span>=<span style="color: #ff0000;">&quot;mx.events.ModuleEvent&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">/**
	 * Loads a remote module.  Specifically, this is a workaround to allow an application being run
	 * locally (not using a web server) to load a module residing on a remote server.
	 * Usually, when attemping to do so using resourceManager.loadResourceModule(),
	 * StyleManager.loadStyleDeclarations(), or IModuleInfo.load() without passing in bytes
	 * results in errors such as the following:
	 *
	 * Error: Unable to load resource module from http://aaronhardy.com/locales/en_US.swf
	 * Error: Unable to load style(SWF is not a loadable module): http://aaronhardy.com/fonts/Astroid.swf.
	 *
	 * Be aware that any module imported with this class may have access to anything within
	 * your application's security sandbox.
	 */</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ModuleMarshaller <span style="color: #0066CC;">extends</span> EventDispatcher
	<span style="color: #66cc66;">&#123;</span>
		protected <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">url</span>:<span style="color: #0066CC;">String</span>;
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		 * Appears to need to be stored in the class scope, otherwise garbage collection
		 * wipes out some of the event handling within IModuleInfo.
		 */</span>
		protected <span style="color: #000000; font-weight: bold;">var</span> module:IModuleInfo;
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		 * Constructor.
		 * @param url The external module to load into the application.
		 */</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ModuleMarshaller<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">url</span>:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">url</span> = <span style="color: #0066CC;">url</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		 * Starts the loading process by loading in the module as bytes.
		 */</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> loadModule<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:URLLoader
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> urlRequest:URLRequest = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #000000; font-weight: bold;">var</span> urlLoader:URLLoader = <span style="color: #000000; font-weight: bold;">new</span> URLLoader<span style="color: #66cc66;">&#40;</span>urlRequest<span style="color: #66cc66;">&#41;</span>;
			urlLoader.<span style="color: #006600;">dataFormat</span> = URLLoaderDataFormat.<span style="color: #006600;">BINARY</span>;
			urlLoader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, bytesLoadedHandler<span style="color: #66cc66;">&#41;</span>;
			urlLoader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>IOErrorEvent.<span style="color: #006600;">IO_ERROR</span>, errorHandler<span style="color: #66cc66;">&#41;</span>;
			urlLoader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>SecurityErrorEvent.<span style="color: #006600;">SECURITY_ERROR</span>, errorHandler<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">return</span> urlLoader;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		 * Once the module bytes are loaded, convert them back into a module within the
		 * application's security domain.
		 */</span>
		protected <span style="color: #000000; font-weight: bold;">function</span> bytesLoadedHandler<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> styleModuleBytes:ByteArray = ByteArray<span style="color: #66cc66;">&#40;</span>URLLoader<span style="color: #66cc66;">&#40;</span>event.<span style="color: #0066CC;">target</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#41;</span>;
			module = ModuleManager.<span style="color: #006600;">getModule</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#41;</span>;
			module.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>ModuleEvent.<span style="color: #006600;">READY</span>, modReadyHandler<span style="color: #66cc66;">&#41;</span>;
			module.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>ModuleEvent.<span style="color: #0066CC;">ERROR</span>, errorHandler<span style="color: #66cc66;">&#41;</span>;
			module.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">null</span>, <span style="color: #000000; font-weight: bold;">null</span>, styleModuleBytes<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		 * Once the module information is loaded, use the factory to create an instance of the
		 * module.
		 */</span>
		protected <span style="color: #000000; font-weight: bold;">function</span> modReadyHandler<span style="color: #66cc66;">&#40;</span>event:ModuleEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			ModuleManager.<span style="color: #006600;">getModule</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">factory</span>.<span style="color: #006600;">create</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			dispatchEvent<span style="color: #66cc66;">&#40;</span>event.<span style="color: #006600;">clone</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		 * Reports errors that may have occurred.
		 */</span>
		protected <span style="color: #000000; font-weight: bold;">function</span> errorHandler<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>event is ModuleEvent<span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				dispatchEvent<span style="color: #66cc66;">&#40;</span>event.<span style="color: #006600;">clone</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>event is ErrorEvent<span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				dispatchEvent<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ModuleEvent<span style="color: #66cc66;">&#40;</span>ModuleEvent.<span style="color: #0066CC;">ERROR</span>, <span style="color: #000000; font-weight: bold;">false</span>, <span style="color: #000000; font-weight: bold;">false</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>,
					ErrorEvent<span style="color: #66cc66;">&#40;</span>event<span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">text</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>If you&#8217;re loading a style module, you may also want this class, which ensures the style module takes effect in your application immediately after the module is loaded.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package com.<span style="color: #006600;">aaronhardy</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">events</span>.<span style="color: #006600;">ModuleEvent</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">/**
	 * Provides the module marshalling functionality of ModuleMarshaller with the ability to
	 * update styles immediately after the module is loaded.
	 */</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> StyleModuleMarshaller <span style="color: #0066CC;">extends</span> ModuleMarshaller
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">/**
		 * If true, forces an immediate update of the application's styles after the module is
		 * loaded.
		 */</span>
		protected <span style="color: #000000; font-weight: bold;">var</span> updateStylesImmediately:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">true</span>;
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		 * Constructor.
		 * @param url The external module to load into the application.
		 * @param update If true, forces an immediate update of the application's styles after
		 *        the module is loaded.
		 */</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> StyleModuleMarshaller<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">url</span>:<span style="color: #0066CC;">String</span>, updateStylesImmediately:<span style="color: #0066CC;">Boolean</span>=<span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">this</span>.<span style="color: #006600;">updateStylesImmediately</span> = updateStylesImmediately;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		 * @inheritDoc
		 */</span>
		override protected <span style="color: #000000; font-weight: bold;">function</span> modReadyHandler<span style="color: #66cc66;">&#40;</span>event:ModuleEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			ModuleManager.<span style="color: #006600;">getModule</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">factory</span>.<span style="color: #006600;">create</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>updateStylesImmediately<span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				mx.<span style="color: #006600;">core</span>.<span style="color: #006600;">Singleton</span>.<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;mx.styles::IStyleManager2&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">styleDeclarationsChanged</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
			dispatchEvent<span style="color: #66cc66;">&#40;</span>event.<span style="color: #006600;">clone</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<h3>The Dirty Details</h3>
<p>So, why does the ModuleMarshaller function without errors while Flex&#8217;s built-in classes do not?  You might not care, but in case you do, here&#8217;s what I know&#8211;and don&#8217;t know.  First, all the built-in functions end up using ModuleInfo.load() found in ModuleManager.as.  This function uses a Loader to load in the contents of the module.  When the loaded SWF file is accessible and ready for use (i.e., the Loader&#8217;s LoaderInfo object dispatches an Event.INIT event), ModuleInfo.initHandler() is called.  In this function we have the following segment of code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">factoryInfo = <span style="color: #000000; font-weight: bold;">new</span> FactoryInfo<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #0066CC;">try</span>
<span style="color: #66cc66;">&#123;</span>
    factoryInfo.<span style="color: #006600;">factory</span> = loader.<span style="color: #006600;">content</span> as IFlexModuleFactory;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #0066CC;">catch</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">error</span>:<span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span>factoryInfo.<span style="color: #006600;">factory</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">var</span> moduleEvent:ModuleEvent = <span style="color: #000000; font-weight: bold;">new</span> ModuleEvent<span style="color: #66cc66;">&#40;</span>
        ModuleEvent.<span style="color: #0066CC;">ERROR</span>, event.<span style="color: #006600;">bubbles</span>, event.<span style="color: #006600;">cancelable</span><span style="color: #66cc66;">&#41;</span>;
    moduleEvent.<span style="color: #0066CC;">bytesLoaded</span> = <span style="color: #cc66cc;">0</span>;
    moduleEvent.<span style="color: #0066CC;">bytesTotal</span> = <span style="color: #cc66cc;">0</span>;
    moduleEvent.<span style="color: #006600;">errorText</span> = <span style="color: #ff0000;">&quot;SWF is not a loadable module&quot;</span>;
    dispatchEvent<span style="color: #66cc66;">&#40;</span>moduleEvent<span style="color: #66cc66;">&#41;</span>;
    <span style="color: #b1b100;">return</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Notice how it takes the content from the loader and attempt to cast it as an IFlexModuleFactory object.  In this case, loader.content is NOT an IFlexModuleFactory instance, resulting in factoryInfo.factory being set to null.  Later in the function, it checks to see if factoryInfo.factory is null.  If it is, an error is thrown.  This is the origin of the errors you see in your application.</p>
<p>So why does ModuleMarshaller work?  When ModuleMarshaller makes this call:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">module.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">null</span>, <span style="color: #000000; font-weight: bold;">null</span>, styleModuleBytes<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>It ultimately ends up in the same ModuleInfo.initHandler() function as we saw above.  In both cases the Flex Builder debugger shows that loader.content is of type GeneratedResourceModule1975496797516746634_mx_core_FlexModuleFactory.  However, when we load the module using the raw bytes loaded with a URLLoader, it IS able to cast the object as an IFlexModuleFactory object, resulting in a non-null factoryInfo.factory object and avoiding any error.</p>
<p>Why such similarity yet one is able to be cast while the other is not?  I don&#8217;t know.  That&#8217;s as far as I can go in my debugging quests with what&#8217;s open source.  I assume it has to do with the <a href="http://www.adobe.com/devnet/flashplayer/articles/flash_player_9_security.pdf" target="_blank">Flash Player security</a> but I haven&#8217;t read anything that would specifically explain why the content cannot be cast as an IFlexModuleFactory object when using built-in Flex module loading methods.  If you can fill in the gap or have questions, please feel free to post a comment.  Bon appetit!</p>
]]></content:encoded>
			<wfw:commentRss>http://aaronhardy.com/flex/loading-a-remote-module-into-a-local-app/feed/</wfw:commentRss>
		<slash:comments>48</slash:comments>
		</item>
		<item>
		<title>Illegal Immigration</title>
		<link>http://aaronhardy.com/politics/illegal-immigration/</link>
		<comments>http://aaronhardy.com/politics/illegal-immigration/#comments</comments>
		<pubDate>Sun, 24 Jun 2007 18:10:41 +0000</pubDate>
		<dc:creator>Aaron Hardy</dc:creator>
				<category><![CDATA[Politics]]></category>
		<category><![CDATA[border]]></category>
		<category><![CDATA[illegal]]></category>
		<category><![CDATA[immigration]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.aaronhardy.com/intimateconversations/politics/illegal-immigration/</guid>
		<description><![CDATA[While watching the news a couple months back, I saw something that struck me as rather &#8220;oxymoronic.&#8221; The broadcast was about the protests in Los Angeles held by illegal immigrants or those who support their cause. While most of the signs that the protesters were holding read something like &#8220;Legalize Immigration,&#8221; &#8220;Land of the Free,&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>While watching the news a couple months back, I saw something that struck me as rather &#8220;oxymoronic.&#8221;  The broadcast was about the protests in Los Angeles held by illegal immigrants or those who support their cause.  While most of the signs that the protesters were holding read something like &#8220;Legalize Immigration,&#8221; &#8220;Land of the Free,&#8221; or other phrases advocating open borders, one of them said &#8220;No somos illegales.&#8221;  For the English audience, this means &#8220;We aren&#8217;t illegals.&#8221;  Interesting.  This summarizes what I think has happened in this whole debate&#8211;politicians and many Americans are starting to think the same way. <span id="more-10"></span></p>
<p>The argument is, &#8220;They aren&#8217;t illegal, they were just doing what they thought was best for their families and American law got in their way.&#8221;  What!?  <b>They&#8217;re illegal.</b>  There&#8217;s no ifs, ands, or buts about it.  The law is in place and they have broken it.  Is it sad to see families split up because a hard-working father has to go to jail?  Sure.  Is it sad to see parents forced to go to back to their homeland and make the decision of whether to leave their children here?  Yes, it definitely is.  But when did we start changing our laws because of some disparaging images of innocent-looking and good-hearted people when these people are, when it comes down to it, <b>illegal</b>.  They became illegal and chose the possibility of facing such issues the second they stepped over the border.  Whether it was one week ago or ten years ago doesn&#8217;t, or shouldn&#8217;t, matter.  They made the decision just like someone who robs a store, even out of need for food for his/her children.  Does it mean I don&#8217;t feel bad for such people?  No.  I&#8217;m saying it&#8217;s an illegal act and should be treated as such.</p>
<p>So what&#8217;s the harm in making exceptions?</p>
<ol>
<li>Those who came to the United States <i>legally</i> are suddenly discredited.  After all, they did the work and didn&#8217;t need to!
<li>Those who have been charged for crossing the border suddenly come up with a plethora of lawsuits because <i>they</i> were treated unfairly.  I realize it shouldn&#8217;t hold any weight in court because changes in law generally can&#8217;t be applied retroactively, but it&#8217;s inevitable.
<li>Every other law will be challenged because, hey, if so many &#8220;innocent&#8221; people are breaking it, there must be something wrong with the law, not the people!
</ol>
<p>One other thing to address before I get off my soap box.  Another reason pro-amnesty folks throw out there for legalizing the illegals is that the U.S. was created by immigrants.  Aren&#8217;t we all immigrants?  Yes, we are all immigrants&#8211;and so is everyone else in most every other country.  The difference is that those coming from New England or the whereabouts were legal immigrants at the time and subsequently created the laws of immigration. If other countries decide to assume similar laws of immigration so that I must go through a process to become a citizen of their country, I believe it is their right and I will abide by it&#8230;even if I really, really wanted to go to that country.</p>
<p>Before you let your horses stampede, let me conclude by saying that I really do appreciate those hard-working, tax-paying, since-crossing-the-border-law-abiding, English-learning immigrants that have entered the country.  I appreciate your contributions to the economy and our society.  I welcome you into the country, <i>our country</i>&#8230;<i>but legally</i>.  I will not support the degradation of our nation&#8217;s law, society, and security to accommodate the need of a few who have bypassed but a single law: crossing the border.  And if you love this country so much, neither should you.</p>
]]></content:encoded>
			<wfw:commentRss>http://aaronhardy.com/politics/illegal-immigration/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

