PureMVC Architects Lounge

PureMVC Manifold => MultiCore Version => Topic started by: devorb on December 16, 2008, 03:06:16



Title: loading external applications problem
Post by: devorb on December 16, 2008, 03:06:16
Hi Guys,

I'm banging my head for 2 days now with this and finally gave up.
I have an application (just a bunch of normal mxml with puremvc) and I'm loading another application into it (mxml with puremvc like the first one). All the flex, puremvc multicore, pipes libraries are externals (not compiled into the code)

Whenever I load the 2nd into the first I want to raise an event in order to connect the 2 through pipes.
And that's where the problem comes in, when this function is called finally then the module is null!

public function connectModule( module:IPipeAwareModule):void
{
junction.registerPipe( ConstPipe.PIPE_SHELL_TO_MODULE,Junction.OUTPUT,new TeeSplit() );
junction.registerPipe( ConstPipe.PIPE_MODULE_TO_SHELL,Junction.INPUT,new TeeMerge() );
junction.addPipeListener( ConstPipe.PIPE_MODULE_TO_SHELL,this,handlePipeMessage );
var moduleToShell: Pipe = new Pipe();
module.acceptOutputPipe( ConstPipe.PIPE_MODULE_TO_SHELL, moduleToShell );
var shellInFitting: TeeMerge = junction.retrievePipe( ConstPipe.PIPE_MODULE_TO_SHELL ) as TeeMerge;
shellInFitting.connectInput( moduleToShell );
var shellToModule: Pipe = new Pipe();
module.acceptInputPipe( ConstPipe.PIPE_SHELL_TO_MODULE, shellToModule );
...
}


Here are some versions I tried with:

SWFLoader


protected var loader:SWFLoader;

public function loadApp():void 
{
loader = new SWFLoader();
var apploc:String = "XXXAPP.swf";

loader.addEventListener(Event.COMPLETE, completeHandler);
loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);

var context:LoaderContext = new LoaderContext();
context.applicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain);
loader.loaderContext = context;
loader.trustContent = true;
loader.source = apploc;
loader.load();         
MXMLholder.addChild(loader);
}

private function completeHandler(event:Event):void
{   
var ev:MyEvent = new MyEvent(ELOADED);
ev.data = loader.loaderInfo.applicationDomain.getDefinition("XXXAPP") as Class;
ev.data = loader.content as IPipeAwareModule;
ev.data = (loader.content as SystemManager).application;
ev.data = loader.content as SystemManager).application as IPipeAwareModule
//And i can continue with all the variations of the above ...
// None of those are working when I dispatch the event the module is always null in connectModule
dispatchEvent(ev);
}


I've also tried with the Loader and ModuleLoader classes ... without sucess.
The application is loaded, appears in the GUI and works correctly inside the shell application.
The problem is that when the event is dispatched (in the completeHandler) and finally the connectModule function is called the module parameter (module = ev.data) is allways null.
I tried to listen after the complete event for the FlexEvent.INITIALIZE event, but that was not dispatched... I suspect I should listen to some initialize event ...
On the other hand if from the module application I call manually the connectModule (in the shell application) it allways works :)
But that's just disgusting from a programming practice perspective isn't it?


Title: Re: loading external applications problem
Post by: puremvc on December 18, 2008, 12:53:48
I haven't tried loading the modules with SWFLoader, only ModuleLoader. And with the latter, there are several events to capture, though I can't get to the references here on this wap browser, it seems like ModuleEvent.READY might be what you're after.

-=Cliff>