How to Use SWC as RSL in Pure AS3 Projects

Using SWC as RSL in Flex projects is a no brainer. Flash Builder and Flex ant task automate a lot of things for your convenience. Unfortunately, that’s not the case with pure AS3 projects. I read somewhere that you can use a special Frame tag and a factory class to load the RSL swf before you instantiate your document class. I tried that but I got mixed results; it didn’t always work in all cases especially when the SWC contains a lot of assets. I might be doing something wrong; I don’t know.

It turned out that you can use a “loader” SWF to load the RSL swf before your main SWFs to achieve the same thing. That left me with one problem, how to get the RSL swf out of the SWC. As we know, SWC is just another compression format, just like zip so any zip expander/extractor will work but manually extracting the SWC is going to be a pain in the @$$ and you’ll have to do it every time you update your SWC. This is where Ant becomes your best friend 😉

In this post, I’ll show you how to do it with Flash Builder & Ant.

Creating Projects

First, we create a new workspace and add build folder to store the published SWFs and then create the projects below:

  1. MyLibs – Flex library project. This is the RSL to be used by AppOne and AppTwo.
  2. AppOne – AS3 project
  3. AppTwo – AS3 project
  4. loader – AS3 project that will load all other SWFs

Then we add a Car class to MyLibs project and compile the project so we have MyLibs.swc in its bin/ folder.

App Projects

Now let’s open AppOne project properties.

  1. Go to ActionScript Build Path settings
  2. Add Mylibs.swc from MyLibs project and set its linkage type “external
  3. Open
  4. Instantiate Car class

Repeat those steps for AppTwo.

The Loader

Below is the file that loads everything.

ANT Script

Here’s the ANT script that extracts MyLibs.swc and put MyLibs.swf in the build folder.

And here’s a longer version If you want to compile your projects with ANT as well.


When you open loader.swf you should see the following trace output in flashlog.txt:

How do we know that Car class didn’t get compiled into the app SWFs? Well, if you have a decompiler like Sothink SWFDecompiler, you can check it visually and see that Car is not compiled into those SWFs.

Decompiled SWFs

Here’s the zip containing the samples →

Also in this category ...

Comments are closed.