1 NativeApplication.nativeApplication.addEventListener(Event.NETWORK_CHANGE, onNetworkChange);
2 private var monitor:URLMonitor;
3 public var urlStr:String;
4 public function onNetworkChange(event:Event):void
5 {
6 trace("网络连接发生改变");
7 //监视网络状态
8 var url:URLRequest=new URLRequest(urlStr);
9 url.method = "GET";
10 monitor = new URLMonitor(url);
11 monitor.addEventListener(StatusEvent.STATUS, onMonitor);
12 monitor.start();
13 }
14 private function onMonitor(event:Event):void
15 {
16 monitor.removeEventListener(StatusEvent.STATUS, onMonitor);
17 trace("连接"+monitor.available);
18 if(monitor.available){
19 //网络连接可用
20 //处理联网操作
21 setDataHandler();
22 papersViewId.initVu();
23 dispatchEvent(new NetOkEvent(NetOkEvent.NETOK_EVENT));
24 }
25 else
26 {
27 //网络连接不可用,相关处理
28 dispatchEvent(new NetErrorEvent(NetErrorEvent.NETERROR_EVENT));
29 }
30 }