actionscript-3 - 弹性 : NetStatusEvent not fired by Local Shared Object. 为什么?

标签 actionscript-3 flash apache-flex

这就是我所做的:在“本地存储”对话框中,我将指针设置为“无”以允许 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正在返回 Stringflush() 的结果命令。与其寻找要触发的事件,不如查看返回值。如果是 pending然后添加您的事件监听器并检查成功/失败。

一个很好的例子:here

关于actionscript-3 - 弹性 : NetStatusEvent not fired by Local Shared Object. 为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15498512/

相关文章:

apache-flex - URLLoader.load 连接的超时时间是多少?

apache-flex - 基于 Flex/Flash 的应用程序是否容易受到 XSS 攻击?发生此类攻击的方式有哪些?

actionscript-3 - As3内存泄漏? -如何从内存中垃圾收集新的as3声音对象?

java - 转换的完成方式与多态行为的概念之间是否存在联系

apache-flex - 在 DataGrid 中使用验证器 - Flex

flash - 上传的 Flash 影片扩展到整个页面...只想显示正确比例的舞台

javascript - 如何使用客户端 javascript 模拟人类行为来玩 Flash 游戏?

actionscript-3 - 在 MovieClip ActionScript 3 中绘制 Rentangle

apache-flex - 如何仅在 AS3 中制作 Flash PreLoader?

apache-flex - 移动和桌面 AIR 之间的差异