flex 监听网络连接情况

 NativeApplication.nativeApplication.addEventListener(Event.NETWORK_CHANGE, onNetworkChange);
private var monitor:URLMonitor;
public var urlStr:String;
public function onNetworkChange(event:Event):void
{
trace("网络连接发生改变");
//监视网络状态
var url:URLRequest=new URLRequest(urlStr);
url.method = "GET";
monitor = new URLMonitor(url);
monitor.addEventListener(StatusEvent.STATUS, onMonitor);
monitor.start();
}
private function onMonitor(event:Event):void
{
monitor.removeEventListener(StatusEvent.STATUS, onMonitor);
trace("连接"+monitor.available);
if(monitor.available){
//网络连接可用
//处理联网操作
setDataHandler();
papersViewId.initVu();
dispatchEvent(new NetOkEvent(NetOkEvent.NETOK_EVENT));
}
else
{
//网络连接不可用,相关处理
dispatchEvent(new NetErrorEvent(NetErrorEvent.NETERROR_EVENT));
}
}
上一篇:移动h5自适应布局


下一篇:homework-02,第二次作业——寻找矩阵最大子序列和