Copy link to clipboard
Copied
Hello,
I'm using URLMonitor to detect the Internet connection for my Adobe Air App. It works perfectly when testing through Flash Builder. But as soon as I test it on a release build, the event doesn't get dispatched!!
Had anyone else experienced this?
-----
[Event(name="networkStatusChanged", type="flash.events.Event")] | ||||
public class NetworkMonitor extends EventDispatcher | ||||
{ | ||||
private var urlMonitor:URLMonitor; | ||||
private var url:String; | ||||
private var _connected:Boolean; | ||||
public function NetworkMonitor(url:String = 'http://www.google.com') | ||||
{ | ||||
super(); | ||||
this.url = url; | ||||
NativeApplication.nativeApplication.addEventListener(Event.NETWORK_CHANGE, onNetwork_ChangeHandler); | ||||
} | ||||
protected function onNetwork_ChangeHandler(event:Event):void | ||||
{ | ||||
start(); | ||||
} | ||||
public function start():void | ||||
{ | ||||
urlMonitor = new URLMonitor(new URLRequest(url)); | ||||
urlMonitor.addEventListener(StatusEvent.STATUS, onNetStatus_ChangeHandler); | ||||
if(!urlMonitor.running) | ||||
urlMonitor.start(); | ||||
} | ||||
public function stop():void | ||||
{ | ||||
if(urlMonitor.running) | ||||
urlMonitor.stop(); | ||||
} | ||||
public function isConnected():Boolean | ||||
{ | ||||
return _connected; | ||||
} | ||||
private function onNetStatus_ChangeHandler(event:StatusEvent):void | ||||
{ | ||||
trace("event code " + event.code); | ||||
trace("event level " + event.level); | ||||
_connected = urlMonitor.available | ||||
dispatchEvent(new NetStatusEvent(NetStatusEvent.NETWORK_STATUS_CHANGED,urlMonitor.available)); | ||||
//stop(); | ||||
} | ||||
} |