Creating ModulesYou can create, add, optimize, and debug modules in Adobe® Flash® Builder™. For information on writing module code, see Creating modular applications. Creating modules in Flash BuilderThe following steps describe how to create a new module in Flash Builder. After you create a new module, you can compile it. Create modules in Flash Builder
Compiling modules in Flash BuilderIn Flash Builder, you can either run the module as if it were an application or you can build the module’s project. If the modules are in the same project as your application, then when you run your application, Flash Builder compiles SWF files for all modules in the project. The SWF files are then loaded into the application at run time. You cannot run the module-based SWF file as a stand-alone Flash application or load it into a browser window. It must be loaded by an application as a module. If you run the module in Flash Builder to compile it, close Adobe Flash Player or the browser window and ignore any errors. Modules should not be requested by the Player or through a browser directly. The module SWF files and main application SWF file are typically in the same directory, although Flash Builder compiles the modules at the same time as your application, regardless of their location. Modules can be in the same directory as the application or in subdirectories. 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. If you compile modules separately from the main application, be sure to include or exclude debugging information, based on whether you want to debug your application and modules. For more information, see Debugging modules in Flash Builder. The Flash Builder workflow is designed around associating modules with a single application. If you want to use modules across multiple applications, consider encapsulating the code in a library component or class and including that in a simple module for each application. Modules are not intended to be used for cross-application code reuse; that is for libraries. Using multiple projects for modulesWhen 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. Using one project for each moduleUsing one project for each module has the following benefits:
Using one project for each module has the following drawbacks:
Using one project for all modulesA related approach is to use a single project for all modules, while keeping the application in its own separate project. This has some of the drawbacks of using a single project for both the application and the modules, but it has many of the same benefits as using a separate project for each module. Using one project for all modules has the following benefits:
Using one module project for all modules has the following drawbacks:
Creating projects for modulesWhen creating a separate project for modules, you change the module project’s output folder to a directory that is used by the application. You also suppress the generation of wrapper files. Create a separate project for modules in Flash Builder
Compiling projects for modulesCompiling multiple projects in Flash Builder is a common operation. First you choose the order in which you want the projects to be compiled and then you compile all projects at the same time. Compile all projects at the same time in Flash Builder
Flex builds all projects in the workspace. The application files are added to each project’s output folder. If you haven’t already chosen to save files automatically before a build begins, you are prompted to save the files. If you want to change the build order, use the Build Order dialog box. Changing the build order is not always necessary. Projects that use modules need to be compiled only by the time the main project application runs, not as it is compiled. In most cases, the default build order is adequate. However, if you want to eliminate overlapping dependencies, you might need to change the build order so that the main application is compiled first. At that time, you use the link-report compiler option to generate the linker report. When you compile the modules, you use the load-externs compiler option to use the linker report that was just generated by the shell application. For more information on reducing module size, see Optimizing modules in Flash Builder. Change the build order of the projects
If you create dependencies between separate projects in the workspace, the compiler automatically determines the order in which the projects are built, so these dependencies are resolved properly. When you use a separate project for each module, you can compile a single module at a time. This can save time over compiling all projects at once, or over compiling a single project that contains all module and application files. Compile a single module’s project
Adding modules to your projectIn some cases, you use modules that are not in your main application’s project. You might have the module in a separate project so that you can use custom configuration options, or you might want to share the module across multiple applications. Add the module’s source code to your application’s source path and then add the module to the application’s module list before you can use it in your project. Add an already-compiled module to your project
Optimizing modules in Flash BuilderIn Flash Builder, you typically select a single application to optimize the module against when you first create the module or add it to a project. If you later decide to change the application that you optimize the module against, or if do not want to optimize the module, you can edit the module’s properties within the project. For more information, see Reducing module size. Optimize modules with Flash BuilderThis procedure assumes the module and application are in the same Flash Builder project. If the modules are in a separate project, manually add the load-externs and link-report compiler options.
To further optimize a module’s file size, you can remove debugging information. If you build a module in Flash Builder, debugging information is included in the module by default. By removing debugging information, you can further reduce the size of the module. For instructions on how to remove debugging information from modules, see Debugging modules in Flash Builder. Debugging modules in Flash BuilderTo debug modules and applications, you must include debug information in the SWF files when they are compiled. To do this in Flash Builder, just run the application, because debug information is included by default. On the command line, you set the debug compiler option to true. The default is true, but if you disabled it in a configuration file, you must be sure to override it. By default, Flash Builder builds a single SWF file that includes debug symbols, so both Run and Debug work when you execute an application that uses modules in Flash Builder. However, including debug symbols in a module’s SWF file makes the SWF file larger. To exclude debug symbols prior to deployment, you must disable debugging for the application’s modules. To do this, you export the release version of the modules by selecting Project > Export Release Build. To exclude debugging information from SWF files in Flash Builder, you can either set the debug option to false in the Additional Compiler Arguments text box, or you can output the SWF files by using the Export Release Build feature, which generates non-debug SWF files. This includes the modules, if those modules are in the current project. If you create a separate project for your modules, you can enable or disable debugging for the entire project, without changing the settings of your main application. When you want to debug a module, you must also debug the application that loads the module. The Flex debugger will not connect to an application that does not contain debug information, even if the modules that the application loads contain that information. In other words, you cannot exclude debug information from the application if you want to debug the module that the application loads. When you’re using modules in an AIR application, the module SWF must be located in the same directory as the main application SWF or one of its subdirectories. |
|