Robotlegs 1.5.2 : Compiling Modules as swf's

thomas.thorstensson's Avatar


03 Oct, 2012 09:12 PM

Hello Again!

This might seem a bit of a stupid question but:

Albeit I after some research understand how to hook up Modules with a ModuleManager : how do I compile an swf for an individual module? Cause assuming I don't compile entire application runtime, is there a good method for setting an individual modules context to compile to an swf? (It's all about view's so each module would end up being an swf in what I have in mind)

Because in a non modular RL project I create the Context from the Application Class. But assuming I just want to compile that particular individual module into an swf then that specific ModularContext needs to be added to stage.

Should I create a temporary View class and go about it that way for each module that I want to compile to swf or am I missing something obvious?

Many Thanks

  1. Support Staff 1 Posted by Ondina D.F. on 04 Oct, 2012 11:51 AM

    Ondina D.F.'s Avatar

    Hi Thomas!

    “When you set up your project's architecture, you can decide to include modules in your application's project, create a separate project for each module, or create a separate project for all modules…. If the modules are in the same project as your Flex application, then when you run your application, Flex Builder compiles the modules' SWF files for you.” [source first link bellow]

    Compile a single module’s project

    1. Right-click the module’s MXML file in the module’s project.
    2. Select Run Application. The Player or browser window tries to run the module after it is compiled. You can close the Player or browser window and ignore any error messages that appear at runtime. Modules are not meant to be run in the Player or in a browser directly.

    Recompiling modules

    If you change a module, you do not have to recompile the application that uses the module if that module is in the same project. This is because the application loads the module at run time and does not check against it at compile time. Similarly, if you make changes to the application, you do not have to recompile the module. Just as the application does not check against the module at compile time, the module does not check against the application until run time.
    If the module is in a separate project than the application that loads it, you must recompile the module separately. [source Adobe, see bellow]

    But, I guess, what you want, is to create a separate project for each module, so you can test them separately?

    In the following linked articles you’ll see the advantages and disadvantages of each approach:

    Adobe Flex 4.7

    Adobe Flex 4.6

    Maybe a better solution for your use case would be to create a separate project for all modules, where you can load only the module that needs testing.
    Of course, you can also build sub-applications for each functional area that you need in your main app, and then load the sub-applications as swfs, or you can use a library project. It all depends on what you need.

    Does this help?


  2. 2 Posted by thomas.thorsten... on 04 Oct, 2012 12:07 PM

    thomas.thorstensson's Avatar

    Thanks Ondina this helps. I guess I was confused by the fact that I'm building a pure AS3 project revamp. I like this approach:

    'You can also create a separate Flex or ActionScript project for each module or for groups of modules. This gives you greater control over how modules are compiled because each project can have different compiler options than the application or other modules. It also lets you compile the module’s project or projects without compiling the application. However, this approach requires that you manually compile each module before compiling the application. One way to do this is to compile all open projects in Flash Builder at one time.'

    This seems to be a good solution to me cause it enables me to compile each project separately to test. So I would treat each separate project as a Robotlegs module.

    Not sure how everything would plug together but Ill see how as I move along.

    Any light you can shed on how my module library should relate to the main application code would be great. For example I could treat my main application as code library for entire project? Rather than dubplicating the lib .swc files....Not sure if there is any best practice here.

    But perhaps you have already implied an answer as the module and vice versa application does not check against eachother Compile time. So each project should be set to run independently and have it's own libraries.

    Thanks! I believe it's time for a small cup of coffe.

  3. Support Staff 3 Posted by Ondina D.F. on 04 Oct, 2012 01:04 PM

    Ondina D.F.'s Avatar

    Well, it’s a complex topic, and I’m afraid I won’t be able to get into all the details :)

    Let’s say you have a separate project where you have a main display object and one module (SomeExternalModule), that you want to load in another project.
    There, where you want to load the module (your main project), you define the source path of the module (SomeExternalModule) under Properties->Flex build path-> source path ( I’m using FlashBuilder). Then you go to Properties->Flex modules and you add something like this: [source path] src\SomeExternalModule.mxml, which is the path to the external module, defined previously. The main app can load this module as any other module.

    Now, about libraries: You actually have a main project and another, separate library project. The main project is the one loading the classes, components, or whatever, contained in a library, not vice versa. In a library you put things that you want to share with other projects, or other modules. Say, you have a library for styles, or you can have a library containing robotlegs models and services, that you can use for a desktop, browser or mobile app. They all share the same models and services, while the views are different.
    Or you can have a library of different components that you load in different parts of your app.

    You’ll have to read more about optimizing modules, runtime shared libraries …:)
    There are also some discussions on this forum about library projects. If you want to see a project using a library take a look at the links from my answer here:

    I’m sorry that I can’t help you more, but even if I had more time, without a concrete use case to talk about, it’s really a huge topic.

    Thanks! I believe it's time for a small cup of coffe.

    You’re welcome, Thomas. Oh, I think I need coffee, too ;) No sugar, of course.


  4. 4 Posted by thomas.thorsten... on 04 Oct, 2012 02:41 PM

    thomas.thorstensson's Avatar


    Yes I used libraries swc's and Flex modules in Flashbuilder before as Flashbuilder is my premium tool nowadays albeit I have a past with FDT and Flashdevelop and before that Scintilla.

    The thing is that this is Not A Flex Project. So thats why I seem confused. I also am slightly in the dark due to that I am using Robotlegs in a non flex pure actionscript modular context.

    But, based on your answers above I will be able to figure it out. I assume something like this can be done without Flex based modules.

    I dig further and thanks for your time.

    Thomas, Over half a mug of latte

  5. Support Staff 5 Posted by Ondina D.F. on 04 Oct, 2012 04:45 PM

    Ondina D.F.'s Avatar

    If it’s a pure as3 project, the only thing different from what I said in the other post is :

    [source path] src\

    as. instead of .mxml

    The component that is supposed to be loaded as a module extends Sprite, and what matters in the end is the swf file you load via your SWFLoader.

    I guess you’re already aware of this: Just mentioning it, in case you need it.

    I think that you think that the things are more complicated than they really are ;)

    I’m sure you’ll find a solution! If not, then come back with questions.


  6. 6 Posted by thomas.thorsten... on 04 Oct, 2012 04:50 PM

    thomas.thorstensson's Avatar

    Aha that was what I didn't realise I never added an .as file as a module (blushes).

    I shall code tonight. This discussion can now be closed, I'm ready to do some work.



  7. Support Staff 7 Posted by Ondina D.F. on 04 Oct, 2012 04:56 PM

    Ondina D.F.'s Avatar

    No problem. No need to feel bad, really! Good luck!

  8. Ondina D.F. closed this discussion on 04 Oct, 2012 04:56 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