问题描述
简单的问题是,如果用户阻止将数据写入共享对象,我如何在 actionscript 中检测?
Simple question is, how do i detect in actionscript if user have blocked from writing data to shared object?
sharedObj = SharedObject.getLocal("rememberme");
这个返回总是共享对象但它的大小是0,即使我阻止了共享对象.
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);
}
如果共享对象被阻止,您可以catch
错误报告,否则如果为 0,则转到 SharedObjectFlushStatus.PENDING
.
If shared object is blocked u can catch
the error report else if 0 it goes to SharedObjectFlushStatus.PENDING
.
这篇关于Flex:如何检测用户是否阻止共享对象写入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!