Monitor the availabilty of Internet Connection for an AIR application
The beauty of Adobe AIR is it enables to develop and deploy a Rich Internet Application (RIA) on the desktop. But one interesting scenario which develops when deploying a RIA on the desktop is, how will the application know, if the internet connection is currently available? How to enable run time handling of the application based on the availability of the Internet Connection?
AIR SDK answers all this by providing the developer with the URLMonitor Class. This class which is included in the ServiceMonitor.swc file, provides properties and methods to handle changes in the Internet Connection. The following steps explain, how to make efficient use of the URLMonitor class to check the availability of the Internet Connection.
Step 1: To access the properties and methods of the URLMonitor class we will have to import the air.net.URLMonitor class
import air.net.URLMonitor;
Step 2: Create an object of URLMonitor class.
private var monitor:URLMonitor;
Step 3: Create an URLRequest object and to the constructor pass the URL you wish to be requested
private var myURL:URLRequest = new URLRequest(“http://www.adobe.com”);
Step 4: On Creation Complete of the application, instantiate the URLMonitor object (monitor) by passing the URLRequest object (myURL) as one of the parameters
monitor = new URLMonitor(myURL);
Step 5: Start the URLMonitor by calling the method start()
monitor.start();
Step 6: Add an event listener where the event is of type Status. This indicates that the service status has changed.
monitor.addEventListener(StatusEvent.STATUS, on_Connection);
Step 7: Now the last and the final step. In the filter function on_Connection(event:Event), check if the Internet Connection is available by checking the boolean value of the property “available”.
Filed under: Uncategorized | Leave a Comment

No Responses Yet to “Monitor the availabilty of Internet Connection for an AIR application”