Give us a call 203-379-0773

What do you do with a SWC?

When you download a Flextras component--or many of the other Flex components out on the interwebs--they often come as a SWC file. What do you do with that SWC file? How do you use it in your Flex projects? I'm writing this to explain what to do.

Where does a SWCs come from?

SWCs are created in one of two ways. In Flex Builder you create a library project. Library projects are a lot like a normal Flex Project, except there is no main application file and the binary output is a swc file, not a swf. The alternate is to use the command line compiler compc.

You create classes in a library project just as if you were going to create classes in a Flex project. The compiler does magic and packages up your code into a SWC which is easily reusable across multiple projects. In this article I'm not going to go into details of creating a SWC, I'm going to focus on what you do after you have the SWC.

Using the SWC

There are three different ways that you can use the classes that reside in a SWC file:

  1. Library Path in Project Properties: This is how I use SWCs most commonly.
  2. Libs folder: The libs folder was introduced in Flex Builder 3. If you put a SWC into a libs folder it is automatically added to your library path, and all the classes in the SWC are available from your project
  3. Library Path command line argument: You can use the library path argument to the mxmlc command line compiler.

These are all different routes to the same endpoint. Most developers I'm aware of use Flex Builder, but I'll go over all three options.

Adding a SWC to the Library Path

First you want to right click on the project and bring up properties:

The project properties window is below. Select, Flex Build Path and then Library Path

Press the buttons to Add a SWC Folder or to add a SWC

Browse to the folder, or directly to a swc, then click okay and the new SWC should be added to your library path. Click okay and you can now use the classes in the SWC inside your application, just as if the code was in the project's source folder.

If you have a library project in the current workspace, you can also add it using the add Project dialog. From the screenshot you can tell that is the way I work when developing Flextras Components.

Using the Libs Folder and Command Line

Using the libs folder is almost trivially easy. Just add your SWC file to the libs folder of your Flex Builder Project. Flex Bulder will automatically add the file library path when compiling the project.

The final method is to use the command line. There isn't much to elaborate on. You just need to know the path to your file and then use the library-path command line argument, like this:

-library-path+=c:/mylibraries/MyButtonSwc.swc

Summary

SWC files allow you to create functionality and easily reuse it throughout many projects. They are a great example of hiding the implementation that is so important to encapsulation. So, those are the ways that you can use a SWC in your Flex Builder Projects.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)

garcinia cambogia reviews

payday loans online

seo services