[AS3]AS处理Cookie的类实例
[AS3]AS处理Cookie的类实例
- package hs.framework.net.so
- {
- public interface ISoAction
- {
- public function ISoAction();
- function getData(param1:String=null):Object;
- function setData(param1:Object, param2:String=null):void;
- }
- }
- package hs.framework.net.so
- {
- import flash.net.SharedObject;
- import flash.utils.*;
- import hsBase.log.*;
- public class AbstractSoAction extends Object implements ISoAction
- {
- /**共享key*/
- public static var sharedkey:String="bjl"
- public function AbstractSoAction()
- {
- }
- public function getData($key:String=null):Object
- {
- throw new Error("Not implemented");
- }
- public function setData($storeData:Object, param2:String=null):void
- {
- throw new Error("Not implemented");
- }
- public static function getUserSharedObject():SharedObject
- {
- try
- {
- return SharedObject.getLocal(sharedkey,"/");
- }catch(e:Error){
- }
- return null;
- }
- public static function storeData($key:String, $storeData:Object):void
- {
- var b:ByteArray;
- var key:String=$key;
- var value:Object=$storeData;
- var so:SharedObject=getUserSharedObject();
- if (so)
- {
- b=new ByteArray();
- try
- {
- b.writeObject(value);
- }
- catch (err:Error)
- {
- Logger.getInstance().logError(err.message);
- }
- so.data[key]=b;
- try{
- so.flush();
- }catch(e:Error){
- }
- }
- }
- public static function fetchData($key:String):Object
- {
- var b:ByteArray;
- var data:Object;
- var key:*=$key;
- var so:SharedObject=getUserSharedObject();
- var a:* = so.data.hasOwnProperty(key);
- Debug.log(" so.data.hasOwnProperty(key):"+ a + "," + key)
- if (so && so.data.hasOwnProperty(key))
- {
- b=so.data[key] as ByteArray;
- if (b && b.bytesAvailable > 0)
- {
- try
- {
- data=b.readObject();
- }
- catch (err:Error)
- {
- Logger.getInstance().logError(err.message);
- }
- }
- // so.flush();
- return data;
- }
- else
- {
- return null;
- }
- }
- public static function removeData($key:String):void
- {
- var so:SharedObject=getUserSharedObject();
- if (so && so.data.hasOwnProperty($key))
- {
- so.data[$key]=null;
- delete so.data[$key];
- }
- }
- }
- }
- package com.upupgame.baccarat.player2.game.models.biz
- {
- import hs.framework.net.so.AbstractSoAction;
- /**
- * 用于保护新用户的配置文件</br>
- * 控制***的强度</br>
- * 40617.1
- * @author Kayer
- * */
- public class GameCalfProtectionBiz extends AbstractSoAction
- {
- private const $KEY : String = "calfConfig";
- public function GameCalfProtectionBiz()
- {
- super();
- }
- public function setCalfData(obj:Object):void
- {
- var $data:Object = getData();
- $data.calfinfo = obj;
- setData($data);
- }
- public function getCalfData():Object
- {
- var $data:Object = getData();
- if( $data != null)
- {
- return $data.calfinfo;
- }
- else
- {
- return null;
- }
- }
- private var data:Object;
- override public function getData($key:String = null):Object
- {
- if (!data)
- {
- data = fetchData($KEY);
- }
- if (!data) {
- data={"calfinfo":{}};
- }
- return data;
- }
- override public function setData($storeData:Object, param2:String=null):void
- {
- storeData($KEY, $storeData);
- }
- }
- }
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...