I'm building my first Flex modules-based app with my own MVC
implementation. I have my main.mxml instantiating my controller just
fine and the controller building a map of the modules (flex modules)
that it can load dynamically.
However, I am running into a wall when the most basic attempt to load
a module fails. I've tried more advanced methods and stepped through
the ModuleLoader, ModuleInfo.load classes and I get anything from "a
local SWF can't use the securityDomain property of a loaderContext
object" to the "SWF is not a loadable module" errors based on the
changes I've made to try and address the problem of not being able to
load and display the most basic module within a host.
Can someone give me the basics on how to create a local build and
test environment that will address the security/sandbox restrictions
of local SWFs loading (my MVC host app) other local SWFs (my module
SWFs). Here's my setup:
- have a basic flex project that outputs a build in the \bin
directory. When I attempt to load a module, also in that same \bin
directory, I can see the loading progress event handler being called
but when the cast to loader.content as IFlexFactoryBlah runs, the
loaded module isn't a "real" module per "SWF is not loadable
module". Although, my module SWF is a <mx:Module> based SWF that
contains only one ui element, a label.
- then I thought maybe it wouldn't work b/c I wasn't loading the
module SWF over HTTP, so I put my view.swf module in the root
directory of my localhost-based HTTP server. Then I ran into the "a
local SWF can't set the securityDomain property in LoaderContect"
error. I tried to manually load the module using the following and
placing a crossdomain.xml into the root of my server with access set
to all allowed via "*":
import mx.events.ModuleEvent;
import mx.modules.ModuleManager;
import mx.modules.IModuleInfo;
var info:IModuleInfo;
Security.allowDomain("localhost");
Security.loadPolicyFile("http://localhost/crossdomain.xml");
var request:URLRequest = new URLRequest
("http://localhost/crossdomain.xml");
var loader:URLLoader = new URLLoader();
loader.load(request);
info = ModuleManager.getModule(view.swf);
info.addEventListener(ModuleEvent.READY, onModuleReady);
info.load
(ApplicationDomain.currentDomain,securityDomain.currentDomain);
This produced the "You can't use securityDomain property of
LoaderContext from a local SWF" type error.
Anyway, where do you normally store module SWFs and the host app that
uses and loads them when you're in dev mode and trying to debug on
your local box???
Here's some of the code:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
creationComplete="onInit();" width="532" height="428">
<mx:Button x="10" y="10" id="btn" label="Load Flex SWF" />
<mx:Panel x="10" y="78" width="341" height="281"
layout="absolute" title="Loaded Module">
<mx:ModuleLoader id="modLoader" width="100%"
height="100%" x="0" y="0">
</mx:ModuleLoader>
</mx:Panel>
<mx:Script>
<![CDATA[
// in my first iteration of this file, i would just try
modLoader.url = objModuleInfo.swf;
//where objModuleInfo is an object containing a property, swf, that
//is a string containing the path to my module
//the module SWF was in the same directory as the host.swf initially,
//then i moved it into my webserver
Here's the module:
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml"
height="164" backgroundColor="#0000ff" width="189"
layout="absolute">
<mx:Panel width="169" height="99" layout="absolute"
title="Module " x="10" y="24">
<mx:Label x="10" y="31" text="View SWF"
color="#400040" fontWeight="bold"/>
</mx:Panel>
</mx:Module>
This started as an mx:Application but I switched it to a mx:Module
per the latest Flex Modules docs recommendation how to create a
runnable/buildable module SWF.
Any thoughts would be GREATLY appreciated.
Thanks!