How to link SWC files to a TextMate Flex project
May 13th, 2009
I was recently asked how to compile using TextMate when you have precompiled SWC dependencies. This is a very common workflow but it’s unfortunately not as automatic as dropping them in your ’src’ directory. This is how to resolve the issue if you’re working with a folder structure built with TextMate’s Flex bundle (via File > New From Template > Flex > Project)
There’s a few ways to handle this. The quick way is to ensure that any SWC’s you use on any project are in your SDK’s frameworks/libs directory and that when mxmlc is run from the command line it runs from this SDK directory.
There’s two drawbacks to this method, however. One is that if you ever update your SDK you’ll have to migrate the SWC’s over manually (when it can often be unapparent which SWC’s are third-party and which are part of the SDK). You’d also need to have a redundant copy of SWC’s in each SDK you use (say you’re trying out both Flex 3 and Flex 4). Secondly, if you work with source control then there are code dependencies which reside outside the project folder, which is not ideal for anyone else that’s trying to collaborate with you, nor yourself if you’re trying to work on another machine. You could include your SDK in the source control, but this is not as compact a solution as sync’ing with the project folder itself.
So say we want to put all dependent SWC files in a ‘libs’ directory parallel our ’src’ directory, how do we do it?
To solve this, and potentially other future dilemmas, you really should familiarize yourself with the TextMate Bundle Editor (Bundles > Bundle Editor > Show Bundle Editor). Notice how there is no ‘Build’ option in the Flex bundle? This is because the Flex bundle also uses elements from the ActionScript 3 bundle. For example, if in the ActionScript 3 bundle you remove the keyboard shortcut for ‘Build’ and then change the ‘Build (mxmlc)’ keyboard shortcut to Cmd-B then you’ll remove a keystroke from your build process even in Flex projects. This is something I’ve personally done as I use mxmlc rather than the default Ant script to build. Remember to Bundles > Bundle Editor > Reload Bundles after making any changes.
But back to the issue at hand, open up Flex > Project > Project-config.xml. You’ll notice this is the schematic of a file which is created automatically when you create an Flex 3 project. Unfortunately, the Project-config.xml schematic in the Flex bundle lacks these two sample nodes that are in the ActionScript 3 bundle. These are:
<!-- Example library linkage -->
<!-- for swc's
<library-path append="true">
<path-element>../lib/bin/</path-element> </library-path> -->
<!-- for src
<source-path append="true">
<path-element>../lib/src/</path-element> </source-path>
-->
This file acts as a project-level override to the general configuration file found in the SDK directory. Close the bundle editor. You’ll want to add the following to your project’s configuration xml which lives in ’src’:
<library-path append="true">
<path-element>../libs/</path-element>
</library-path>
Now you can create a new directory named ‘libs’ parallel to ’src’ and drop into here all SWC files that your project depends on. Save the configuration file and you should be able to build. Now anyone with the Flex SDK will be able to save your project directory locally and jump right into compiling
You can also add any other project-specific compiler instructions in here. More information on your compiler switches options are here. For example, during a recent project I had a lot of unimportant warnings being fired with each compile so I was able to silence them with:
false
HTH.