I am trying to build a swf file using actionscript code. I have downloaded Flex SDK. Now I am trying to compile .as file. It works fine and compiles into .swf file using the following command from the bin folder of Flex Home. .
Command: /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 );
}
}
}
This is a basic example and works fine. But if I add a import,
import flash.net.NetworkInfo;
then it throws the following error Error: Definition flash.net:NetworkInfo could not be found.
I have gone through various tutorials but can't seem to make it work. So do I need to include any library while running the command?
Before speaking about your code, you should know that
flash.net.NetworkInfois only available for Air 2 and up. And as Adobe said about it : "... This feature is supported on all desktop operating systems and AIR for TV devices, but is not supported on all mobile devices. You can test for support at run time using the NetworkInfo.isSupported property. See AIR Profile Support for more information regarding API support across multiple profiles. ...", it is not supported on all mobile devices, that's why It's better to useNetworkInfo.isSupportedto verify if it's supported or not.For how to use it, take this example from Adobe.com which I have implemented in this code :