代码之家  ›  专栏  ›  技术社区  ›  Irwin

flex是否有主电影的onclose/ononload活动?

  •  0
  • Irwin  · 技术社区  · 16 年前

    当电影关闭或卸载时,我希望释放本地连接,我应该用什么事件来执行此操作?

    2 回复  |  直到 16 年前
        1
  •  1
  •   cwallenpoole    16 年前

    我不相信有,但我认为你无论如何都可以强制关闭。

    不完全确定这会有多简单,但这里是我最好的猜测。在实例化本地连接时,请确保将其包含在客户端中(或作为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;
    
        2
  •  0
  •   Jörg Reichardt    16 年前

    我想您可以在javascript中对卸载事件作出反应,并通过外部接口调用flex应用程序中的一些清理函数。不过,对ExternalInterface没有太多的帮助,所以我不太确定。