Every now and then, while working on a AIR application, i feel the need to save or restore some config info, like the last window position, or the last opened files.

Instead of embedding this login in every app, I thought about a PreferenceManager class that stores and restores values.

How it should behave:

  • It must save data on a file.
  • It must save data on an open and editable format, so if something goes wrong..
  • It should be a static class, so i can access it in every other class of my application, whitout the need to have the reference to the instantiated object.
  • It should be really simple to use. And should not require any setup.


So having stated this, the public interface looks like this:


GeSHi Error: GeSHi could not find the language actionscript3 (using path /nfs/c03/h01/mnt/85630/domains/nightdrops.com/html/wp-content/plugins/snipplr/geshi/geshi/) (code 2)

Preferences will be saved in a file in File.applicationStorageDirectory called preferences.xml, so every Application will have his own preference file.

The usage comes easy, when I want to save a preference, let’s say the last user name entered I’ll


GeSHi Error: GeSHi could not find the language actionscript3 (using path /nfs/c03/h01/mnt/85630/domains/nightdrops.com/html/wp-content/plugins/snipplr/geshi/geshi/) (code 2)

and next time I open the application, to retrieve the data


GeSHi Error: GeSHi could not find the language actionscript3 (using path /nfs/c03/h01/mnt/85630/domains/nightdrops.com/html/wp-content/plugins/snipplr/geshi/geshi/) (code 2)

This implies two things: when i get a preference that hasn’t been set, the method will return null and I can only save string values.

Sooner or later I’ll talk about reflection and how to serialize any kind of object.

So now go download the Preferences.as class!