O'Reilly logo

Essential ActionScript 3.0 by Colin Moock

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Distributing a Class Library as a .swf File

When working with multiple .swf files that use the same class, compiling that class into every .swf is a waste of space. When file size is a concern, we can prevent such redundancies by producing a class library in the form of a separate .swf file and loading that .swf file at runtime. Once the library has loaded the first time, it is cached on the end user's machine and can be reused by other .swf files without being downloaded again.

Tip

The process of creating and using a .swf-based class library is more complex than using a .swc-based class library. Consequently, you should use .swf-based class libraries only when you wish to make your application's file size as small as possible.

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

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

To demonstrate the process of creating a .swf file containing a class library in Flex Builder 2, we'll again return to the beavercore example. The following steps describe how to create a class library, named beavercore.swf, that contains a single class, TextAnimation (we'll assume we're starting from scratch, even though some of the following steps are repeated from the earlier section "Creating a .swc-Based Class Library in Flex Builder 2").

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

  2. In the New Flex Library Project dialog, for Project name, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required