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 />

Network interfaces<br />

Adobe AIR 2 and later<br />

You can use the NetworkInfo object to discover the hardware and software network interfaces available to your<br />

application. The NetworkInfo object is a singleton object, you do not need to create one. Instead, use the static class<br />

property, networkInfo, to access the single NetworkInfo object. The NetworkInfo object also dispatches a<br />

networkChange ev<strong>en</strong>t wh<strong>en</strong> one of the available interfaces change.<br />

Call the findInterfaces() method to get a list of NetworkInterface objects. Each NetworkInterface object in the list<br />

describes one of the available interfaces. The NetworkInterface object provides such information as the IP address,<br />

hardware address, maximum transmission unit, and whether the interface is active.<br />

The following code example traces the NetworkInterface properties of each interface on the cli<strong>en</strong>t computer:<br />

package {<br />

import flash.display.Sprite;<br />

import flash.net.InterfaceAddress;<br />

import flash.net.NetworkInfo;<br />

import flash.net.NetworkInterface;<br />

public class NetworkInformationExample ext<strong>en</strong>ds Sprite<br />

{<br />

public function NetworkInformationExample()<br />

{<br />

var networkInfo:NetworkInfo = NetworkInfo.networkInfo;<br />

var interfaces:Vector. = networkInfo.findInterfaces();<br />

}<br />

}<br />

}<br />

if( interfaces != null )<br />

{<br />

trace( "Interface count: " + interfaces.l<strong>en</strong>gth );<br />

for each ( var interfaceObj:NetworkInterface in interfaces )<br />

{<br />

trace( "\nname: " + interfaceObj.name );<br />

trace( "display name: " + interfaceObj.displayName );<br />

trace( "mtu: " + interfaceObj.mtu );<br />

trace( "active?: " + interfaceObj.active );<br />

trace( "par<strong>en</strong>t interface: " + interfaceObj.par<strong>en</strong>t );<br />

trace( "hardware address: " + interfaceObj.hardwareAddress );<br />

if( interfaceObj.subInterfaces != null )<br />

{<br />

trace( "# subinterfaces: " + interfaceObj.subInterfaces.l<strong>en</strong>gth );<br />

}<br />

trace("# addresses: " + interfaceObj.addresses.l<strong>en</strong>gth );<br />

for each ( var address:InterfaceAddress in interfaceObj.addresses )<br />

{<br />

trace( " type: " + address.ipVersion );<br />

trace( " address: " + address.address );<br />

trace( " broadcast: " + address.broadcast );<br />

trace( " prefix l<strong>en</strong>gth: " + address.prefixL<strong>en</strong>gth );<br />

}<br />

}<br />

}<br />

Last updated 6/6/2012<br />

790

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

Saved successfully!

Ooh no, something went wrong!