Wiki

Clone wiki

dsair / SettingsManager

HOWTO: SettingsManager: Saving and recovering app settings

Introduction

The SettingsManager controls saving the app settings locally. It's essentially a wrapper for the SharedObject class, which the bonus of compressing the settings data before saving it, to save on space

Details

Check out the TestSettings.as file for the full details.

As with all examples, you need to init the framework before doing anything:

#!actionscript

DSAir.init( this ); // "this" is your Document class

##Registering classes##

The first thing you need to do when using the SettingsManager is to register your settings class. You can do this by passing the class itself:

#!actionscript

SettingsManager.instance.registerClass( MySettings );

If your settings class contains any other classes, then you need to register those as well. This is to make sure that you recover the right class, and not simply an Object.

##Getting your settings##

You can get your settings by calling

#!actionscript

var settings:MySettings = SettingsManager.instance.get() as MySettings;

In this example, settings will be null if there are no settings.

##Saving your settings##

You can save your settings by calling something like:

#!actionscript

var settings:MySettings = new MySettings;

// do something with settings

// save it
var success:Boolean = SettingsManager.instance.save( settings );
trace( "Did we save our settings alright? " + success );

##Clearing your settings##

If your want to clear your settings, just call:

#!actionscript

SettingsManager.instance.clear();

Updated