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 = "http://www.development.com";
var someUrl = "http://www.production.com";

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 = "http://www.development.com";
trace(someUrl = "http://www.development.com");

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.
name=value
someUrl=http://www.development.com
#someUrl=http://www.production.com

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?

7 Responses to Configuring Flash Applications with INI Files

  1. mike chambers says:

    cool stuff. Here is a ActionScript 1 version that I wrote a while ago:http://www.markme.com/mesh/archives/000069.cfmand here are the docs for it:http://www.markme.com/mesh/files/config/mike chambersmesh@macromedia.com

  2. Christian and Mike, nice work!I have been using something similar for a while now with VB apps that we use as wrappers for .swf files. We use .ini files to configure the VB app on the fly, and I devised a little routine to read in the same .ini file into Flash so that I could have access to the same values for testing and configuration. Makes life much easier. I also use the loadvars and ondata. Mine is not as robust error wise, but does essentially the same thing, although rather than put things into an array I set local variables in a specific namespace that is unique to the way I write some of the apps, such that each item becomes a local variable named: APP_xxxxxx with a property of xxxxx. sometimes I make them global, just depends on the need.Take a look at it here:http://www.impossibilities.com/blog/parse_ini.asFeel free to use and abuse.Rob

  3. Paul Arce says:

    XML and it is more trouble than it is worth in some cases as you mentioned in the article.

  4. Paul T says:

    This was very usefull thanks

  5. festus says:

    pls let me know your message clearly to anable me close to you thanks for your ancitipation.an nd holder in accounting.also pls introduce me to some good asistance to anable me sent my writing book all over the country.

  6. Marco says:

    Hello Christian,the download-links doesn’t work. Where can I also find them, I am very interested in your solution…