gpt4 book ai didi

actionscript-3 - Adobe Air - 检查互联网连接

转载 作者:行者123 更新时间:2023-12-01 06:59:29 24 4
gpt4 key购买 nike

我正在使用 Adob​​e Flash CS 5 构建 Air 应用程序。我需要检查互联网连接是否可用。

我遇到了这个错误:

1172: Definition air.net could not be found. 1046: Type was not found or was not a compile-time constant: 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)
}

有什么不见了?
谢谢。
乌里

最佳答案

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

你只需要导入: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();
}

关于actionscript-3 - Adobe Air - 检查互联网连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9671678/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com