Hello, I have an AS3 app which continuously send HTTP requests to a server.
If there is a HTTP request in progress already and it's not important (kind of "I am alive" event) I would like to cancel it. But if the ongoing request is important, I'd like to wait its completion before I send another one. I wonder how to implement this waiting properly, since AS3 doesn't seem to provide wait() and notify() Here is my code private var request:URLRequest; private var loader:URLLoader; private var vars:URLVariables; private var notImportant:Boolean; .... loader.addEventListener(Event.COMPLETE, handleComplete); ..... private function fetch(event:Number, arg:String=null):void { // fix the caching problems in MSIE vars.mod = (new Date()).getTime(); vars.event = event; if (arg != null) vars.arg = arg; else delete vars.arg; if (notImportant) { try { loader.close(); } catch (error:StreamError) { trace(error); } } else { // XXX call wait() here? XXX } loader.load(request); } private function handleComplete(event:Event):void { ........ // XXX call notify() at the end } How could I solve this? I can't keep looping and checking some variable (like requestCompleted) because there is no sleep() function either and CPU usage would be high: private function fetch(event:Number, arg:String=null):void { ..... while (! requestCompleted) { // XXX call sleep(10) here XXX } Thank you for any suggestions Alex _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders