views:

522

answers:

3

Hi Experts,

Is it possible to make httpService Requests synchronous in Flex?

if yes pls tell me how to do this.

It was asked to me in an interview.

Thanks

+3  A: 

It's not possible.

Gregor Kiddie
+1  A: 

It's not possible.

mazgalici
A: 

Well hang on, I mean it depends - you couldn't do it in a functional way, but if we're talking strictly theoretical then you could hack something like this:

var returned:Boolean = false;

function syncService():void {
     httpService.addEventListener(Event.COMPLETE, completeHandler);
     httpService.send();

     while (!returned) {}

     return;
}

function completeHandler(e:Event):void {
     returned = true;
}

I'd never use that in production and it might not even work. It's just asking for time-out errors etc - but in theory that should do it, right?

Myk
That will not work. ActionScript runs in a single thread, and it will just get stuck in your while loop, never calling the completeHandler, and never drawing to the screen again.
joshtynjala