Return to Snippet

Revision: 39712
at October 30, 2011 17:16 by adrianparr


Updated Code
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"));

Revision: 39711
at January 20, 2011 02:21 by adrianparr


Initial Code
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) {
			var _data = 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"));

Initial URL
http://www.terrypaton.com/shared-object-manager/

Initial Description
Credit for this goes to Terry Paton

Initial Title
AS3 Shared Object Manager

Initial Tags
object

Initial Language
ActionScript 3