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\mymain.as" -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.