软硬度:如何检测,从写作,如果用户已阻止共享对象软硬、对象、用户

2023-09-09 21:34:26 作者:Stay(坚持)

简单的问题是,我如何检测动作,如果用户已经从数据写入共享对象受阻?

  sharedObj = SharedObject.getLocal的(了rememberMe);
 

这回始终共享对象,但它的大小为0,即使我已封锁共享对象。

当我试图将数据保存到共享对象和冲洗,它引发了我的错误,因为写作被阻止。那么,什么是正确的方式检查是否写入共享对象是残疾人?

 错误:错误#2130:无法刷新共享对象。
 
微软推出AI作文批改 爱写作 ,语法自动检查及纠正功能将在更多场景应用

解决方案

  VAR my_so:共享对象= SharedObject.getLocal的(MySpace的);
VAR flushStatus:字符串= NULL;
尝试 {
    flushStatus = my_so.flush();
}赶上(错误:错误){
    跟踪(错误...无法写入共享对象到磁盘的\ n);
}
如果(flushStatus!= NULL){
    开关(flushStatus){
        案例SharedObjectFlushStatus.PENDING:
            跟踪(请求允许保存对象... \ N);
            my_so.addEventListener(NetStatusEvent.NET_STATUS,调用onFlushStatus);
            打破;
        案例SharedObjectFlushStatus.FLUSHED:
            跟踪(刷新值到磁盘\ñ。);
            打破;
    }
}
函数调用onFlushStatus(事件:将NetStatusEvent):无效{
    跟踪(用户关闭权限对话框... \ N);
    开关(event.info。code){
        案SharedObject.Flush.Success:
            跟踪(用户授予权限 - 值存储\ñ。);
            打破;
        案SharedObject.Flush.Failed:
            跟踪(用户权限被拒绝 - 没有保存价值\ñ。);
            打破;
    }
my_so.removeEventListener(NetStatusEvent.NET_STATUS,调用onFlushStatus);
}
 

如果共享对象被阻止U可以否则,如果0它去 SharedObjectFlushStatus.PENDING 错误报告。

来源

Simple question is, how do i detect in actionscript if user have blocked from writing data to shared object?

sharedObj = SharedObject.getLocal("rememberme");

This return always shared object but it's size is 0, even I have blocked shared object.

When I'm trying to save data to shared object and flush it, it throws me an error, because writing is blocked. So what would be the right way check if writing to shared object is disabled?

Error: Error #2130: Unable to flush SharedObject.

解决方案

var my_so:SharedObject = SharedObject.getLocal("mySpace");
var flushStatus:String = null;
try {
    flushStatus = my_so.flush();
} catch (error:Error) {
    trace("Error...Could not write SharedObject to disk\n");
}
if (flushStatus != null) {
    switch (flushStatus) {
        case SharedObjectFlushStatus.PENDING :
            trace("Requesting permission to save object...\n");
            my_so.addEventListener(NetStatusEvent.NET_STATUS, onFlushStatus);
            break;
        case SharedObjectFlushStatus.FLUSHED :
            trace("Value flushed to disk.\n");
            break;
    }
}
function onFlushStatus(event:NetStatusEvent):void {
    trace("User closed permission dialog...\n");
    switch (event.info.code) {
        case "SharedObject.Flush.Success" :
            trace("User granted permission -- value saved.\n");
            break;
        case "SharedObject.Flush.Failed" :
            trace("User denied permission -- value not saved.\n");
            break;
    }
my_so.removeEventListener(NetStatusEvent.NET_STATUS, onFlushStatus);
}

If shared object is blocked u can catch the error report else if 0 it goes to SharedObjectFlushStatus.PENDING.

SOURCE