Paying Tribute to Libraries

If you need to modularize reusable components, look no further than libraries: Runtime Shared Libraries (RSL), to be specific. Assuming that you are using Flash Builder, the basic procedure is:

  1. Create a Flex Library project containing classes to be reused (call it, say, ComponentLibrary).

  2. Add a mapping to this project to the Flex Build Path of the application(s) that makes use of the library classes.

If you do not have the source code, add a mapping to the SWC file of the library compiled by a third party instead of to the library project. Look in the Flex Build Path of your application: all Flex framework classes are added via several .swc files, similar to Figure 7-8.

Default link type: merge into code

Figure 7-8. Default link type: merge into code

At this configuration level, library projects merely separate development of the business application from building of the reusable components; however, your application is still built as monolithic .swf. Why? Because when you add mapping to the library project or .swc of the compiled library, the default link type is “Merged into code.” This is static linking, where the application .swf contains only those classes it could determine as required at compile time. Recall the dynamic instantiation from Example 7-19:

var clazz:Class =
   loaderInfo.applicationDomain.getDefinition("CustomGrid") as Class;
dg  = DataGrid(new clazz());

Assuming the CustomGrid ...

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.