Application Modularization from 30,000 Feet

Even a relatively small Flex application has to be modularized. More often than not, a Flex application consists of more than one Flash Builder project. You’ll learn more about modularization in Chapter 7; for now, a brief overview will expose you to the main concepts that each Flex developer/architect should keep in mind.

Your main Flash Builder project will be compiled into a main .swf application, and the size of this .swf should be kept as small as possible. Include only must-have pieces of the application that have to be delivered to the client’s computer on the initial application load. The time of the initial application load is crucial and has to be kept as short as possible.

Modularization of the Flex application is achieved by splitting up the code into Flex libraries (.swc files) and Flex modules (.swf files). Initially, the application should load only the main .swf and a set of shared libraries that contain objects required by other application modules. Flex modules are .swf files that have <mx:Module> as a root tag. They can be loaded and unloaded during the runtime using Flex’s ModuleLoader loader. If the ability to unload the code during the runtime is important to your Flex application, use modules. If this feature is not important, use Flex libraries, which are loaded in the same application domain and allow direct referencing of the loaded objects in the code with the strong type checking.

Although .swf files are created by the mxmlc compiler, Flex libraries are compiled into .swc files via the compc compiler. Flex libraries can be linked to an application in one of three ways:

  • Merged into code

  • Externally

  • Via Runtime Shared Libraries (RSLs)

The linkage type has to be selected based on the needs of the specific application.

Note

Chapter 8 describes pros and cons of each type of linkage, as well as a technique that allows you to create so-called self-initialized libraries that can be reused in Flex applications in a loosely coupled fashion.

Application fonts and styles are good candidates for being compiled into a separate .swf file that is precompiled and is loaded during the application startup. This will improve the compilation speed of the Flash Builder’s projects, because compiling fonts and styles is a lengthy process.

Modularizing the application also simplifies work separation between Flex developers, as each small team can work on a different module. Flex 3.2 has introduced so-called subapplications, which are nothing but Flex application .swf files that can be compiled in different versions of Flex. SWFloader can load this subapplication either in its own or in a separate security sandbox.

Get Agile Enterprise Application Development with Flex now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.