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

[AS3]as3的SharedObject简单应用SCookie

时间:2015-10-23 16:01酷播
[AS3]as3的SharedObject简单应用SCookie

[AS3]as3的SharedObject简单应用SCookie

SCookie 只是SharedObject的一个简单应用,简化了SharedObject的使用,能够更方便一些管理本地数据。 对于经常用到本地数据存储的同学,也许能有一点点帮助....
使用方法
写入:

SCookie.setCookie("cookie名称" ,"cookie属性名",cookie属性的内容)

读取:

SCookie.getCookie("cookie名称","属性名称")

清除:
SCookie.clearCookie("cookie名称")

eg:
import com.sixuu.SCookie

SCookie.setCookie("test","name","liam")
SCookie.setCookie("test","sex","male")
SCookie.setCookie("test","age",22)

  trace(SCookie.getCookie("test","name")) //liam

  trace(SCookie.getCookie("test","sex")) //male

  trace(SCookie.getCookie("test","age")) //22

  1. package com.sixuu { 
  2.     import flash.net.SharedObject; 
  3.      
  4.     public class SCookie { 
  5.  
  6.         public function SCookie() { 
  7.              
  8.         } 
  9.         static public function setCookie(cookieName:String,propertyName:String,value:Object){ 
  10.             var so:SharedObject=SharedObject.getLocal(cookieName,"/") 
  11.             so.data[propertyName]=value 
  12.             so.flush() 
  13.         } 
  14.            public static function getCookie(cookieName:String,propertyName:String ) 
  15.         {  
  16.             var so:SharedObject=SharedObject.getLocal(cookieName,"/") 
  17.             //trace("cookie size is "+so.size) 
  18.             return so.data[propertyName] 
  19.              
  20.         } 
  21.          
  22.          public static function clearCookie(clearedCookieName:String ) 
  23.         {  
  24.             var so:SharedObject=SharedObject.getLocal(clearedCookieName,"/") 
  25.             so.clear() 
  26.              
  27.         } 
  28.  
  29.     } 
  30.      

 

热门文章推荐

请稍候...

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

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