【发布时间】:2016-02-10 23:05:23
【问题描述】:
我尝试使用谷歌搜索,但我发现的只是 Adobe 和 Freshplanets NetworkInfo ANE 的 NetworkInfo。 NetworkInfo 由于某种原因无法正常工作,freshplanets network-info API 无法做到这一点。有没有其他方法可以完成这项任务?
我从这个使用 networkInfo 的链接下载了这个例子:[http://www.adobe.com/devnet/air/native-extensions-for-air/extensions/networkinfo.html][1]
这是上面示例中主类的代码:
/*
ADOBE 系统公司 版权所有 2011 Adobe Systems Incorporated 版权所有。
注意:Adobe 允许您根据以下规定使用、修改和分发此文件 随附的 Adobe 许可协议的条款。如果您从 Adobe 以外的源,则您对其的使用、修改或分发需要事先 Adobe 的书面许可。
*/
package
{
import com.adobe.nativeExtensions.Networkinfo.InterfaceAddress;
import com.adobe.nativeExtensions.Networkinfo.NetworkInfo;
import com.adobe.nativeExtensions.Networkinfo.NetworkInterface;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.text.TextField;
import flash.text.TextFormat;
public class NetworkInfoUsageApp extends Sprite
{
private var info:TextField;
public function NetworkInfoUsageApp()
{
super();
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
var ntf:Vector.<NetworkInterface> = NetworkInfo.networkInfo.findInterfaces();
info = makeTextField(50, 50);
for each (var interfaceObj:NetworkInterface in ntf)
{
trace("Interface Name:" + interfaceObj.name + "\n" );
trace("MTU:" + interfaceObj.mtu.toString + "\n" );
trace("Display Name of the Interface:" + interfaceObj.displayName + "\n" );
trace ("Active ?" + interfaceObj.active.toString() + "\n" );
trace("Hardware Address:" + interfaceObj.hardwareAddress + "\n");
info.appendText("Interface Name:" + interfaceObj.name + "\n" );
info.appendText("MTU:" + interfaceObj.mtu.toString() + "\n" );
info.appendText("Display Name of the Interface:" + interfaceObj.displayName + "\n" );
info.appendText("Active ?" + interfaceObj.active.toString()+ "\n");
info.appendText("Hardware Address:" + interfaceObj.hardwareAddress + "\n");
for each(var address:InterfaceAddress in interfaceObj.addresses)
{
trace("Address" + address.address + "\n");
trace("broadcast address" + address.broadcast + "\n");
trace("ipversion" + address.ipVersion + "\n")
trace("prefixlength" + address.prefixLength +"\n")
info.appendText("Address" + address.address + "\n" );
info.appendText("broadcast address" + address.broadcast + "\n" );
info.appendText("ipversion" + address.ipVersion + "\n");
info.appendText("prefixlength" + address.prefixLength +"\n" );
}
}
}
private function makeTextField(x:Number, y:Number):TextField
{
var tf:TextField = new TextField();
tf.x = x;
tf.y = y;
tf.border=true;
this.stage.addChild(tf);
tf.height = 800;
tf.width = 450;
tf.type = "input";
var tff:TextFormat=new TextFormat();
tff.size=18;
tff.color=0x0000ff;
tf.defaultTextFormat=tff;
tf.setTextFormat(tff);
tf.text="hello";
return tf;
}
}
}
当我从 Flash Pro 运行影片时,出现以下错误:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.adobe.nativeExtensions.Networkinfo::NetworkInfo/findInterfaces()[/Users/gangwar/Documents/Adobe Flash Builder 4.5/NetworkInfoActionScriptLibrary/src/com/adobe/nativeExtensions/Networkinfo/NetworkInfo.as:70]
at NetworkInfoUsageApp()[C:\Users\Dani\Desktop\wifi test\NetworkInfoUsageApp\src\NetworkInfoUsageApp.as:39]
at runtime::ContentPlayer/loadInitialContent()
at runtime::ContentPlayer/playRawContent()
at runtime::ContentPlayer/playContent()
at runtime::AppRunner/run()
at ADLAppEntry/run()
at global/runtime::ADLEntry()
当我发布 apk 并在我的设备上运行它时。什么都没有出现,只有白色。
【问题讨论】:
-
NetworkInfo 正是这样做的,你为什么不解释一下你想做什么呢。
-
您正在寻找可用 WiFi 网络的列表? ANE 可能会这样做,但您到底想做什么?
-
使用 networkInfo 给了我这个错误。无法访问空对象引用的属性或方法。
-
NetworkInfo不会那样做,你写的一些代码会那样做;显示引发该错误的代码。 -
我已经用更多细节更新了这个问题。
标签: android actionscript-3 air