Matt Gifford aka coldfumonkeh | Consultant Developer
View Github Profile

Detecting Network Connectivity in Flex AIR applications

Jul 20, 2010

Detecting network connectivity is a crucial part of AIR application development.

If you're releasing or developing AIR applications that require an internet connection, you want to ensure that you have the connectivity before you start running your 'online code' to trap any possible errors that may occur from lack of connection or downtime.

In this brief video tutorial, I outline the basics required to set up network connectivity monitoring functionality inside of your AIR application.

To view the video, click on the video link above, or watch it directly on YouTube.


<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx=""

			// network monitoring functions
			/* **************************** */

			// import the URLMonitor class

			Set up the URL string variable for the URLRequest to check.
			In this example, let's use as we can be sure 99.99%
			of the time that it will be up and running.
			private var strURLMonitor	: String = '';
			private var	monitor			: URLMonitor;
			private var isOnline		: Boolean = false;

			This function checks the online status by attempting
			to resolve a connection to a remote address
			private function monitorConnection():void {
				monitor = new URLMonitor(
								new URLRequest(strURLMonitor)

			Declare the status from the monitorConnection function
			and set the value to the variable isOnline
			private function announceStatus(e:StatusEvent):void {
				trace("Status change. Current status: " + monitor.available);
				if(monitor.available) {
					isOnline = true;
					Inside here, you can run any functions or script
					that require network connection, as it exists.
				} else {
					isOnline = false;

			The network connection has changed.
			Run the monitorConnection function to check status
			private function onNetworkChange(event:Event):void {
				trace('network change');

			private function init():void {
					Keep an eye on network connectivity...
					Any losses, and run the onNetworkChange method
						Event.NETWORK_CHANGE, onNetworkChange);

				// run monitorConnection


	<s:Label x="10"
			 text="Online? {isOnline}"
			 fontSize="72" />


Latest Blog Posts

Jul 16, 2020
Github Actions with CommandBox and TestBox
Read More
Jul 9, 2020
Azure pipelines with CommandBox and TestBox
Read More
Dec 23, 2019
CFML content moderation detection component library
Read More