Why IE doesn’t drop Flash NetConnections / NetStreams and how to fix it.
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: "actionscript 3", ActionScript, bug, disconnect, flash, ie, jQuery, netconnection

June 23rd, 2009 at 6:51 am
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!!!!!!!!!!!!!!!
February 13th, 2010 at 11:03 am
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?
April 9th, 2010 at 3:23 am
[...] 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 : [...]
October 31st, 2010 at 4:30 am
Tremendous points for upload files for having myself personally get moving. I am going to keep this specific website link and return to it.
January 10th, 2011 at 3:20 am
Whats the difference between a guitar and a tuna fish?? You can tune a guitar but you can’t tuna fish ..
January 21st, 2011 at 11:31 pm
Of course, what a good internet site and informative posts, I’ll add backlink - bookmark this site? Regards,
Reader.
July 2nd, 2011 at 9:25 pm
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
July 31st, 2011 at 3:04 am
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.”
September 5th, 2011 at 10:04 pm
Like a Beginner, I am usually searching on the web for posts that can aid me. Thank you
September 21st, 2011 at 1:50 pm
Any idea how to do this with a VideoPlayer Component? Thanks!
November 25th, 2011 at 10:53 am
banking…
[...]VOKLE | the awesomest blog in the universe! » Blog Archive » Why IE doesn’t drop Flash NetConnections / NetStreams and how to fix it.[...]…
November 27th, 2011 at 11:46 am
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.[...]…