Posted By

adrianparr on 01/20/11


Tagged

object variables Shared manager storage as3 sol


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

burnandbass
kure69
darkbaron1912
merritt212
scottwatkins


AS3 Shared Object Manager


 / Published in: ActionScript 3
 

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

Credit for this goes to Terry Paton

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

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: romech on March 25, 2012

Useful! But what's the use of "storage" and "dictionary"?

You need to login to post a comment.