Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I configure an Air application to reference an external configuration file?

I'd like to reference an external configuration (e.g., *.ini) file that will allow me to set configuration variables for each deployment of my Air application. Unfortunately, I haven't been able to find any information on the best way to approach this problem.

With that being said, does anyone have any advice on how to make this happen?

like image 940
Huuuze Avatar asked Mar 30 '09 21:03

Huuuze


2 Answers

Here's the implementation of the small xml idea:

var file:File = File.applicationDirectory.resolvePath( "config.xml" );
var stream:FileStream = new FileStream();

stream.open( file, FileMode.READ );
config = new XML( stream.readUTFBytes( stream.bytesAvailable ));
stream.close();

Just place the config.xml file in your src directory, it will appear in the installed directory when the release package gets installed. I made config a public var on my main application, so I can just do Application.application.config.someOption from anywhere in my project.

like image 113
Lucki Avatar answered Nov 15 '22 09:11

Lucki


I dont know if there is an air centric way of making this happen. I haven't found any good class i the api docs. If you got a lot of configuration options there might be an idea to look for an existing library that can help you. But if you just need to store some simple settings i would just create a small xml file and parse it with E4X.

It might be possible to jam it inside the application descriptor but it doesn't feel like a good solution if you want someone to manually change some settings.

like image 26
Tjelle Avatar answered Nov 15 '22 10:11

Tjelle