/ Published in: ActionScript 3
Credit for this goes to Terry Paton
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
package { import flash.net.SharedObject import flash.utils.Dictionary; public class SharedObjectManager { public function SharedObjectManager():void { _instance = this } public function setupSharedObject(_string:String):void { // setup the shared object if it doesn't exist already so = SharedObject.getLocal (_string) } public function getData(_string:String):Object { var _data:Object = so.data[_string] return _data } public static function getInstance():SharedObjectManager { return _instance } public function setData(_key:String,_val:*):void { so.data[_key] = _val save() } public function save():void { // save the shared object so.flush() } public static var _instance:SharedObjectManager public var so:SharedObject public var storage:Object public var dictionary:Dictionary } } // Usage Example // // import SharedObjectManager; // var _sharedOBJ:SharedObjectManager = new SharedObjectManager(); // _sharedOBJ.setupSharedObject ("test"); // // set the data // _sharedOBJ.setData ("lives",3); // // get the data // trace (_sharedOBJ.getData ("lives"));
URL: http://www.terrypaton.com/shared-object-manager/