Configuring Flash Applications with INI Files

I have seen several different techniques for configuring Flash applications. The simplest and most often used is probably the comment technique:

//var someUrl = "";
var someUrl = "";

Another technique is to use trace statements to redefine variables for a development environment, then omit the trace statements while publishing your movie in preparation for production (thereby defining the variables in a manner appropriate for production):

var someUrl = "";
trace(someUrl = "");

These methods both require you to maintain your configuration inside your application FLA file, which isn’t always convenient, especially if you want one SWF file to run two different ways in two different contexts. External configuration is more appropriate for this type of requirement. To configure your applications externally, you can use several techniques:

  • XML
  • XMLSocket
  • loadMovie
  • loadVariables
  • Probably some others I can’t think of right now

XML is a great solution, but sometimes it’s overkill, and can be more trouble than it’s worth for just a few configuration parameters. In such circumstances, I like to use external files in INI format:

# This is a comment.  It will be ignored.

For parsing external INI files, I use the PropertyLoader class (along with the SimpleMap class). So far I have had good luck putting the INI file in the same directory as the the SWF file and loading it like this:

var pLoader:PropertyLoader = new PropertyLoader();
pLoader.loadFromUrl("myConfigFile.ini", this, "onSuccess","onFailure");

public function onSuccess(params:SimpleMap):Void
trace("Just loaded "+params.size()+" properties.");

public function onFailure(msg:String):Void
trace("It didn't work because: " + msg);

What kinds of techniques do you use for configuration?