Created
December 15, 2013 17:57
-
-
Save grapefrukt/7975990 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ; | |
import flash.errors.Error; | |
import flash.net.SharedObject; | |
/** | |
* Completely unnecessary wrapper for SharedObject | |
* @author Martin Jonasson, [email protected] | |
*/ | |
class SaveData { | |
private var _so:SharedObject; | |
public function new() { | |
// maybe call load here, depending on use case... | |
} | |
public function load():Void { | |
// first part is the name of your project or otherwise | |
// use a slash as the second argument to make it location independent | |
// (if not .swf's stored in different locations will have separate saves) | |
_so = SharedObject.getLocal( "spaceblocks", "/" ); | |
} | |
// saving, put this in the set() call to always save when something changes | |
public function save():Void { | |
try { | |
var flushStatus = _so.flush(); | |
} catch ( e:Dynamic ) { | |
trace("Couldn't write..."); | |
} | |
} | |
// saves a variable (can be anything pretty much, including objects and such) | |
public function set(field:String, data:Dynamic):Void { | |
Reflect.setField(_so.data, field, data); | |
} | |
// what this function does is left as an excersise for the reader ;) | |
public function get(field:String):Dynamic { | |
return Reflect.field(_so.data, field); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment