Follow Flex After Dark on Twitter

Libraries in Flex

A Library is collection of Flex/ActionScript classes and resources compiled to a .swc file.

A library is different than a Flex application in that you cannot launch a library. Rather, a library is a code reuse and packaging mechanism.

There's two ways you can use libraries in your project: .swc file or project reference.

Project Lib Folder

Each new Flex project is automatically created with a lib folder. Each Flex library (.swc file) added to the lib directory will automatically be included in your project's build path.

Referencing Libraries

Managing Libraries

  1. Right-click on your Project
  2. Select Properties from the menu
  3. Select Flex Build Path from the left
  4. Click on the Library Path tab

images/screenshot/TODO

Referencing another Project

To reference a Flex Library project in your workspace...

  1. Get to your project's properties Library Path tab (described above)
  2. Click the Add Project button
  3. Select the Project you wish to reference
    1. Listed projects include all Flex Library Projects in your Flex Builder workspace

images/screenshot/TODO

Flex Library Build Paths

For each Flex Library you must specify which classes and assets are included in it.

Just because you've created a class in a Library project does not mean that it will automatically included in the built library. (It should mean that, but it doesn't.)

To specify which classes and assets are included in your library:

  1. Right-click on your Project
  2. Select Properties from the menu
  3. Select Flex Library Build Path from the left
  4. Select the Classes tab
    1. Make sure all the classes you want included are checked (typically you'll want all the classes in your project)
  5. Select the Assets tab
    1. Make sure all the assets you want included are checked

images/screenshot/TODO

If you rename a file in your library, you may have to re-include it in your build path. (It shouldn't be necessary, but it often is.)

Related Links:

  • ???

(From Flex Builder documentation) (Search for "Flex project types") (Using Flex Builder 3 / Flex Builder Basics / Working with Projects)

Configuring libraries for your applications

You use SWC libraries in your projects in the following ways:

Merged into the application When you add a SWC file to the project's library path, the components contained in the library are available to use in your application. When you build the application, only the library components you actually used are compiled into the application SWF file. In other words, all of your application code is merged into a single SWF file. This is the most common and straightforward way of using library components.

External to the application You can keep library components separate from the compiled SWF file, so they are not merged into the file. The compiler resolves all code contained in the library that is used by the application, but does not merge the code into the application SWF file. The advantage of this approach is that you make the application SWF file smaller. The components contained in the SWC file are retrieved and loaded into memory as needed, at run time.

Runtime Shared Library In Flex projects only, you can also use SWC files as a Runtime Shared Library (RSL), which is similar to a dynamically linked library on other platforms. Use SWC files as an RSL when you have a collection of components that are used by more than one application.

There are several advantages to sharing components between applications by using an RSL. First, the library is loaded into memory once, cached, and then available to all the applications that use those components. Second, the components contained within the library are only loaded when they are needed, which reduces the application's start-up time because the size of each application is smaller. The potential problem to this approach is that the entire RSL is loaded into memory, rather than the individual components that the applications use. For more information about when to use SWC files as an RSL, see Using Runtime Shared Libraries in Building and Deploying Adobe Flex 3 Applications.

Related Docs
  • Flex Projects Overview of the different types of projects that can be created with Flex Builder.
Recent Docs
Random Docs