Here’s a class that comes in handy from time to time. It allows you to store key/value pairs, for configuration purposes for instance, and load them from an external XML source. You can also modify the settings by code. Here are some examples:
To add a setting or change the value of an existing setting, simply define it as a property as follows:
AppSettings.getInstance().mySetting = “myValue”;
To get a setting, request it as a property:
var result:String = AppSettings.getInstance().mySetting;
To delete a setting, use the delete operator:
The XML format is similar to that of .Net’s AppSettings config section. All settings are contained in a
<add key=”myFirstSetting” value=”aValue”/>
<add key=”mySecondSetting” value=”anotherValue”/>
To load these XML settings, just call the load() method:
AppSettings.getInstance().load(“pathtosettings.xml”); (to load from an xml file)
AppSettings.getInstance().load(myXmlObject); (to load from an xml object)
To use this class, just place the herrodius.swc from the bin folder in your classpath. More info is available in the release notes.
This class uses the flash_proxy class to control the dynamic properties. It is similar to the older __resolve() method but offers much better control.
The download contains the binaries, the docs and the source files: herrodius-as3lib-v0.1.zip
Any feedback is greatly appreciated.
Add to Bloglines - Digg This! - del.icio.us - Stumble It! - Twit This! - Technorati links - Share on Facebook - Feedburner