cili
cili

Reputation: 1067

Flex4: Using httpService in consecutive function calls

I have this button:

<s:Button includeIn="MeniuPrincipal" label="Descarcare Date" click="downloadLmData(event)"/>

and this click event handler:

protected function downloadLmData(event:MouseEvent):void
{
    downloadData('competenta', 'competente');
    downloadData('localitate', 'localitati');
}

the downloadData function looks like this:

private function downloadData(item:String, items:String):void 
{
    try {
        var colVar:String   = 'col' + cappitalize(items);

        this.status = "Descarcare date in curs...";

        this[colVar] = null;

        var service:HTTPService = new HTTPService();
        service.url = serverUrl + items + '/xml';
        service.resultFormat = "xml";
        service.method = "GET";
        service.addEventListener(ResultEvent.RESULT, addArguments(downloadDataComplete, [item, items]));
        service.send();
    } catch (error:Error) {
        errorHandler.defaultErrorHandler(error);
    }
}

The problem is, all calls are ignored, except for the first one. Is there any "queuing" mechanism which would allow all calls to be made?

Thank you.

Upvotes: 1

Views: 485

Answers (2)

zawhtut
zawhtut

Reputation: 8561

I will rather use observer pattern. The easiest way.

Upvotes: 0

Florian F
Florian F

Reputation: 8875

You need to chain your asynchronous calls. See these 2 blog posts for implementations :

http://kuwamoto.org/2006/05/16/dealing-with-asynchronous-events-part-1/

http://kuwamoto.org/2006/05/16/dealing-with-asynchronous-events-part-2/

Upvotes: 1

Related Questions