13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Basics of networking and communication<br />

import air.net.URLMonitor;<br />

import flash.net.URLRequest;<br />

import flash.ev<strong>en</strong>ts.StatusEv<strong>en</strong>t;<br />

var monitor:URLMonitor;<br />

monitor = new URLMonitor(new URLRequest('http://www.example.com'));<br />

monitor.addEv<strong>en</strong>tList<strong>en</strong>er(StatusEv<strong>en</strong>t.STATUS, announceStatus);<br />

monitor.start();<br />

function announceStatus(e:StatusEv<strong>en</strong>t):void {<br />

trace("Status change. Curr<strong>en</strong>t status: " + monitor.available);<br />

}<br />

Socket monitoring<br />

Adobe AIR 1.0 and later<br />

AIR applications can also use socket connections for push-model connectivity. Firewalls and network routers typically<br />

restrict network communication on unauthorized ports for security reasons. For this reason, developers must consider<br />

that users do not always have the capability to make socket connections.<br />

The following code uses an instance of the SocketMonitor class to detect connectivity changes to a socket connection.<br />

The port monitored is 6667, a common port for IRC:<br />

import air.net.ServiceMonitor;<br />

import flash.ev<strong>en</strong>ts.StatusEv<strong>en</strong>t;<br />

socketMonitor = new SocketMonitor('www.example.com',6667);<br />

socketMonitor.addEv<strong>en</strong>tList<strong>en</strong>er(StatusEv<strong>en</strong>t.STATUS, socketStatusChange);<br />

socketMonitor.start();<br />

function announceStatus(e:StatusEv<strong>en</strong>t):void {<br />

trace("Status change. Curr<strong>en</strong>t status: " + socketMonitor.available);<br />

}<br />

If the socket server requires a secure connection, you can use the SecureSocketMonitor class instead of SocketMonitor.<br />

Domain Name System (DNS) records<br />

Adobe AIR 2.0 and later<br />

You can look up DNS resource records using the DNSResolver class. DNS resource records provide information like<br />

the IP address of a domain name and the domain name of an IP address. You can look up the following types of DNS<br />

resource records:<br />

ARecord—IPv4 address for a host.<br />

AAAARecord—IPv6 address for a host.<br />

MXRecord—mail exchange record for a host.<br />

PTRRecord—host name for an IP address.<br />

SRVRecord—service record for a service.<br />

To look up a record, you pass a query string and the class object repres<strong>en</strong>ting the record type to the lookup() method<br />

of the DNSResolver object. The query string to use dep<strong>en</strong>ds on the record type:<br />

Last updated 6/6/2012<br />

793

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!