·您当前的位置:首页 > 技术教程 > AS2与AS3技术 >

[AS3]as3与SharedObject记录缓存与清除缓存

时间:2014-08-11 08:50酷播
之前做一个数据缓存,就顺便把写入缓存,清除缓存,获取缓存都整理了一下,其中也做了些参考,个人水平有限,有需要的就拿去改改用吧。

之前做一个数据缓存,就顺便把写入缓存,清除缓存,获取缓存都整理了一下,其中也做了些参考,个人水平有限,有需要的就拿去改改用吧。

  1.         import flash.net.SharedObject; 
  2.         import flash.system.Security; 
  3.         import flash.system.SecurityPanel; 
  4.         public class cookie 
  5.         { 
  6.                 private var so:SharedObject; 
  7.                 private var _name:String 
  8.                 public function cookie(file_name:String) 
  9.                 { 
  10.                         // constructor code 
  11.                         so = SharedObject.getLocal(file_name,"/"); 
  12.                         _name=file_name 
  13.                 } 
  14.                 public function flushData(key:String,value:*):void 
  15.                 { 
  16.                         //添加数据 
  17.                         if (so.data.cookie == null) 
  18.                         { 
  19.                                 var obj:Object = {}; 
  20.                                 obj[key] = value; 
  21.                                 so.data.cookie = obj
  22.                         } else 
  23.                         { 
  24.                                 so.data.cookie[key] = value; 
  25.  
  26.                         } 
  27.                         trace(key+":"+so.data.cookie[key]); 
  28.                         flush(); 
  29.                 } 
  30.                 public function deleteData(key:String):void 
  31.                 { 
  32.                         //CuPlayer.com提示:删除数据值 
  33.                         if (judge(key)) 
  34.                         { 
  35.                                 delete so.data.cookie[key]; 
  36.                                 flush(); 
  37.                         } 
  38.                 } 
  39.                 public function getName():String 
  40.                 { 
  41.                         //CuPlayer.com提示:获取数据名 
  42.                         return _name 
  43.                 } 
  44.                 public function getData(key:String):* 
  45.                 { 
  46.                         //CuPlayer.com提示:获取数据值 
  47.                         if (judge(key)) 
  48.                         { 
  49.                                 return so.data.cookie[key]; 
  50.                         } else 
  51.                         { 
  52.                                 return null; 
  53.                         } 
  54.                 } 
  55.                 public function clearData():void 
  56.                 { 
  57.                         //CuPlayer.com提示:清除缓存 
  58.                         so.clear(); 
  59.                 } 
  60.                 public function judge(key:String):Boolean 
  61.                 { 
  62.                         //CuPlayer.com提示:判断数据是否存在 
  63.                         return so.data.cookie != undefined && so.data.cookie[key] != undefined 
  64.                          
  65.                 } 
  66.                 private function flush():void 
  67.                 { 
  68.                         //CuPlayer.com提示:写入 
  69.                         if (so) 
  70.                         { 
  71.                                 try 
  72.                                 { 
  73.                                         so.flush(); 
  74.                                 } 
  75.                                 catch (e:Error) 
  76.                                 { 
  77.                                         Security.showSettings(); 
  78.                                         Security.showSettings( SecurityPanel.LOCAL_STORAGE ); 
  79.                                 } 
  80.                         } 
  81.                 } 
  82.  
  83.         } 
  84.  

 

热门文章推荐

请稍候...

保利威视云平台-轻松实现点播直播视频应用

酷播云数据统计分析跨平台播放器