SWC Assets Packer

Written by Gilles on December 9, 2011

The SWC assets packer is an sh/PHP script (Mac, Linux compatible) which compresses a directory of assets (sound, image, data)  into one SWC file. The final SWC file contains the assets packaged in the same way you organized your folders (eg. myAsset/myFolder/happypic.png will become class myfolder.HappypicPng).
There is no need of using Flash authoring tool to export your assets as this script makes their integration quicker and more efficient.

How to use it?

Download files here and drop it in your scripts folder. Edit swc-assets-packer.sh and define the SDK_LOCATION variable with your flex sdk path (see below).

In terminal type:

It will create a swc called “NameOfMyPack.swc” with assets in “myAssetDir” inside your current directory.

Two optionals parameters are available:

-p allows you to move swc in a particular directory

-s allow you to create a swf in a particular directory

How it works

First the sh script call a php script which scroll your assets folder and create automatically packages and to empty classes based on your assets organisation. For instance assetsDir/myDir/mySubDir/myImage.png will become the class mydir.mysubdor.MyImagePng.
All classes created are instancied in an empty classes declared inside a hidden package (called Z_ASSET_PACKER_YouPackageName), all theses classed are instancied in a class in root package called “YouPackageName”. This is the only way to force flash compiling all your assets.
After that the original sh script use the compc command to compile the main classe we created before and create a fresh new swc file.

Optimization and automation

The sh script has been made for my workflow and it doesn’t perfectly with other cases, up to you to update the sh file in order to make your own batch.
For windows guys, you can easily create a batch script which will call the php script and flex sdk command (compc).

Hope this will save you some precious time, please fill free to drop comment if you have any question.

Here is the sources,