Modules are SWF files that can be loaded by an application but cannot run indepedently. Modules are built in to Flex 3, but it takes a bit of finagling to use modules in Flash.
I have been able to use modules successfully in Flash. Below are the steps to follow. I have also included the sample source code:
Grab the latest Flex SDK. I used 3.2:
In the Flash IDE (I’m using CS4), create a reference to the Flex SDK:
File > Publish Settings > Flash > Settings > Library Path
Add a reference to frameworks\libs (see the following image)
Create a module by creating a class that extends mx.modules.ModuleBase.
public class ModuleAlpha extends ModuleBase implements IModuleAlpha
public function ModuleAlpha()
public function addNumbers(a:Number, b:Number):Number
return a + b;
Compile the module using the mxmlc command line compiler.
Note: If you’ve placed your source in subdirectories, you will need to let the compiler know your source path.
In my example, ModuleAlpha.as is located in the com.electrotank.modules package.
Thus, here is my command to compile:
>mxmlc "-source-path+=../../../" ModuleBeta.as
Create a “parent” application that will load in your module(s) via mx.modules.ModuleManager.
Here is an excerpt from the sample code provided:
private const URL_MOD_ALPHA:String = "ModuleAlpha.swf";
_modules[URL_MOD_ALPHA] = ModuleManager.getModule(URL_MOD_ALPHA);
Create an instance of your newly uploaded module using the factory of IModuleInfo:
var modAlpha:IModuleAlpha = IModuleAlpha(IModuleInfo(_modules[URL_MOD_ALPHA]).factory.create());
Be sure to use your powers only for good and not evil.