Just call your next function in two places...
I don't really see the problem. If it's not important just cancel it can
call the new function, otherwise, wait for the complete event to fire and
then call it...

Ashim

The Random Lines
My online portfolio
www.therandomlines.com


2009/8/21 Alexander Farber <[email protected]>

> 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();

               > > >DO NEW CALL

>
>                                } 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

  > > > DO NEW CALL

>
>               }
>
> 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
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to