Loading modules

Mankind's Avatar


27 Nov, 2012 10:41 AM

Hi, can anyone help. I want to load modules to my new project from another project. Can i only get the module swf file and add it to my new project to load or do i have to copy all the actors, view, mediator and context of the module along with the module swf to the new project? Its not getting loaded if i add only the swf file. OR Am i missing some property somewhere?

  1. Support Staff 1 Posted by Ondina D.F. on 27 Nov, 2012 11:20 AM

    Ondina D.F.'s Avatar

    Is it a Flex, ActionScript or a Flash Professional project?
    What IDE are you using?
    Are you using the robotlegs modular utility?

    Could it be that the metadata has been stripped out?


  2. 2 Posted by Mankind on 27 Nov, 2012 11:34 AM

    Mankind's Avatar

    Hi Ondina,
    Its a project in FLEX4, IDE is FlashBuilder and yes i have used Robotlegs Modular Utility.
    And thank you for your quick concern. :)

     From: Ondina D.F. <[email blocked]>
    To: [email blocked]
    Sent: Tuesday, November 27, 2012 4:50 PM
    Subject: Re: Loading modules [Questions #1361]

  3. Support Staff 3 Posted by Ondina D.F. on 27 Nov, 2012 11:49 AM

    Ondina D.F.'s Avatar

    No problem.
    If the metatada isn’t the problem, then perhaps it has to do with the applicationDomain.

    See if there is an answer for you in these discussions and let me know whether you’re still having problems or not:




    If that doesn’t help, you should provide more details, about how are you loading the modules, how are you initializing the contexts, etc

  4. 4 Posted by Mankind on 27 Nov, 2012 02:35 PM

    Mankind's Avatar

    Hi Ondina,
    Apologies for not giving sufficient information in the beginning. So here is what i am trying to do.
    (Using Flash Builder, RL Modular app framework for every project)

    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.

    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..

    var modAAInfo:IModuleInfo = ModuleManager.getModule("modules/AAModule.swf"); modAAInfo.addEventListener(ModuleEvent.READY, onReady); modAAInfo.load(null,null,null,moduleFactory);

    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.
    var aaModule:IVisualElement = modAAInfo.factory.create() as IVisualElement;

    Second, I tried ModuleLoader component and Class both. Both gave same result- nothing loaded!
    var moduleLoader:ModuleLoader = new ModuleLoader(); moduleLoader.applicationDomain = ApplicationDomain.currentDomain; addElement(moduleLoader); moduleLoader.url = "modules/WeatherModule.swf";

    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.

    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.S. All the modules loads and functions well in project_A and i have also added -isolate-styles=false to the additional compiler argument.

  5. Support Staff 5 Posted by Ondina D.F. on 27 Nov, 2012 03:32 PM

    Ondina D.F.'s Avatar

    Hey Mankind,

    Yes, more details are always good :)

    Just checking that I understand. Which one is your use case:
    1. You moved the swfs from project A into project B, meaning you have a folder named modules in your project B, and there are all the sfws that you then want to load
    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?

    Assuming your modules are in project B:

    • First step, as you know, is to let FlashBuilder know about the modules: Project->Properties->Flex Modules-> add: yourPathTo/moduleName

    Are you sure you didn’t forget to do so?

    • What I use to do, is having a container, say a Flex Group id="moduleLoaderContainer"
    • Then somewhere in actionscript I call


    private var moduleLoader:ModuleLoader;
    public function loadModules(moduleURL:String):void
       moduleLoader=new ModuleLoader();
       moduleLoader.addEventListener(ModuleEvent.READY, onModuleReady);
       moduleLoader.addEventListener(ModuleEvent.ERROR, onModuleError);
       moduleLoaderContainer.addElement(moduleLoader as IVisualElement);
    • That’s because it is easier to unload modules like this:
    private function unloadModules():void
       if (moduleLoader)
          moduleLoader = null;

    I have a bad experience with ModuleManager, when it comes to unloading modules and make them eligible for garbage collection.

    Let me know how it goes. We’ll find a solution together :)


  6. 6 Posted by Mankind on 28 Nov, 2012 05:53 AM

    Mankind's Avatar

    Hi Ondina,
    You got it right. That's exactly what i want to do in my example project.
    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.
    Rest i did the same and same thing happened, nothing loaded. And when i tried to trace the flow, i got this output.

    adding module

    [SWF] modules/WeatherModule.swf - 145,140 bytes after decompression

    module ready

    module error

    here adding module is the beginning of the module loading function.
    Then it is loading the module(i think)
    module ready is the ready event listener function called. and module error is the error event listener function called. How can both be called one after another?

    This time i am attaching a zip file of my project files, you might want to have a look.
    Once again thanks for the support you people provide.

  7. Support Staff 7 Posted by Ondina D.F. on 28 Nov, 2012 11:32 AM

    Ondina D.F.'s Avatar

    I'm attaching 2 projects:
    yours, modified, and one that I created in order to show you how to load the modules.
    I'll do the explaining a bit later.

  8. Support Staff 8 Posted by Ondina D.F. on 28 Nov, 2012 12:10 PM

    Ondina D.F.'s Avatar

    Hi, again,

    ModularExperiment contains 2 Modules:
    SimpleModule and SomeModule

    SomeModule was built using the Modular utility, SimpleModule is just a simple module.

    Both are mxml modules(!), added to the project properties-> Flex Modules, where I selected :
    „Do not optimize (module can be loaded by multiple applications)“

    In your project:

    • The 2 modules are under modules folder

    • Under project properties Flex Build Path I chose Framework linkage : Runtime shared library (RSL)

    • In MAContext I mapped the module like this: viewMap.mapType(IModule);
      where IModule is org.robotlegs.utilities.modular.core.IModule; which SomeModule is implementing.

    • I added 2 buttons in MainView to load SimpleModule and SomeModule

    When SomeModule is loaded, you can see the label in the view set by SomeModuleMediator onRegister(). SimpleModule doasn’t have a mediator.

    Of course that’s a very simple scenario, just for the sake of an example.

    It seems that your 2 modules have some issues. I wasn’t able to load them.
    Are they mxml modules? Are they implementing an interface?
    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.

    Let me know about your progress :)


  9. Support Staff 9 Posted by Ondina D.F. on 29 Nov, 2012 10:06 AM

    Ondina D.F.'s Avatar

    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.

    As you could see in my example, my modules got loaded just fine.
    When I try to load your modules I get this error:
    SWF is not a loadable module

    Maybe your issue has something to do with this FlashPlayer bug:

    Here Aaron’s workaround:

    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.


  10. 10 Posted by Mankind on 29 Nov, 2012 03:26 PM

    Mankind's Avatar

    Hi Ondina,
    No problem, i changed the AIR runtime. Didn't find any explanation about the problem :(
    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).
    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.

  11. Support Staff 11 Posted by Ondina D.F. on 29 Nov, 2012 04:04 PM

    Ondina D.F.'s Avatar

    Hi Mankind,

    Before looking at the entire code, just a quick observation.

    The reason why you couldn’t load my module (SimpleModule) in your new app is the wrong path:

    The correct path is:

    It would be good to keep the error handler in your code, so you can see what’s going on :)

    moduleInfo.addEventListener(ModuleEvent.ERROR, onModuleError);

    protected function onModuleError(event:ModuleEvent):void

    trace('module error ' + event.errorText);


    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.

    I’ll look at your code and come back with answers as soon as time permits.


  12. Support Staff 12 Posted by Ondina D.F. on 29 Nov, 2012 06:07 PM

    Ondina D.F.'s Avatar

    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 Runtime shared libraries (RSL) 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,

    I’ve attached 2 new projects: yours and mine, modified.
    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.

    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
    moduleInfo.load(null, null, null, moduleFactory);

    moduleInfo.load(ApplicationDomain.currentDomain, null, null, moduleFactory);

    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.
    Please let me know if you still have problems.

    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)

  13. 13 Posted by Mankind on 03 Dec, 2012 12:09 PM

    Mankind's Avatar

    Hi Ondina,
    Looks like i found out the reason why my modules are not being loaded and yours are perfectly loaded.
    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.
    I am going to point out what i did(changed) in order to make my modules addable to other the projects.

    Create modules without optimizing it for its current project(true by default)

    Set framework linkage to Runtime shared library in property option of the project

    I mapped the IModule as viewMap.mapType(IModule) in application context

    Once again thanks and do expect more trouble from my side in future. :)

  14. Support Staff 14 Posted by Ondina D.F. on 03 Dec, 2012 02:29 PM

    Ondina D.F.'s Avatar

    Hey Mankind,

    That’s good news! Yeah, the settings in FlashBuilder are sometimes tricky.

    Once again thanks

    You’re more than welcome!!

    and do expect more trouble from my side in future. :)

    Haha, more trouble? I won't be able to say I haven't been warned. Kidding ;-)


  15. Ondina D.F. closed this discussion on 03 Dec, 2012 02:29 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac