How to use SharedObject for save,get,delete date


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

Useful flash code.


Copy this code and paste it in your HTML
  1. The SharedObject class is used to read and store limited amounts of data on a user's computer or on a server. Shared objects offer real-time data sharing between multiple client SWF files and objects that are persistent on the local computer or remote server. Local shared objects are similar to browser cookies and remote shared objects are similar to real-time data transfer devices.
  2.  
  3. About how to save,get,delete date,we had do some code for you to understands....
  4.  
  5. Here is a save user , get user, delete user utils code.
  6.  
  7. public class SharedObjectUtils
  8. {
  9.  
  10. private static const LOCAL:String = "www.activetofocus.com";
  11.  
  12. /* get user list */
  13. public static function getUserList():Array
  14. {
  15. var shareObject:SharedObject = SharedObject.getLocal(SharedObjectUtils.LOCAL);
  16. var arr:Array = shareObject.data;
  17. return arr;
  18. }
  19.  
  20.  
  21. /* save user */
  22. public static function saveUser(userId:String,userName:String,userPassword:String):void
  23. {
  24. var shareObject:SharedObject = SharedObject.getLocal(SharedObjectUtils.LOCAL);
  25. var arr:Array = shareObject.data;
  26. var newArr:Array = [];
  27. if(arr != null && arr.length >0)
  28. {
  29. var k:int=0;
  30. for(var i:int = arr.length - 1; i>=0;i--)
  31. {
  32. if(arr[i].id != userId && k<2)
  33. {
  34. newArr.unshift(arr[i]);
  35. k++;
  36. }
  37. }
  38. }
  39. newArr.push({id:userId,name:userName,password:userPassword});
  40. shareObject.data= newArr;
  41. shareObject.flush();
  42. }
  43.  
  44.  
  45. /* delete user */
  46. public static function deleteUser(userId:String):void
  47. {
  48. var shareObject:SharedObject = SharedObject.getLocal(SharedObjectUtils.LOCAL);
  49. var arr:Array = shareObject.data;
  50. var newArr:Array = [];
  51. if(arr != null && arr.length >0)
  52. {
  53. for(var i:int=0; i
  54. {
  55. if(arr[i].id != userId) newArr.push(arr[i]);
  56. }
  57. }
  58. shareObject.data= newArr;
  59. shareObject.flush();
  60. }
  61.  
  62. }
  63.  
  64. from: http://activetofocus.com/blog/how-to-use-sharedobject-for-save-get-delete-date-27/

URL: http://activetofocus.com/blog/how-to-use-sharedobject-for-save-get-delete-date-27/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.