Friday, October 2, 2009


The companies that I work for tend to store swf files on CDNs (Content Delivery Networks) which distributes the file over multiple servers. Each server has a copy of the swf, and the one you get, when you visit the company site, might come from any of them.

This works well except for when I'm making rapid changes to the swf. Each time I make a change, the swf needs to get copied to all of the servers in the network. Until that happens, I can't be sure that everyone is seeing the must current version. Worse, I can't be sure that I'm seeing the most current version. Is my bug fix not working because there's something wrong with it? Or am I seeing the version before the fix.

The best way to deal with this is not to post constant fixes to the CDN. Test on a single-server site and then upload to the CDN when the app is ready to go live. In theory that works -- and in reality it works for most of the dev cycle -- but in this world of "always in beta," there's now less of distinction between the testing phase and the live phase. (Which sucks and is wrong, wrong, wrong, but I don't run the world.)

So inevitably I wind up tweaking the swf after it's gone live and is hosted on the CDN. If I find that a change has not propagated to all of the machines on the network, I have to run through a somewhat lengthy set of steps in a web control panel, to make sure that everyone is getting the latest copy. I only want to do this if necessary. Sometimes all the machines get updated as soon as I upload my changes. How can I tell?

Here's my simple solution:

import flash.ui.ContextMenu;
import flash.ui.ContextMenuItem;

const APP_VERSION : String = "1.0";

var menu: ContextMenu = new ContextMenu();
var contextMenuItem : ContextMenuItem = new ContextMenuItem( "app version: " + APP_VERSION );
menu.customItems.push( contextMenuItem );
this.contextMenu = menu;

I put this in my Document class and change the APP_VERSION every time I upload. Then, when I'm looking at it in the browser, I just need to right click on it to see if I'm looking at the most current version.