0

I want to detect the network disconnection for my web app.

For AIR application it is possible, using the AIR URLMonitor. And in Flash AS3 I am using javascript's

'navigator.onLine' using ExternalInterface.

But the above code does not work always.

Do I have to write my own code to continuously check if my network connection is persistent?

Sris
  • 87
  • 2
  • 14

1 Answers1

2

You need to create an URLLoader and look for a response from your website on a timer tick.

var checkTimer:Timer = new Timer(1000);
var checkLoader:URLLoader = new URLLoader();
var checkURL:URLRequest = new URLRequest("mysite");
checkLoader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);

checkTimer.addEventListener(TimerEvent.TIMER, checkURL);
checkTimer.start();

function checkURL(e:TimerEvent):void
{
  checkLoader.load(checkURL);
}

function onIOError(e:IOErrorEvent):void
{
  //down
}

This is basically the same behaviour as URLMonitor's.

Kodiak
  • 5,978
  • 17
  • 35
  • thank you Kodiak. I works but only problem is when the connection is set I could not receive any of the Complete, or HTTPStatus or any other even that says it is connected. I searched in other places, but I think I have to rely on : IOErrorEvent, since it stops perfectly when internet is connected. – Sris Aug 30 '12 at 13:09