Distributing a Class Library as a .swc File

When working with a team of offsite developers or publishing a class library for the world at large, the approach of sharing class files directly can be cumbersome. For the sake of convenience, Adobe's ActionScript tools provide the option to wrap a class library in a single file, known as a .swc file.

The following sections describe first, how to create a .swc file containing a class library and then how to use classes from that library in an application.

Creating a .swc-Based Class Library in Flex Builder 2

To demonstrate the process of creating a .swc file containing a class library in Flex Builder 2, we'll return to the Beaver Code example from the preceding section. Our class library will be called "beavercore," and have a main package of com.beavercore. The package name matches a fictional web site, http://www.beavercore.com, that the developers at Beaver Code have created to host the beavercore class library.

The following steps describe how to create a .swc file, beavercore.swc, containing the beavercore class library. For the sake of simplicity, the library contains a single class only, com.beavercore.effects.TextAnimation.

  1. In Flex Builder, select File → New → Flex Library Project.

  2. In the New Flex Library Project dialog, for Project name, enter beavercore, then click Next.

  3. For Main source folder, enter src, then click Finish.

  4. With the src folder in the beavercore project selected, choose File → New → Folder. For Folder name, enter com ...

Get Essential ActionScript 3.0 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.