我正在尝试使用actionscript代码构建一个swf文件。我已经下载了Flex SDK。现在我正在尝试编译.as文件。它工作正常,并使用Flex Home的bin文件夹中的以下命令编译成.swf文件。
命令:/ mxmlc /home/anshul/Downloads/HelloWorld/src/Main.as
FileName:Main.as
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
public class Main extends Sprite
{
public function Main():void
{
if (stage) init();
}
private function init(e:Event = null):void
{
var tf:TextField = new TextField();
tf.text = "Hello, world!, Lets see working or not";
addChild( tf );
}
}
}
这是一个基本的例子,工作正常。但是,如果我添加导入,
import flash.net.NetworkInfo;
然后它抛出以下错误 错误:无法找到定义flash.net:NetworkInfo。
我已经完成了各种教程,但似乎无法使其发挥作用。那么在运行命令时我是否需要包含任何库?
答案 0 :(得分:0)
在谈到您的代码之前,您应该知道flash.net.NetworkInfo
是only available for Air 2 and up。正如Adobe所说:“ ...所有桌面操作系统和AIR for TV设备都支持此功能,但并非所有移动设备都支持此功能。您可以使用NetworkInfo在运行时测试支持。 isSupported属性。有关跨多个配置文件的API支持的详细信息,请参阅AIR配置文件支持.... “,并非所有移动设备都支持,这就是为什么最好使用NetworkInfo.isSupported
来验证它是否是支持与否。
关于如何使用它,请从我在此代码中实现的Adobe.com中获取此示例:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
width="620" height="573" creationComplete="init(event)">
<fx:Script>
<![CDATA[
import flash.net.NetworkInfo;
import mx.events.FlexEvent;
protected function init(event:FlexEvent):void
{
// enable the button only if NetworkInfo is supported
btn.enabled = NetworkInfo.isSupported;
}
protected function btn_clickHandler(event:MouseEvent):void
{
// get device network interfaces
var output:String = '';
var results:Vector.<NetworkInterface> = NetworkInfo.networkInfo.findInterfaces();
for (var i:int=0; i<results.length; i++) {
output = output + "Name: " + results[i].name + "\n"
+ "DisplayName: " + results[i].displayName + "\n"
+ "MTU: " + results[i].mtu + "\n"
+ "HardwareAddr: " + results[i].hardwareAddress + "\n"
+ "Active: " + results[i].active + "\n";
for (var j:int=0; j<results[i].addresses.length; j++) {
output = output + "Addr: " + results[i].addresses[j].address + "\n"
+ "Broadcast: " + results[i].addresses[j].broadcast + "\n"
+ "PrefixLength: " + results[i].addresses[j].prefixLength + "\n"
+ "IPVersion: " + results[i].addresses[j].ipVersion + "\n";
}
output = output + "\n";
}
txt.text = output;
}
]]>
</fx:Script>
<s:Button id="btn" x="10" y="10" width="192" height="33" label="Get Network Interfaces"
click="btn_clickHandler(event)"/>
<s:TextArea id="txt" x="8" y="45" width="602" height="509"/>
</s:WindowedApplication>
答案 1 :(得分:0)
正如@akmozo所说,flash.net.NetworkInfo
是AIR类,因此您需要在构建命令中包含AIR配置:
/mxmlc ./Main.as -load-config+=$FLEX_HOME/frameworks/air-config.xml