Managing Flex Modules

May 13th, 2007

When working with modules the “edit-compile-run” cycle can get in your way: Compiling the main application and then the separate modules, managing multiple Flex Builder/Ant projects, etc. For developing, it would be best to have just one big project. Here is how we do it…

  • Keep each of your modules in a separate directory, declaring it as mx:Module (in this example the module is ImageManager)
  • In your main application beneath your src directory, have the following two source directories:
    Directory Layout

    1. mod-access/extern
      The ImageManagerAccess.mxl here is just a wrapper for the mx:ModuleLoader:

      <mx:ModuleLoader xmlns:mx=“http://www.adobe.com/2006/mxml” width=“100%” height=“100%” creationComplete=“url=’ImageManager.swf’; loadModule()”/>
    2. mod-access/embed
      The ImageManagerAccess.xml includes the Module ImageManager itself:

      <local:ModAccessEmbed xmlns:imageManager=“imageManager.*” xmlns:local=“*” width=“100%” height=“100%”>
            <imageManager:imageManager/>
          </local:ModAccessEmbed>

      The class ModAccessEmbed mimics the behavior of the mx:ModuleLoader class. The code shows an excerpt

      public class ModAccessEmbed extends Canvas
          {
            public function loadModule() : void
            {       
              …
            }
            public var url:String;
            … // additional methods from mx:ModuleLoader as needed 
          }
  • Wherever you want the module to appear, don’t use a mx:ModuleLoader, but the corresponding ImageManagerAccess
  • If you want your Flex project to contain all modules code in the main .swf, put mod-access/embed into your projects source path. If you want to build it separately, put mod-access/extern into your source path and remove the mod-access/embed line.

This way, you can easily switch (by just swapping the source pathes) between building one swf that contains the complete modules and compiling main application and modules separately. Or use Flex Builder to develop the integrated version and an Ant build.xml for compiling the final application.swf as well as the swf for the modules.

Useful links for working with modules/RSLs:

Share This

Leave a Reply

You must be logged in to post a comment.

Close
E-mail It
Socialized through Gregarious 42