coding and other fun

Flex, Java …and all the rest - by Bernhard Hirschmann

Entries Comments



Category: modules


Flex modules in Eclipse projects

7 April, 2008 (14:28) | ActionScript, Flex, modules | By: admin

With bigger Flex applications you might consider separating parts of your application to modules (<mx:Module>). When I came to this point, I encountered into troubles handling the Eclipse projects with the separate module code. Here is the result of my analysis, which finally worked out, after trapping in to several error messages like “SWF is not a loadable module”.

The reason you want to separate parts of your application surely is that such a module will be loaded when needed, and not initially. This saves donwload time for the user, because the main part of your application will stay slim, because the module parts are in separate SWF files. The module SWF file doesn’t contain Flex framework code, because this parts are already in the main app, therefore is has a tiny file size.

The main application project AND the module project, they both reside in normal Eclipse Flex projects. I first made the mistake to put the module project into a FlexLibrary project, which doesn’t work. I always got the error message “SWF is not a loadable module” then. So make sure the module project is a normal Flex project.

In the main app project, link to the module project in the following way:

Build path in Eclipse

Go to the context menu “Properties” and select “Flex Build Path”. Click on “Source path” and “Add Folder…” to select the source folder of the other Eclipse project, containing your module. After clicking OK, Eclipse will add this additional sourde folder to the path.

Now tell Eclipse to create a separate SWF file containing the module:

Flex Modules menu in Eclipse

In the “Flex Modules” menu you click “Add…” to choose the module file from your additional source path, which you just linked to your project’s path. As a result, Eclipse (or actually the FlexBuilder) will create a separate SWF file containing the module. There you go!

But wait! There’s more…

another bloody trap for me was that I set a new ApplicationDomain for the ModuleLoader, which again showed the error message “SWF is not a loadable module” - seems like someone didn’t have time for more detailed explanations, hm? So better leave this away to succeed.

If you still have questions about details of the settings, I provide a ZIP containing my two Eclipse test projects. Feel free to download and import both Eclipse projects in your workspace.

Eclipse Projects