AS3 Shared Object Manager


/ Published in: ActionScript 3
Save to your folder(s)

Credit for this goes to Terry Paton


Copy this code and paste it in your HTML
  1. package {
  2.  
  3. import flash.net.SharedObject
  4. import flash.utils.Dictionary;
  5.  
  6. public class SharedObjectManager {
  7. public function SharedObjectManager():void {
  8. _instance = this
  9. }
  10. public function setupSharedObject(_string:String):void {
  11. // setup the shared object if it doesn't exist already
  12. so = SharedObject.getLocal (_string)
  13. }
  14. public function getData(_string:String):Object {
  15. var _data:Object = so.data[_string]
  16. return _data
  17. }
  18. public static function getInstance():SharedObjectManager {
  19. return _instance
  20. }
  21. public function setData(_key:String,_val:*):void {
  22. so.data[_key] = _val
  23. save()
  24. }
  25. public function save():void {
  26. // save the shared object
  27. so.flush()
  28. }
  29. public static var _instance:SharedObjectManager
  30. public var so:SharedObject
  31. public var storage:Object
  32. public var dictionary:Dictionary
  33.  
  34. }
  35. }
  36.  
  37. // Usage Example
  38. //
  39. // import SharedObjectManager;
  40. // var _sharedOBJ:SharedObjectManager = new SharedObjectManager();
  41. // _sharedOBJ.setupSharedObject ("test");
  42. // // set the data
  43. // _sharedOBJ.setData ("lives",3);
  44. // // get the data
  45. // trace (_sharedOBJ.getData ("lives"));

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.