这就是我所做的:在“本地存储”对话框中,我将指针设置为“无”以允许 0 kB。然后我运行我的代码。我收到带有 [允许] 和 [拒绝] 按钮的“本地存储”对话框。我点击[拒绝]
我得到的输出是
2. we are here now
3. adding a handler to the SharedObject
注意:不调用 onFlushStatus 事件处理程序。
我重复上述内容,但现在单击 [允许]。
我得到的输出是一样的:
2. we are here now
3. adding a handler to the SharedObject
注意:不调用 onFlushStatus 事件处理程序。
我正在使用这里的代码
Flex: How to detect if user has blocked shared object from writing
无论我尝试什么(并且我尝试了很多),事件处理程序都不会在单击 [Allow] 或 [Deny] 按钮时调用。但我想知道用户点击了哪个按钮。
var so: SharedObject = null;
var flushStatus: String = null;
so = SharedObject.getLocal('mySpace');
try {
flushStatus = so.flush();
} catch (error: Error) {
trace('1. could not write SharedObject to disk');
}
trace('2. we are here now');
if (flushStatus == flash.net.SharedObjectFlushStatus.PENDING) {
trace('3. adding a handler to the SharedObject');
so.addEventListener(NetStatusEvent.NET_STATUS, onFlushStatus);
}
public function onFlushStatus(event: NetStatusEvent): void
{
trace('4. in event handler');
}
按照建议,我更改了代码并在调用 flush() 之前添加了事件监听器。然后我再次运行我的测试。不幸的是,我的 onFlushStatus() 没有被调用。
var so: SharedObject = null;
var flushStatus: String = null;
so = SharedObject.getLocal('mySpace');
trace('0. adding a handler to the SharedObject');
so.addEventListener(NetStatusEvent.NET_STATUS, onFlushStatus);
flushStatus = so.flush();
trace('2. we are here now');
public function onFlushStatus(event: NetStatusEvent): void
{
trace('4. in event handler');
}
我为 [拒绝] 得到的输出
0. adding a handler to the SharedObject
2. we are here now
我得到的输出 [允许]
0. adding a handler to the SharedObject
2. we are here now
不调用 onFlushStatus()。
最佳答案
来自 this链接似乎是 so.flush
正在返回 String
与 flush()
的结果命令。与其寻找要触发的事件,不如查看返回值。如果是 pending
然后添加您的事件监听器并检查成功/失败。
一个很好的例子:here
关于actionscript-3 - 弹性 : NetStatusEvent not fired by Local Shared Object. 为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15498512/