tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/1361-loading-modulesRobotlegs: Discussion 2012-12-03T14:30:30Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/215844322012-11-27T11:20:38Z2012-11-27T11:20:38ZLoading modules<div><p>Hello,<br>
Is it a Flex, ActionScript or a Flash Professional project?<br>
What IDE are you using?<br>
Are you using the robotlegs modular utility?</p>
<p>Could it be that the metadata has been stripped out?<br>
See:<br>
<a href=
"https://github.com/robotlegs/robotlegs-framework/wiki/Common-Problems#wiki-metadata-stripping">
https://github.com/robotlegs/robotlegs-framework/wiki/Common-Proble...</a></p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/215844322012-11-27T11:34:59Z2012-11-27T11:34:59ZLoading modules<div><p>Hi Ondina,<br>
Its a project in FLEX4, IDE is FlashBuilder and yes i have used
Robotlegs Modular Utility.<br>
And thank you for your quick concern. :)</p>
<p>________________________________ From: Ondina D.F. <a href=
"mailto:tender+dff50a8a7bc7af93e654dd0736af54a2d4db5fcb0@tenderapp.com">
tender+dff50a8a7bc7af93e654dd0736af54a2d4db5fcb0@tenderapp.com</a>
To: <a href=
"mailto:too_young_to@yahoo.com">too_young_to@yahoo.com</a><br>
Sent: Tuesday, November 27, 2012 4:50 PM<br>
Subject: Re: Loading modules [Questions <a title="Discussion #1361"
href="/discussions/questions/1361">#1361</a>]</p></div>Mankindtag:robotlegs.tenderapp.com,2009-10-18:Comment/215844322012-11-27T11:49:11Z2012-11-27T11:49:11ZLoading modules<div><p>No problem.<br>
If the metatada isn’t the problem, then perhaps it has to do
with the <em>applicationDomain</em>.</p>
<p>See if there is an answer for you in these discussions and let
me know whether you’re still having problems or not:</p>
<p><a href=
"http://knowledge.robotlegs.org/discussions/problems/650-robotlegs-modular-loading-from-swf">
http://knowledge.robotlegs.org/discussions/problems/650-robotlegs-m...</a></p>
<p><a href=
"http://knowledge.robotlegs.org/discussions/problems/505-loading-robotlegs-project-swf-into-robotlegs-project">
http://knowledge.robotlegs.org/discussions/problems/505-loading-rob...</a></p>
<p><a href=
"http://knowledge.robotlegs.org/discussions/problems/521-loading-one-robotlegs-project-to-another-robotlegs-project">
http://knowledge.robotlegs.org/discussions/problems/521-loading-one...</a></p>
<p>If that doesn’t help, you should provide more details,
about how are you loading the modules, how are you initializing the
contexts, etc</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/215844322012-11-27T14:35:42Z2012-11-27T14:35:42ZLoading modules<div><p>Hi Ondina,<br>
Apologies for not giving sufficient information in the beginning.
So here is what i am trying to do.<br>
(Using Flash Builder, RL Modular app framework for every
project)</p>
<p>In my project_A i created 3 modules modAA, modABand modAC and
now in project_B I want to add these modules dynamically. These
modules are also supposed to communicate with the project_B(parent
app). Now when i moved these .swf files for the modules to the
project_B and tried to add them, I faced problems.</p>
<p>First, i tried to load them by ModuleManager class, like that in
project_A in some view of the project_B. For loading i created
IModuleInfo instance. like this..</p>
<p><code>var modAAInfo:IModuleInfo =
ModuleManager.getModule("modules/AAModule.swf");
modAAInfo.addEventListener(ModuleEvent.READY, onReady);
modAAInfo.load(null,null,null,moduleFactory);</code></p>
<p>This seems alright because but when i created the instance of
IVisualElement, in onReady(), which i am supposed to add as element
in the view it turned out to be null.<br>
<code>var aaModule:IVisualElement = modAAInfo.factory.create() as
IVisualElement;</code></p>
<p>Second, I tried ModuleLoader component and Class both. Both gave
same result- nothing loaded!<br>
<code>var moduleLoader:ModuleLoader = new ModuleLoader();
moduleLoader.applicationDomain = ApplicationDomain.currentDomain;
addElement(moduleLoader); moduleLoader.url =
"modules/WeatherModule.swf";</code></p>
<p>Only for testing, i placed all modAA files from project_A to
project_B and also mapped it in context of project_B. Then it was
added but i am sure module is not added like this.</p>
<p>I was told that ModuleManager is the bast way to add a module
but the problem of creating module null is bugging me. Hope above
information will provide you better idea whats wrong with me(the
project). Is there a better way to meet the above requirement,
please enlighten me.</p>
<p>P.S. All the modules loads and functions well in project_A and i
have also added <code>-isolate-styles=false</code> to the
additional compiler argument.</p></div>Mankindtag:robotlegs.tenderapp.com,2009-10-18:Comment/215844322012-11-27T15:32:22Z2012-11-27T15:48:48ZLoading modules<div><p>Hey Mankind,</p>
<p>Yes, more details are always good :)</p>
<p>Just checking that I understand. Which one is your use case:<br>
1. You moved the swfs from project A into project B, meaning you
have a folder named <em>modules</em> in your project B, and there
are all the sfws that you then want to load<br>
2. You have project A containing swfs, in a folder *modules”,
and you want project B to load them from the location of project
A?</p>
<p>Assuming your modules are in project B:</p>
<ul>
<li>First step, as you know, is to let FlashBuilder know about the
modules: Project->Properties->Flex Modules-> add:
<em>yourPathTo/moduleName</em></li>
</ul>
<p>Are you sure you didn’t forget to do so?</p>
<ul>
<li>What I use to do, is having a container, say a Flex Group
id="moduleLoaderContainer"</li>
<li>Then somewhere in actionscript I call</li>
</ul>
<p>loadModules("yourdomain/modules/SomeView.swf");</p>
<pre>
<code>private var moduleLoader:ModuleLoader;
public function loadModules(moduleURL:String):void
{
moduleLoader=new ModuleLoader();
moduleLoader.addEventListener(ModuleEvent.READY, onModuleReady);
moduleLoader.addEventListener(ModuleEvent.ERROR, onModuleError);
moduleLoader.applicationDomain=ApplicationDomain.currentDomain;
moduleLoader.loadModule(moduleUrl);
moduleLoaderContainer.addElement(moduleLoader as IVisualElement);
}</code>
</pre>
<ul>
<li>That’s because it is easier to unload modules like
this:</li>
</ul>
<pre>
<code>private function unloadModules():void
{
if (moduleLoader)
{
moduleLoaderContainer.removeElement(moduleLoader);
moduleLoader.unloadModule();
moduleLoader = null;
}
}</code>
</pre>
<p>I have a bad experience with ModuleManager, when it comes to
unloading modules and make them eligible for garbage
collection.</p>
<p>Let me know how it goes. We’ll find a solution together
:)</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/215844322012-11-28T05:53:01Z2012-11-28T05:55:08ZLoading modules<div><p>Hi Ondina,<br>
You got it right. That's exactly what i want to do in my example
project.<br>
In the first step you suggested to add modules to the project, I
went there and it asked for the root source file for the module in
the project_B. Do I have to bring source file too? Since I have
placed my module as swf there so its not finding it.<br>
Rest i did the same and same thing happened, nothing loaded. And
when i tried to trace the flow, i got this output.</p>
<p><code>adding module</code></p>
<p><code>[SWF] modules/WeatherModule.swf - 145,140 bytes after
decompression</code></p>
<p><code>module ready</code></p>
<p><code>module error</code></p>
<p>here <code>adding module</code> is the beginning of the module
loading function.<br>
Then it is loading the module(i think)<br>
<code>module ready</code> is the ready event listener function
called. and <code>module error</code> is the error event listener
function called. How can both be called one after another?</p>
<p>This time i am attaching a zip file of my project files, you
might want to have a look.<br>
Once again thanks for the support you people provide.</p></div>Mankindtag:robotlegs.tenderapp.com,2009-10-18:Comment/215844322012-11-28T11:32:09Z2012-11-28T11:32:09ZLoading modules<div><p>I'm attaching 2 projects:<br>
yours, modified, and one that I created in order to show you how to
load the modules.<br>
I'll do the explaining a bit later.</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/215844322012-11-28T12:10:07Z2012-11-28T12:15:32ZLoading modules<div><p>Hi, again,</p>
<p>ModularExperiment contains 2 Modules:<br>
SimpleModule and SomeModule</p>
<p>SomeModule was built using the Modular utility, SimpleModule is
just a <em>simple</em> module.</p>
<p>Both are mxml modules(!), added to the project properties->
Flex Modules, where I selected :<br>
„Do not optimize (module can be loaded by multiple
applications)“</p>
<p>In your project:</p>
<ul>
<li>
<p>The 2 modules are under modules folder</p>
</li>
<li>
<p>Under project properties Flex Build Path I chose Framework
linkage : Runtime shared library (RSL)</p>
</li>
<li>
<p>In MAContext I mapped the module like this:
viewMap.mapType(IModule);<br>
where IModule is org.robotlegs.utilities.modular.core.IModule;
which SomeModule is implementing.</p>
</li>
<li>
<p>I added 2 buttons in MainView to load SimpleModule and
SomeModule</p>
</li>
</ul>
<p>When SomeModule is loaded, you can see the label in the view set
by SomeModuleMediator onRegister(). SimpleModule doasn’t have
a mediator.</p>
<p>Of course that’s a very simple scenario, just for the sake
of an example.</p>
<p>It seems that your 2 modules have some issues. I wasn’t
able to load them.<br>
Are they mxml modules? Are they implementing an interface?<br>
Without seeing the code for your modules, I can’t say
what’s going on, but, hopefully, based on my little project,
ModularExperiment, you’ll find out how to proceed.</p>
<p>Let me know about your progress :)</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/215844322012-11-29T10:06:02Z2012-11-29T10:06:02ZLoading modules<div><p>I forgot to tell you that I changed the air runtime to 3.2, so
if you are using an older version you’ll have to change the
application descriptor file accordingly.</p>
<p>As you could see in my example, my modules got loaded just
fine.<br>
When I try to load your modules I get this error:<br>
SWF is not a loadable module</p>
<p>Maybe your issue has something to do with this FlashPlayer
bug:<br>
<a href=
"http://bugs.adobe.com/jira/browse/SDK-15393">http://bugs.adobe.com/jira/browse/SDK-15393</a></p>
<p>Here Aaron’s workaround:<br>
<a href=
"http://aaronhardy.com/flex/loading-a-remote-module-into-a-local-app/">
http://aaronhardy.com/flex/loading-a-remote-module-into-a-local-app/</a></p>
<p>I’m curious if that solves your problem. If you found a
solution already, it would be good to tell us about it. It might
help others in a similar situation as yours.</p>
<p>Cheers,<br>
Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/215844322012-11-29T15:26:29Z2012-11-29T15:26:29ZLoading modules<div><p>Hi Ondina,<br>
No problem, i changed the AIR runtime. Didn't find any explanation
about the problem :(<br>
I was in fact going through your codes for things which i might
have missed in my project and came to a conclusion that problem
could be in modules as they are not loading as easily as it has
been told(strange thing i am also not able to load your module from
your example).<br>
This time i will be attaching the files of the project where i am
creating the modules. I am sure you will find some problem that. I
am desperately on it and trying to find the solution. Will share as
soon as i find one.</p></div>Mankindtag:robotlegs.tenderapp.com,2009-10-18:Comment/215844322012-11-29T16:04:40Z2012-11-29T16:04:40ZLoading modules<div><p>Hi Mankind,</p>
<p>Before looking at the entire code, just a quick observation.</p>
<p>The reason why you couldn’t load my module (SimpleModule)
in your new app is the wrong path:<br>
“com/foreignModule/SimpleModule.swf"</p>
<p>The correct path is:<br>
“com/modularapp/modules/foreignModule/SimpleModule.swf"</p>
<p>It would be good to keep the error handler in your code, so you
can see what’s going on :)</p>
<p>moduleInfo.addEventListener(ModuleEvent.ERROR,
onModuleError);</p>
<p>…</p>
<p>protected function onModuleError(event:ModuleEvent):void<br>
{</p>
<pre>
<code>trace('module error ' + event.errorText);</code>
</pre>
<p>}</p>
<p>The projects that I attached yesterday are working just fine
with my modules. I suspect you didn’t follow the instructions
for the FlashBuilder settings.</p>
<p>I’ll look at your code and come back with answers as soon
as time permits.</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/215844322012-11-29T18:07:26Z2012-11-29T18:07:26ZLoading modules<div><p>Another reason for not being able to load my modules in your app
is what I’ve already mentioned, you have to go to
FlashBuilder::properties::flex build path:: and set framework
linkage to <strong>Runtime shared libraries (RSL)</strong> in the
application that’s loading the foreign modules. Just making
sure you didn’t forget that :) It’s an easy mistake to
make, especially when you are under stress. Actually it's just an
oversight, not a mistake,</p>
<p>I’ve attached 2 new projects: yours and mine,
modified.<br>
In Modular experiments there are now 2 Modules built wit the
modular utility: SomeModule and AnotherModule. The difference
between them is that AnotherModule does not define an
ApplicationDomain for the injector to work with, whilst SomeModule
does that.</p>
<p>When you try to load them in your app, inside your method
getForeighModule(), AnotherModule would isssue an error, if you
don’t specify the ApplicationDomain as the first param of
the<br>
moduleInfo.load(null, null, null, moduleFactory);</p>
<p>Correct:<br>
moduleInfo.load(ApplicationDomain.currentDomain, null, null,
moduleFactory);</p>
<p>Since your „foreign“ modules, that you’re just
copying and pasting into your current application, are similar to
AnotherModule, you’ll have to load them into the current
application domain, like I did. It works fine on m end.<br>
Please let me know if you still have problems.</p>
<p>I’m running out of time for today, so we’ll have to
continue tomorrow, my tomorrow (it is 7 p.m. here, where I
live)</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/215844322012-12-03T12:09:48Z2012-12-03T12:10:42ZLoading modules<div><p>Hi Ondina,<br>
Looks like i found out the reason why my modules are not being
loaded and yours are perfectly loaded.<br>
The reason was small and simple. The modules i created was by
default 'Optimized' for my project project where i am creating
those modules. So its always looking for the package structure of
the project where it was created. I changed it after reading your
post above. And also set the framework linkage to 'RSL'. After
this, i created fresh modules and its is can be easily loaded to my
any of the project. Thanks for your valuable support. It was
definitely small problem but you support made it possible to learn
me several new things and sort out my problem.<br>
I am going to point out what i did(changed) in order to make my
modules addable to other the projects.</p>
<p><code>Create modules without optimizing it for its current
project(true by default)</code></p>
<p><code>Set framework linkage to Runtime shared library in
property option of the project</code></p>
<p><code>I mapped the IModule as viewMap.mapType(IModule) in
application context</code></p>
<p>Once again thanks and do expect more trouble from my side in
future. :)</p></div>Mankindtag:robotlegs.tenderapp.com,2009-10-18:Comment/215844322012-12-03T14:29:02Z2012-12-03T14:29:02ZLoading modules<div><p>Hey Mankind,</p>
<p>That’s good news! Yeah, the settings in FlashBuilder are
sometimes tricky.</p>
<blockquote>
<p>Once again thanks</p>
</blockquote>
<p>You’re more than welcome!!</p>
<blockquote>
<p>and do expect more trouble from my side in future. :)</p>
</blockquote>
<p>Haha, more trouble? I won't be able to say I haven't been
warned. Kidding ;-)</p>
<p>Cheers,<br>
Ondina</p></div>Ondina D.F.