Why IE doesn’t drop Flash NetConnections / NetStreams and how to fix it.

Problem

The Adobe Flash Player ActiveX control for Internet Explorer 7 (I don’t know about IE6) will not disconnect NetConnections if the connection was made by a swf instance loaded in a tab and only that tab was closed. If IE itself is closed though the NetConnection will be dropped. This could lead to hung “ghost” connections where you won’t hear any audio, etc. but your Wowza Media Server (and maybe Flash Media Server, who knows?) will still think the client is connected.

Explanation

Laziness on the part of two large corporations.

Solution

Register a JS handler function for window.onbeforeunload that uses the Flash ExternalInterface to call a function in your swf that manually closes the NetConnection. The event “onbeforeunload” is recognized and executed by IE, Safari and Firefox before the onunload event is fired. It is apparently not handled by Opera AFAIK but that’s ok since IE is the only one that actually needs this fix.

In your ActionScript 3 code somewhere:


import flash.external.ExternalInterface;

....

private someFunction():void{

if( ExternalInterface.available ){

ExternalInterface.addCallback("disconnect", disconnect);

}

}

private function disconnect():void {

_my_net_connection1.close();

}

In your Javascript code for the page that loads your swf:


window.onbeforeunload = function(){

// pure JS

var swf = document.getElementById('mySwf');

swf.disconnect();

// jQuery 1.2.6 version

$("#mySwf")[0].disconnect();

}

The End

(image originally from visualizeus)

Tags: , , , , , , ,

12 Responses to “Why IE doesn’t drop Flash NetConnections / NetStreams and how to fix it.”

  1. baklach Says:

    ok!!!

    my Flash function passes variables to PHP which removes XML nods in XML file. It is kinde online user list for flash chat. In Flash it works great wen Log Out button pressed!!!! So when i call the function from Javascript it works but only onLoad, not “onbeforeunload”. it seems that flash can’t pass the data to PHP befor browser window closed!!!!! this is making me crazy!!!!! i cant figure it out!!!! Could You please Help me!!!!!!!!!!!!!!???????

    Thanks a lot!!!!!!!!!!!!!!!

  2. fix blue screen Says:

    Thanks for sharing this excellent post, i truly love your weblog, but i’ve some problem i dont know whether it’s my side problem or in your site? some words of the submit on your blog have charactor encoding problem, yes i use auto detecting, can u pls look into this problem a bit?

  3. On ghost users | AVChat Software Product Blog Says:

    [...] In some cases when closing a tab in IE, IE will not remove the client side swf (index.swf) from the …, thus the ping calls will be made  even tough the user has closed the tab containing the chat.  Such ghost users can only be removed by : [...]

  4. two file upload ajax Says:

    Tremendous points for upload files for having myself personally get moving. I am going to keep this specific website link and return to it.

  5. benedict Says:

    Whats the difference between a guitar and a tuna fish?? You can tune a guitar but you can’t tuna fish ..

  6. Sandy Cassman Says:

    Of course, what a good internet site and informative posts, I’ll add backlink - bookmark this site? Regards,
    Reader.

  7. Porfirio Johndrow Says:

    picture is good but you are going too fast and additionally you did not point out concerning which you necessity a static ip from your isp to do it

  8. Wilbur Niebel Says:

    I concur which if done incorrectly, backlinks can hurt your research engine rankings. Possessing to a lot of outbound links can raise a red flag with search engines, because they may feel that your site is too “spammy.”

  9. Candace Echoles Says:

    Like a Beginner, I am usually searching on the web for posts that can aid me. Thank you

  10. John Says:

    Any idea how to do this with a VideoPlayer Component? Thanks!

  11. banking Says:

    banking…

    [...]VOKLE | the awesomest blog in the universe! » Blog Archive » Why IE doesn’t drop Flash NetConnections / NetStreams and how to fix it.[...]…

  12. Classic Bass Guitar Says:

    Classic Bass Guitar…

    [...]VOKLE | the awesomest blog in the universe! » Blog Archive » Why IE doesn’t drop Flash NetConnections / NetStreams and how to fix it.[...]…

Leave a Reply