2013-03-19 55 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