Using URLMonitor we can check status of client net connection .
import mx.states.SetStyle;
import mx.controls.Alert;
import air.net.URLMonitor;
private var monitor:URLMonitor;
private function init():void
{
// URLRequest that the Monitor Will Check
var url:URLRequest = new URLRequest("http://www.google.com");
// Checks Only the Headers - Not the Full Page
url.method = "HEAD";
// Create the URL Monitor and Pass it the URLRequest
monitor = new URLMonitor(url);
// Set the Interval (in ms) - 3000 = 3 Seconds
monitor.pollInterval = 3000;
// Create the Event Listener that Will Be Fired When Connection Changes
monitor.addEventListener(StatusEvent.STATUS,on_connection);
// Start the URLMonitor
monitor.start();
}
private function on_connection(event:StatusEvent):void
{
txt_NetStatus.setStyle("fontWeight","bold");
if(monitor.available==true) // OR USED if(event.code=="Service.available")
{
txt_NetStatus.text="NET CONNECTION AVAILABLE";
txt_NetStatus.setStyle("color","green");
vb.setStyle("backgroundColor","#B0EA8F");
}
else if(monitor.available==false) // OR USED if(event.code=="Service.unavailable")
{
txt_NetStatus.text="NO NET CONNECTION FOUND";
txt_NetStatus.setStyle("color","red");
vb.setStyle("backgroundColor","#FFAF56");
}
}
Monday, June 15, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment