2013-03-19 54 views
4

这就是我所做的:在“本地存储”对话框中,我将指针设置为“无”以允许0 kB。然后我运行我的代码。我通过[允许]和[拒绝]按钮获得“本地存储”对话框。我点击[拒绝]Flex:NetStatusEvent未由本地共享对象触发。为什么?

我得到的输出是

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

不管我尝试(我试过很多),事件处理程序被从未叫上[允许]或[拒绝]按钮点击。但我想知道用户点击了哪个按钮。

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 

输出I获得[允许]

0. adding a handler to the SharedObject 
2. we are here now 

的onFlushStatus()不被调用。

+0

我想冲洗前添加一个侦听器,然后跟踪。 – Vesper 2013-03-19 11:45:18

+0

我已经在过去做过,现在又做了一次,可以肯定。但事件处理程序不被调用。 – user2186259 2013-03-19 12:03:29

+0

你有没有想过这个?我碰到了完全相同的墙,文档看起来不对。 – 2015-08-05 15:40:41

回答

0

this链接看来,so.flush返回Stringflush()命令的结果。而不是寻找一个被解雇的事件,你应该看看回报的价值。如果是pending,则添加您的事件侦听器并检查成功/失败。

一个很好的例子:here