Adobe Integrated Runtime (AIR) for JavaScript Developers Pocket Reference

(nextflipdebug5) #1

102 | Chapter 4: AIR Mini-Cookbook


constructor takes a String that represents the URL service
endpoint to query. TheURLRequestclass also contains infor-
mation about how to query the endpoint (i.e. GET, POST),
and any additional data that should be passed to the server:


var request = air.URLRequest( "http://www.adobe.com" ) ;
var monitor = new window.runtime.air.net.URLMonitor( request );

TheURLMonitorclass will raise aStatusEvent.STATUSevent
when the network state changes. Once the event handler has
been registered, theURLMonitorinstance can be told to start
watching for network start changes:


monitor.addEventListener( air.StatusEvent.STATUS, doStatus );
monitor.start( );

After a network change has been propagated as an event, the
URLMonitor.availableproperty on the originatingURLMonitor
instance can be used to check for the presence of a connec-
tion. TheURLMonitor.availableproperty returns a Boolean
value that reflects the state of the network. As it is necessary
to query the originatingURLMonitor instance for network
availability, the object should be declared in a scope that is
accessible across the application:


<html>
<head>

<title>HTTP Monitor</title>
<script type="text/javascript" src="AIRAliases.js">
</script>
<script src="servicemonitor.swf"></script>

<script>
var monitor = null;

function doLoad( )
{
var request = new air.URLRequest( "http://www.adobe.
com" );

monitor = new window.runtime.air.net.URLMonitor( request );
monitor.addEventListener( air.StatusEvent.STATUS, doStatus );
monitor.start( );
}
Free download pdf