·您当前的位置:首页 > 技术教程 > PHP教程 >

[AS3]as3基于SharedObject的Cookie类源代码

时间:2016-07-03 12:09酷播
[AS3]as3基于SharedObject的Cookie类源代码
  1. /**     
  2.  * @link http://www.klstudio.com     
  3.  * @author Kinglong   
  4.  * @playerversion flash player 9    
  5.  * @asversion 3.0   
  6.  * @version 0.5   
  7.  */      
  8.    
  9. package com.klstudio.util {    
  10.         
  11.     import flash.net.SharedObject;      
  12.    
  13.     public class Cookie {    
  14.             
  15.         private var _time:uint;    
  16.         private var _name:String;    
  17.         private var _so:SharedObject;    
  18.             
  19.         public function Cookie(name:String = "klstudio"timeOut:uint=3600) {    
  20.             _name = name;    
  21.             _time = timeOut;    
  22.             _so = SharedObject.getLocal(name, "/");    
  23.         }    
  24.             
  25.         //cuplayer.com提示:清楚超时内容;    
  26.         public function clearTimeOut():void {    
  27.             var obj:* = _so.data.cookie;    
  28.             if(obj == undefined){    
  29.                 return;    
  30.             }    
  31.             for(var key in obj){    
  32.                 if(obj[key] == undefined || obj[key].time == undefined || isTimeOut(obj[key].time)){    
  33.                     delete obj[key];    
  34.                 }    
  35.             }    
  36.             _so.data.cookie = obj;    
  37.             _so.flush();    
  38.         }    
  39.             
  40.         private function isTimeOut(time:uint):Boolean {    
  41.             var today:Date = new Date();            
  42.             return time + _time * 1000 < today.getTime();    
  43.         }    
  44.             
  45.         //cuplayer.com提示:获取超时值;    
  46.         public function getTimeOut():uint {    
  47.             return _time;    
  48.         }    
  49.             
  50.         //cuplayer.com提示:获取名称;    
  51.         public function getName():String {    
  52.             return _name;    
  53.         }    
  54.             
  55.         //清除Cookie所有值;    
  56.         public function clear():void {    
  57.             _so.clear();    
  58.         }    
  59.             
  60.         //cuplayer.com提示:添加Cookie值    
  61.         public function put(key:String, value:*):void {    
  62.             var today:Date = new Date();    
  63.             key = "key_"+key;    
  64.             value.time = today.getTime();    
  65.             if(_so.data.cookie == undefined){    
  66.                 var obj:Object = {};    
  67.                 obj[key] = value;    
  68.                 _so.data.cookie = obj;    
  69.             }else{    
  70.                 _so.data.cookie[key] = value;    
  71.             }    
  72.             _so.flush();    
  73.         }    
  74.             
  75.             
  76.         //cuplayer.com提示:删除Cookie值;    
  77.         public function remove(key:String):void {    
  78.             if (contains(key)) {    
  79.                 delete _so.data.cookie["key_" + key];    
  80.                 _so.flush();    
  81.             }    
  82.         }    
  83.             
  84.         //cuplayer.com提示:获取Cookie值;    
  85.         public function get(key:String):Object{         
  86.             return contains(key)?_so.data.cookie["key_"+key]:null;    
  87.         }    
  88.             
  89.         //cuplayer.com提示:Cookie值是否存在;    
  90.         public function contains(key:String):Boolean{    
  91.             key = "key_" + key;     
  92.             return _so.data.cookie != undefined && _so.data.cookie[key] != undefined;    
  93.         }    
  94.     }    

 

热门文章推荐

请稍候...

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

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