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”.

protected function on_Connection(event:Event):void
{
if(event.target.available == true)
{
//Code comes here
}
}
So in 7 simple steps, we have devised a solution to check for the availability of the Internet Connection in an AIR application.
Code snippet available below,
protected function on_Connection(event:Event):void 			{ 				if(event.target.available == true) 				{


When we make use of Cold Fusion as the backend server for a Flex Application. We have to take precautions when handling variables of type Date and Integer. In particular, precaution has to be exercised when a null value is sent for the Date and Integer variables from Flex to CF.
Reason: When a null value is sent for variable of any data type from Flex, the Cold Fusion handles it differently. In particular, Cold Fusion does not believe in the concept of null and stores it as empty value i.e. If there is a variable by name “dt”. Instead of having dt = null, we will have dt = “” in CF. This creates issues when building Data intensive applications (one of the key focus area of DCD). MySQL associates the concept of nothing to “null” and not to {empty}/””. Only in the case of String does MySQL recognizes {empty}/ “” and stores it as null.
Work Around: Let us look at the following lines of code, to better understand the work around.
a) <cfquery name=”updateItem” datasource=”Test”>

UPDATE test
SET Start_Date = <CFQUERYPARAM cfsqltype=CF_SQL_TIMESTAMP  null=”#dt1#”  VALUE=”#item.Start_Date#”>
WHERE  test_id = <CFQUERYPARAM CFSQLTYPE=”CF_SQL_INTEGER” VALUE=”#item.test_ID#”>

</cfquery>

The above lines of code show a sample SQL query in CF. It shows an Update query which tries to set the value of field Start_Date, to the value existing in the variable #item.Start_Date#. In the above code I would like to draw the attention to a specific property in the CFQUERYPARAM, the property “null”.
Above we have set the property null to a variable #dt1#. This property decides if we are passing a null value to the Query or Not
b) Now let us have a look at dt1 variable. dt1 is a CF variable with a boolean value. The Boolean value for that variable is decided on the value present in item.Start_Date. If item.Start_Date is empty then dt1 is true.
<cfset var dt1 = “false”>
<cfif item.Start_Date EQ “”>
<cfset dt1 = “true”>
</cfif>

Combining a and b. We have the following algorithm:
a) Initialize a CF variable dt1 to false
b) Check if the value present in item.Start_Date = “”
c) If empty, set dt1 to true, else keep it at false
d) In the SQL query set the null property to take the value present in dt1
e) If dt1 is true, then null value is sent to database, else database gets the value in item.Start_Date

Flex applications can more often than not be divided into two broad categories:

1) Applications built around a very specific design

2) Applications built with data at the core

Flex 4 provides great new features which addresses both styles of application development. For the first set of applications, Flash builder 4 empowers the developers with a new Developer/Designer Workflow theme. For the second set of applications, Flash Builder 4 provides a new and exciting feature called Data Centric Development (DCD). DCD is a Rapid Application Development feature in Flash Builder 4 which is aimed to enable traditional web developers to quickly build Flex apps, which will connect to server side back ends like Cold Fusion, PHP, LCDS, BlazeDS, HTTPService and WebService.

I will not dwell into the intricacies of both the workflows in this post, as their already exist some amazing articles which completely cover the functionalities of the two features. The links to those articles are documented below,

Quick Links:

Developer/Designer Workflow theme:

1) Tutorials on Flash Catalyst and Flex 4

Data Centric Developement:

1) Introduction to DCD

2) Build a Master-Detail Flex-Cold Fusion application without writing a line of code

3) Building Flex and LCDS based CRUD application using Flash Builder 4

4) DCD Service Wizard – PHP service

5) DCD Service Wizard – HTTPService

6) Using WebServices with DCD

7) Building Flex and Java based CRUD application using Flash Builder 4




Follow

Get every new post delivered to your Inbox.