返回顶部

收藏

Flash Cookie Class

更多

import flashCookie;var fc:flashCookie = new flashCookie;3种方法:setCookie - requires two argumnets, a name for your cookie and an object containing whatever data you want to store.readCookie - requires one argument, the name of your cookie, and returns an object containing three properties, or false if the cookie isn't found. The returned object contains three properties: cookie_name, cookie_created and cookie_data.deleteCookie - requires the name of the cookie to delete.

[Flash/ActionScript/Flex]代码

class flashCookie {

     private var so:SharedObject;

     function flashCookie() {
          //empty
     }

     //set cookie with the current date and time
     public function setCookie(cName:String,cData:Object):Void {    
          var date:Date = new Date();
          so = SharedObject.getLocal(cName);
          so.data.cookie_name = cName;
          so.data.cookie_created = date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() + " - " + date.getDate() + "/" + (date.getMonth() + 1) + "/" + date.getFullYear();
          so.data.cookie_data = cData;
          so.flush();   
     }

     //retrieve the cookie if it exists
     public function readCookie(cName:String):Object {  
          so = SharedObject.getLocal(cName);
          if (so.data.cookie_name == cName) {
               return so.data.cookie_data;
          } 
          return false;     
     }

     //delete the cookie
     public function deleteCookie(cName:String):Void {  
          so = SharedObject.getLocal(cName);
          if (so.data.cookie_name == cName) {
               so.clear();
          }     
     }
}

标签:Cookie

收藏

0人收藏

支持

0

反对

0

发表评论