Adobe Air - 检查互联网连接

Uli*_*Uli 3 apache-flex air actionscript-3

我正在使用Adobe Flash CS 5构建Air应用程序.我需要检查是否有可用的Internet连接.

我遇到了这个错误:

1172:无法找到定义air.net.1046:未找到类型或不是编译时常量:URLMonitor.

这是我的代码:

import air.net.*;

var monitor:URLMonitor;

function checkInternetConnection(e:Event = null):void
{
var url:URLRequest = new URLRequest("http://www.google.com");
url.method = "HEAD";
monitor = new URLMonitor(url);
monitor.pollInterval = 3000;
//
monitor.addEventListener(StatusEvent.STATUS,onConnection);
//
function onConnection(e:Event = null):void
{
trace("onConnection")
}
//
monitor.start();
trace(monitor)
} 
Run Code Online (Sandbox Code Playgroud)

缺什么?谢谢.乌利

小智 10

嗨,我已成功使用以下代码.

您只需导入:import air.net.URLMonitor;

protected function init():void
        {
            // Center main AIR app window on the screen
            nativeWindow.x = (Capabilities.screenResolutionX - nativeWindow.width) / 2;
            nativeWindow.y = (Capabilities.screenResolutionY - nativeWindow.height) / 2;
            // Detects a general change in network status
            NativeApplication.nativeApplication.addEventListener(Event.NETWORK_CHANGE,onNetworkChange);
        }

        //Checking for network connectivity
        protected function onNetworkChange(e:Event):void
        {
        //  Alert.show("Your Network State changed", "INFO");
            monitor = new URLMonitor(new URLRequest('http://www.adobe.com'));
            monitor.addEventListener(StatusEvent.STATUS, netConnectivity);
            monitor.start();
        }

        protected function netConnectivity(e:StatusEvent):void 
        {
            if(monitor.available)
            {
                Alert.show("Status change. You are connected to the internet", "INFO");
            }
            else
            {
                Alert.show("Status change. You are not connected to the internet", "INFO");
            }

            monitor.stop();
        }
Run Code Online (Sandbox Code Playgroud)


Pix*_*ant 7

你需要添加aircore.swc

转到文件 - > ActionScript设置

在"库路径"选项卡上,单击"+"图标("添加新路径"),然后单击"Flash"图标("浏览到SWC").

然后,您需要浏览到安装Flash CS5的位置,然后转到AIK2.5/frameworks/libs/air /并选择aircore.swc