Calendar

August 2008
M T W T F S S
« Jul    
 123
45678910
11121314151617
18192021222324
25262728293031

Tag Cloud

Categories

Archives

Highest Rated

Most Viewed

Recent Posts

Recent Comments

ConnectionManager

Many AIR applications require Internet access. The problem is that since the application is launched from the desktop, an Internet connection can not be assumed. I have created a ConnectionManager that will handle all that is involved in testing for a connection.

Basic sample initializing the ConnectionManager:

  1. private var cm:ConnectionManager = new ConnectionManager();

The constructor of the ConnectionManager class can also accept up to four optional arguments.

Constructor arguments
showMessage:Boolean - if true, the user will be alerted when a connection failure occurs. defaults to true
connectionURL:String - the URL used to test for an Internet connection. defaults to http://www.google.com
message:String - the message that will be displayed to the user when an Internet connection test fails. defaults to “This application requires\nan Internet connection”
alertType:String - the type of alert, can be either “popup” which will display a mx.controls.Alert window or “toast” which will utilize the AlertWindow component preset to be a critical alert. defaults to popup

properties
isConnected - bindable property which holds the current connection status

The first example uses the ConnectionManager with all of the default values. Upon load of the application, the ConnectionManager will attempt to connect to http://www.google.com and alert the user with a popup alert if a connection failure occurs. The isConnection property is also being shown.

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
  3.     layout="absolute">
  4.     <mx:Script>
  5.         <![CDATA[
  6.             import com.everythingflex.air.managers.ConnectionManager;
  7.             [Bindable]
  8.             private var cm:ConnectionManager = new ConnectionManager();
  9.  
  10.         ]]>
  11.     </mx:Script>
  12.     <mx:Label text="Connection Status: {cm.isConnected}"
  13.         fontSize="20"
  14.         horizontalCenter="0"
  15.         verticalCenter="0"/>
  16. </mx:WindowedApplication>

eflex006.jpg

The second example customizes the ConnectionManager by defining a connectionURL, message, and also setting the alertType to toast. Upon launch of the application, the ConnectionManager will attempt to connect to http://www.adobe.com and show the message “Please check your Internet connection” in an AlertWindow when a connection failure occurs. The isConnection property is also being shown.

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
  3.     layout="absolute">
  4.     <mx:Script>
  5.         <![CDATA[
  6.             import com.everythingflex.air.managers.ConnectionManager;
  7.  
  8.             [Bindable]
  9.             private var cm:ConnectionManager = new ConnectionManager(true,
  10.                                             "http://adobe.com",
  11.                                             "Please check your Internet connection",
  12.                                             "toast");
  13.         ]]>
  14.     </mx:Script>
  15.     <mx:Label text="Connection Status: {cm.isConnected}"
  16.         fontSize="20"
  17.         horizontalCenter="0"
  18.         verticalCenter="0"/>
  19. </mx:WindowedApplication>

eflex007.jpg

Share/Save/Bookmark