2009-08-07 37 views

回答

1

我不相信有,但我認爲你可以強制關閉無論如何。

不完全確定這將是多麼簡單,但這裏是我最好的猜測。當實例化你的LocalConnection,一定要包括這在客戶端(或作爲AS2屬性):

function close() 
{ 
    myConnection.close(); 
} 

除此之外,我會包括這個試圖具有連接連接:

var commName:String = "MY_CONNECTION"; 
var myConnection:LocalConnection = new LocalConnection(); 

// Try to tell any open LocalConnection on this channel to close. 
// This may cause an AsyncErrorEvent, so be sure to add the appropriate 
// Error handling. 
myConnection.send(commName, "close"); 

try 
{ 
    myConnection.connect(commName); 
} 
catch(error:Error) 
{ 

    // If there is another connection already open on the same channel, 
    // that will cause an Error. I have had some luck catching that 
    // Error and then calling connect again. That said, you would be 
    // best to take precautions anyway. 
    try 
    { 
     myConnection.connect(commName); 
    } 
    catch(error:Error) 
    { 
     // Your connection cannot connect!!! 
     // DO SOMETHING!!! 
    } 
} 
myConnection.client = this; 
+0

這看起來不錯。我有興趣明確關閉連接,因爲我明白連接名稱必須是唯一的,並且如果頁面重新加載,我不希望連接浮動並導致問題。 – Irwin 2009-08-07 17:19:15

0

我想你可以對JavaScript中的unload事件作出反應,並通過ExternalInterface調用flex應用程序中的某些清理函數。雖然並沒有使用ExternalInterface,但我並不確定。