Hey everyone,
I have a number of timers that I use to refresh data from our server using urlloaders to retrieve xml files.
This works perfectly until the pc running the flash file has a temporary dissconnect from the network. From that point forward, the urlloaders will always throw an IO_ERROR, even after the connection has been restablished.
I want to be able to cleanly wait for the network issue to resolve itself, and then continue with the normal timer urlloading.
I wrote the following in an attempt to suspend normal timed urlloaders until the network connection is restored:
// network monitor
var networkMonitorXMLLoader:URLLoader = new URLLoader();
networkMonitorXMLLoader.addEventListener(Event.COMPLETE, networkMonitorXMLLLoaded);
networkMonitorXMLLoader.addEventListener(IOErrorEvent.IO_ERROR, networkMonitorXMLLoaderErrorHandler);
var networkMonitorTMR:Timer = new Timer(10000,0);
networkMonitorTMR.addEventListener(TimerEvent.TIMER, checkNetwork);
networkMonitorTMR.start();
function checkNetwork(e:Event = null):void
{
networkMonitorXMLLoader.load(new URLRequest(\\server\share\file.xml));
}
function networkMonitorXMLLoaderErrorHandler(e:Event = null) :void
{
trace("Off");
}
function networkMonitorXMLLLoaded(e:Event = null) :void
{
trace("On");
}
The trouble is that this also falls prey to the same issue it was trying to fix. You can see this for yourself by running the above code, changing the path to a file that exists on your network, and then watching the outputs on the console. It will say 'on' approximately once every 10 seconds... next unplug your ethernet cable. It will switch to repeating 'off'. Then plug your ethernet cable back in. It will continue saying 'off' until you stop it, even after the connection has been reestablished.
Oddly enough, this is only an issue for network files. If I do the same thing but wiht a website instead, it works as it is supposed to... How do I fix this?
Thanks!
- Scott
when you get an error, ready your previous urlloader for gc, create a new urlloader and re-add those listeners.