AIR: Check if connected to the internet or not
Wally Kolcz
With most of my AIR apps connecting to the internet either to get or push data, having the ability to monitor the connection to the internet is vital to the success of the application. I am building an AIR app that allows my client to search images that she has on the web site from her laptop when she is at conferences. I decided to check the connectivity of the internet and have it enable or disable a 'search' button called 'search_btn'.
When the application is lauched I launch the functions below and they monitor the connection to the site constanty. If the connection is broken, the search button becomes disabled.
public function startMonitoring():void {
var monitor:URLMonitor = new URLMonitor(new URLRequest('http://www.med.umich.edu'));
monitor.addEventListener(StatusEvent.STATUS, changeStatus);
monitor.start();
}
public function changeStatus(e:Event):void {
if (e.target.available){
search_btn.enabled = true;
}else{
search_btn.enabled = false;
}
}
Posted in AIR | Flex | Flash |
1 comments
Nov 23, 2009 at 10:20 PM
I often read your blog and always find it very interesting. Thought it was about time i let you know…Keep up the great work