ActionScript 3 cookie class

ActionScript 3 cookie class:

package com.foxarc.util {  
      
    import flash.net.SharedObject;    
 
    public class Cookie {  
          
        private var _time:uint;  
        private var _name:String;  
        private var _so:SharedObject;  
          
        public function Cookie(name:String = "foxarc", timeOut:uint=1800) {  
            _name = name;  
            _time = timeOut;  
            _so = SharedObject.getLocal(name, "/");  
        }  
          
        //Clear time out contents;  
        public function clearTimeOut():void {  
            var obj:* = _so.data.cookie;  
            if(obj == undefined){  
                return;  
            }  
            for(var key in obj){  
                if(obj[key] == undefined || obj[key].time == undefined || isTimeOut(obj[key].time)){  
                    delete obj[key];  
                }  
            }  
            _so.data.cookie = obj;  
            _so.flush();  
        }  
          
        private function isTimeOut(time:uint):Boolean {  
            var today:Date = new Date();          
            return time + _time * 1000 < today.getTime();  
        }  
          
        //Get time out value;  
        public function getTimeOut():uint {  
            return _time;  
        }  
          
        //Get name   
        public function getName():String {  
            return _name;  
        }  
          
        //Clear all values of cookie

        public function clear():void {  
            _so.clear();  
        }  
          
        //add values of cookie

        public function put(key:String, value:*):void {  
            var today:Date = new Date();  
            key = "key_"+key;  
            value.time = today.getTime();  
            if(_so.data.cookie == undefined){  
                var obj:Object = {};  
                obj[key] = value;  
                _so.data.cookie = obj;  
            }else{  
                _so.data.cookie[key] = value;  
            }  
            _so.flush();  
        }   
                      
        //Delete values of cookie
        public function remove(key:String):void {  
            if (contains(key)) {  
                delete _so.data.cookie["key_" + key];  
                _so.flush();  
            }  
        }  
          
        //Get values of cookie   
        public function get(key:String):Object{       
            return contains(key)?_so.data.cookie["key_"+key]:null;  
        }  
          
        //Is the value of cookie exist   
        public function contains(key:String):Boolean{  
            key = "key_" + key;   
            return _so.data.cookie != undefined && _so.data.cookie[key] != undefined;  
        }  
    }  




Comment: 0 | Read times: -
Announce commentary
Your name
Content
Validation code Code