Method 1: Using URLMonitor and URLRequest
private var mon:URLMonitor;
private var monurl:URLRequest = new URLRequest('http://www.blogger.com');
protected function isOnInternet():Boolean
{
//to check internet connection
var isInternet:Boolean = false;
monurl.method = URLRequestMethod.HEAD;
mon = new URLMonitor(monurl);
mon.start();
mon.addEventListener(StatusEvent.STATUS, function(event:StatusEvent):void
{
if(event.code == 'Service.available')
{
//internet connection available
isInternet = true;
}
});
return isInternet;
}
Method 2: Using NetworkInfo
private function checkInternetConnection():Boolean
{
var interfaces:Vector.<NetworkInterface> = NetworkInfo.networkInfo.findInterfaces();
if(interfaces.length==0)
{
return true;
}
for(var i:uint = 0; i < interfaces.length; i++)
{
if(interfaces[i].name.toLowerCase() == "wifi" && interfaces[i].active)
{
trace("WiFi connection enabled");
return true;
}
else if(interfaces[i].name.toLowerCase() == "mobile" && interfaces[i].active)
{
trace("Mobile data connection enabled");
return true;
}
}
return false;
}
private var mon:URLMonitor;
private var monurl:URLRequest = new URLRequest('http://www.blogger.com');
protected function isOnInternet():Boolean
{
//to check internet connection
var isInternet:Boolean = false;
monurl.method = URLRequestMethod.HEAD;
mon = new URLMonitor(monurl);
mon.start();
mon.addEventListener(StatusEvent.STATUS, function(event:StatusEvent):void
{
if(event.code == 'Service.available')
{
//internet connection available
isInternet = true;
}
});
return isInternet;
}
Method 2: Using NetworkInfo
private function checkInternetConnection():Boolean
{
var interfaces:Vector.<NetworkInterface> = NetworkInfo.networkInfo.findInterfaces();
if(interfaces.length==0)
{
return true;
}
for(var i:uint = 0; i < interfaces.length; i++)
{
if(interfaces[i].name.toLowerCase() == "wifi" && interfaces[i].active)
{
trace("WiFi connection enabled");
return true;
}
else if(interfaces[i].name.toLowerCase() == "mobile" && interfaces[i].active)
{
trace("Mobile data connection enabled");
return true;
}
}
return false;
}
No comments:
Post a Comment