To execute Flex cleanup function when browser is closed by user

前端 未结 3 778
忘掉有多难
忘掉有多难 2021-01-14 08:01

I have a Flex client application. I need a clean up function to run in Flex when the user closes the browser. I found the following solution on the net, but it only works ha

3条回答
  •  悲哀的现实
    2021-01-14 08:40

    An alternate way to clean up the session on client side is to use JavaScript and external.interface class in as3. Here is sample code:

    JavaScript:

    function cleanUp()
    {
    
        var process;
        var swfID="customRightClick";
        if(navigator.appName.indexOf("Microsoft") != -1){
            process = window[swfID];
            }else
        {
            process = document[swfID];
        }
        process.cleanUp();
    }
    

    and in the as3 class where the clean up function is defined use this:

    import flash.external.ExternalInterface;
    
    if (ExternalInterface.available)
    {
        ExternalInterface.addCallback("cleanUp", cleanUp);
    }
    
    function cleanUp():void {// your code }
    

提交回复
热议问题