shareobjectutil.as

来自「用Flex实现的一个关于减肥系统的web界面,内部没有实际的业务逻辑,只是一个原」· AS 代码 · 共 63 行

AS
63
字号
package diet.util.shareObject
{
    import flash.events.MouseEvent;
    import flash.events.NetStatusEvent;
    import flash.net.SharedObject;
    import flash.net.SharedObjectFlushStatus;
    
    public class ShareObjectUtil {
        
        private var mySo:SharedObject;
        public var appName:String = "application-name";
        
        public function ShareObjectUtil() {
            //addEventListener(MouseEvent.CLICK, saveValue);
            //addEventListener(MouseEvent.CLICK, clearValue);
            
            mySo = SharedObject.getLocal(appName);
           //getDataFromShareObject();
        }
		public function getValue(name:String):Object 
		{
			var value:Object = SharedObject.getLocal(appName).data[name];
			return value;
		}
        public function saveValue(name:String,value:Object):void {
            mySo.data[name] = value;
            
            var flushStatus:String = null;
            
                flushStatus = mySo.flush(10000);
            
            if (flushStatus != null) {
                switch (flushStatus) {
                    case SharedObjectFlushStatus.PENDING:
                        //output.appendText("Requesting permission to save object...\n");
                        mySo.addEventListener(NetStatusEvent.NET_STATUS, onFlushStatus);
                        break;
                    case SharedObjectFlushStatus.FLUSHED:
                        //output.appendText("Value flushed to disk.\n");
                        break;
                }
            }
        }
        
        private function clearValue(event:MouseEvent):void {
            //output.appendText("Cleared saved value...Reload SWF and the value should be \"undefined\".\n\n");
            delete mySo.data.savedValue;
        }
        
        private function onFlushStatus(event:NetStatusEvent):void {
            //output.appendText("User closed permission dialog...\n");
            switch (event.info.code) {
                case "SharedObject.Flush.Success":
                    //output.appendText("User granted permission -- value saved.\n");
                    break;
                case "SharedObject.Flush.Failed":
                    //output.appendText("User denied permission -- value not saved.\n");
                    break;
            }
            mySo.removeEventListener(NetStatusEvent.NET_STATUS, onFlushStatus);
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?