views:

81

answers:

1

My problem, simplified: I have a dataGrid with a dataProvider "documents" A column of the datagrid has a labelFunction that gets the project_id field of the document, and returns the project name, from a bindable variable "projects"

Now, I dispatch the events to download from the server the documents and the projects, but If the documents get downloaded before the projects, then the label function gives an error (no "projects" variable)

Therefore, I must serialize the commands being executed: the getDocuments command must execute only after the getProjects command.

In the real world, though, I have dozens of resources being downloaded, and those command are not always grouped together (so I can't for example execute the second command from the onSuccess() method of the first, because not always they must be executed together..)..

I need a simple solution.. I need an idea..

A: 

If I understand you correctly, you need to serialize the replies from the server. I have done that by using AsyncToken.

The approach: Before you call the remote function, add a "token" to it. For instance, an id. The reply from the server for that particular call will then include that token. That way you can keep several calls separate and create chains of remote calls.

It's quite cool actually:

    service:RemoteObject;
    // ..      
    var call:AsyncToken = service.theMethod.send();
    call.myToken = "serialization id";

    private function onResult(event:ResultEvent):void 
    {
       // Fetch the serialization id and do something with it
       var serId:String = event.token.myToken;
    }
Martin Wickman
I should add that I haven't used Cairngorm. It may mess things up, but my approach above works with "plain old" Flex and probably in Cairngorm as well.
Martin Wickman
I don't understand it..I'm not using remote functions.. I'm using HTTPService calls to an http server that returns plain XML data (it's a REST api written in rails)Can your method still be applied?
luca