他们建议采用哪种方法来验证与互联网的连接?我已经尝试使用URLRequest或只是ping通,但未成功。
import air.net.URLMonitor;
private var stateNet : Boolean = true;
private var monitor : URLMonitor;
功能:
public function checkInternetConnection():Boolean{
monitor = new URLMonitor(new URLRequest('http://www.google.com/'));
monitor.addEventListener(StatusEvent.STATUS, announceStatus);
monitor.start();
if(monitor.available == true){
stateNet;
}else{
stateNet = false;
}
return stateNet;
}
public function announceStatus(e:StatusEvent):void {
trace("Status change. Current status: " + monitor.available);
}
“错误”: monitor.available始终为false