简单的问题是,如果用户阻止将数据写入共享对象,我如何在actionscript中检测到?
sharedObj = SharedObject.getLocal("rememberme");
这个返回始终是共享对象,但它的大小为0,即使我已阻止共享对象.
当我试图将数据保存到共享对象并刷新它时,它会抛出一个错误,因为写入被阻止.那么检查写入共享对象是否被禁用的正确方法是什么?
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); }
如果共享对象被阻止,你可以捕获错误报告,如果为0,它将转到SharedObjectFlushStatus.PENDING.