Automating SWC Creation in Flex 1.5

Flex was made for true software developers. I apparently am not the target market of said demographic, or have yet to see the benefit of casting off the usage of clicking graphical buttons.

Suffice it to say, there isn’t a symbol to right click on with an “Export SWC…” in the context menu like in Flash. Since Yahoo! Maps was created this way, however, it must still be good, right?

A program called “compc.exe” creats SWC’s in Flex. You point it at an MXML or AS file, tell it where your classes root folder is, and tell it what to name the the SWC file. There are a lot more parameters you can use the docs, but those main 3 are all you need to create SWC’s.

SWC’s are basically .zip files that contain your packaged component, and potentially other assets. They are what jar files are to Java. They can contain non-graphical, compiled assets for portable class libraries, or even images that your component needs to draw itself.

They are really nice in Flex because you deploy with your app, greatly simplifying the amount of files in your project. Additionally, you can deploy them on the server so all applications on your Flex server compile with the same SWC.

Since I was constantly testing a component recently, I had to keep remaking the SWC. Here’s a simple script you can paste into Notepad, and save as a .bat file on Windows. Then, all you have to do is double-click the file, and it’ll recompile the SWC for you.

cd c:\program files\macromedia\flex\bin
compc -o "C:\mypath\my.swc" "c:\mypath\" -root "c:\mypath\"

Ensure there is a carriage return after the “bin” so the compc part appears on it’s own line.

You can obviously automate this in other build tools like ANT.

One Reply to “Automating SWC Creation in Flex 1.5”

  1. Great intro. I never see as much information on compc/SWCs as I would like, but I’m a bit biased. I’m sure part of this is because it is only a command line tool in 1.x. In 2.0, the SWC format has completely changed. The catalog.xml file within the SWC is much cleaner and smaller. You can also add arbitrary files and do some other advanced things that couldn’t be done before.

    It was named compc, by the way, as shorthand for Component Compiler. We tried to come up with better names, but the ‘temporary’ name I used seemed to stick.

Comments are closed.