lunedì, gennaio 26, 2009

Adobe AIR: Monitoring Your Internet Connection

David Tucker has a great snippet of code on his blog on monitoring your Internet connection in Adobe AIR.

“AIR is meant to facilitate applications that work when online and offline. For example, if you developed an AIR application to manage your blog, you would want to be able to write blog posts whether you were online or offline. To accomplish this, the application would do one of two actions depending on whether it had an internet connection. If it were online, it would take your post and upload it. If it weren't online, it would store it (either in a file or in a local SQLite database).”

To make it work in Flash CS3:

Add the URL Monitor class. How, you might ask? Drag the ServiceMonitorShim component from the Components panel to the Library.

(This will be available to you if you’ve downloaded the AIR update for Flash CS3.)

 

cid:image002.png@01C945AD.633646D0

 

2. Add this import statement:

import air.net.*;

Note: if you don’t do step 1, you might get this annoying error: “1172: Definition air.net could not be found.”