Update: somehow this works when running flash in browser, but doesn't work if you run from IDE. You might want to try running in browser if you have the same problem.
I am making a chat application that repeatedly reads a text file from my server using Flash & Actionscript 3.0. I am opening the file with URLLoader, and it works fine at first. However after around 10 calls, the URLLoader gets stuck.
It does not give a completion event, does not give a security error, does not give a status event and does not throw an exception. It simply never fires any event at all. I even added a random value to the URL to make sure it is not some caching issue. I can detect when it gets stuck of course, but there doesn't seem to be any way to unstuck it. Even if I call close() on the URLLoader and then set it to null and create another one, it won't resume polling.
Below is the function that polls the server and gets called once every two seconds.
private function check_server() {
var url:String = "http://coworkthailand.com/say/snd/index.php?"+Math.random();
if (loader != null) {
trace("was already checking "+loader.bytesLoaded+" / "+loader.bytesTotal);
return;
}
loader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.addEventListener(Event.COMPLETE, completeHandler);
loader.addEventListener(flash.events.IOErrorEvent.IO_ERROR,
function(e:Event) { loader = null; trace("fail"); })
loader.addEventListener(flash.events.SecurityErrorEvent.SECURITY_ERROR,
function(e:Event) { loader = null; trace("security error"); })
loader.addEventListener(flash.events.HTTPStatusEvent.HTTP_STATUS,
function(e:flash.events.HTTPStatusEvent) { trace("status "+e.status); });
try {
loader.load(new URLRequest(url));
} catch (error:Error) {
trace("Unable to load requested document.");
}
}
This is not an important project, but any ideas would be much appreciated!