21 September 2011
Note: By clicking the download link for any source examples on this page, you acknowledge that you have read and agree to the Adobe AIR SDK License Agreement. These files are considered Sample Code.
Note: Adobe recommends using the next version of Flash Builder for developing native extensions for Adobe AIR. Sign up now to get access to the prerelease of Flash Builder 4.6.
The NetworkInfo class is a native extension for Adobe AIR. It allows AIR application developers, from ActionScript, to get information for each network interface.
ActionScript already provides a NetworkInfo class that works on desktop and AIR for TV devices. This native extension provides a similar class so that AIR applications for iOS can also get information for each network interface.
The attached ZIP files contain:
The ActionScript library contains the NetworkInfo class. The NetworkInfo class provides the AIR application this public method and property:
public static function get networkInfo(): NetworkInfopublic function findInterfaces(): Vector.<NetworkInterface>The NetworkInfo object is a singleton. The AIR application gets the single NetworkInfo object using the static networkInfo property.
The findInterfaces() method returns a Vector of NetworkInterface objects. The NetworkInterface class is also defined in the ActionScript library. The NetworkInterface class provides these public properties:
public function get name():Stringpublic function get displayName():Stringpublic function get mtu():intpublic function get hardwareAddress():Stringpublic function get active():Booleanpublic function get addresses():Vector.<InterfaceAddress>The addresses() property returns a Vector of InterfaceAddress objects. The InterfaceAddress class is also defined in the ActionScript library. It contains these public properties:
public function get address():Stringpublic function get broadcast():Stringpublic function get prefixLength():intpublic function get ipVersion():StringNote: The public functions and properties of the classes in the NetworkInfo extension—NetworkInfo, NetworkInterface, and InterfaceAddress—correspond with the public functions and properties in the existing ActionScript classes by the same name. See NetworkInfo, NetworkInterface, and InterfaceAddress in the ActionScript 3 Reference for the Adobe Flash Platform.
To use the NetworkInfo extension, an AIR application does the following:
NetworkInfo.networkInfo .findInterfaces() method to get a list of network interfaces.For example:
var ntf:Vector.<NetworkInterface> = NetworkInfo.networkInfo.findInterfaces();
Note: Do not call new NetworkInfo() . Trying to create an instance of the NetworkInfo class in this manner throws an exception.
Then you can process each NetworkInterface object in the returned Vector. For example:
for each (var interfaceObj:NetworkInterface in ntf)
{
// Access interfaceObj.name, interfaceObj.displayName, interfaceObj.active,
// interfaceObj.hardwareAddress, and interfaceObj.mtu
for each(var address:InterfaceAddress in interfaceObj.addresses)
{
// Access address.address, address.broadcast, address.ipVersion, and address.prefixLength
}
}
Note that the prefixLength field of the InterfaceAddress class is not supported. Its value is always -1 .
The iOS native library is implemented in Objective C, using the native extension C API. The native library contains examples of these native extension C APIs:
FREInitializer()and FREFinalizer().FREContextInitializer() and FREContextFinalizer() .findInterfaces(), that uses the signature of FREFunction().FRENewObject()FRENewObjectFromBool()FRENewObjectFromInt32()FRENewObjectFromUTF8()FRESetArrayElementAt()The native function findInterfaces() calls the iOS API getifaddrs() function to get a linked list of the device's network interfaces. The function processes the elements in the list, returning an array of NetworkInterface objects to the ActionScript side of the extension.
For more information about developing native extensions for Adobe AIR, see:
For more information about using a native extension in an AIR application, see: