我想在电影关闭或卸载时处理我的本地连接,我应该用什么事件来处理?
答案 0 :(得分: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;
答案 1 :(得分:0)
我猜你可以对JavaScript中的unload事件作出反应,并通过ExternalInterface在flex app中调用一些清理函数。虽然没有使用ExternalInterface,所以我不太确定。