Saving and Accessing Version/Compilation Information with Flex Applications

Filed under ActionScript 3, Flex, Programming

On several occasions while developing Flash applications I've run into problems with proxy/cache servers. The pattern is usually something like this:

  1. I notice a bug in an application that only occurs when running it on the server
  2. I debug the application, find the bug and issue a fix
  3. I deploy the new version that contains the fix onto the server
  4. I empty the browser cache and run the app on the server again, noticing that the bug seems to persist
  5. I wonder if the version I'm seeing is indeed the version that has the fix, or an older build served to me by some cache server between my workstation and the server
  6. I have to resort to stupid trickery (comparing md5 hashes of .swfs or something) in order to find out

The obvious solution to this problem is to make some sort of version information (that changes on each build) accessible to the application itself so that it can print it into the log or display it in the UI. As of Flex 3, this is quite easy to do with the conditional compilation feature in the mxmlc compiler.

Due to the kinds of problems I've described above, I've taken up the practice of injecting a specific kind of string into my Flex apps at compilation time, containing the date and time of when it was compiled, as well as the hostname of the computer where it was compiled (and even though I only started this practice due to this specific problem that I was trying to solve, I believe saving version information into the build product should be standard practice for all kinds of software). An example of how I do this follows:

  1. Compile the binary with the conditional compilation parameter:
  2. /path/to/mxmlc -define+=DEBUG::compiled,"Fri_Sep_12_17:26:13_on_Alis-MacBook.local" -strict=true /path/to/myApp.mxml
  3. Print out the "compiled" value in the application code:
  4. var DEBUG:Namespace = new Namespace("DEBUG");
    var compiledStr:String = DEBUG::compiled;
    trace("SWF was compiled: "+compiledStr);

Of course, for this to actually be useful, you somehow need to be able to automate the creation of this "compiled" string value. Here are some example scripts that show how to go about doing this:


Ralph Krausse January 19, 2010 at 8:28 PM

Very nice but I can’t get my project to compile.

Error: Access of undefined property compiled.