Use an AsyncToken to "tag" the requests using the data property. When a result comes in check the AsyncToken data property to see which one has come in.
--- In flexcoders@yahoogroups.com, "txakin" <txakin@...> wrote: > > Hi all, I'm having some problems with the asynchronous in Flex using > RemoteObject to communicate with the Java side to get some information. > > > * First of all, let me explain what i'm doing: > I have developed a search component to allow the user to find stored > documents by name, content or both in some folders. The component has 2 > panels: > > > > 1. Filter: The properties to filter are a keyword and a list of > folders > > 2. Result: Per each folder selected by the user, will display a > datagrid with the documents stored in. > When the user fill the filter and click the Search button, automatically > i send one request to the Java side per each selected folder (if the > user has selected 3 folders, will send 3 requests to the server using > RemoteObject) > > I'm retrieving 3 ResultEvents, but in randomly order, and sometimes the > result of the search are not correct because of this. The result of each > responses is the dataprovider of the different DataGrids. > > Here i put some of my code (in my example, this delegate class will be > instantiated3 times, one per selected folder) > > public class SearchDelegate { > public var remoteObject:RemoteObject = new RemoteObject(); > > public function findDocuments(urlEndpoint:String, keyword:String, > folder:String):void { > try { > remoteObject.endpoint = urlEndpoint; > remoteObject.destination = "searchService"; > remoteObject.addEventListener(ResultEvent.RESULT, > onFindDocumentsSuccess); > remoteObject.findBasic(keyword, folder); > } catch (error:Error) { > > ErrorMgr.getInstance().raiseError(ErrorMgr.APPLICATION_ERROR, error); > } > } > > public function onFindDocumentsSuccess(event:ResultEvent):void { > remoteObject.removeEventListener(ResultEvent.RESULT, > onFindDocumentsSuccess); > var documents:ArrayCollection = event.result; > dispatcher.dispatchEvent(new SuccessEvent(ticket, > SuccessEvent.SUCCESS, false, true, documents)); > } > } > > * My question is: How can i solved this problem? Is any way to match > the different requests with the real responses. In my case looks like > the responses are overwritten between them (for example: i should have 3 > different results, but in many cases i have only 2 results, because one > response has overwritten one of the others). I know i can do it > synchronous, but in my case i want only in ASYNCHRONOUS way > * The other things about my program are working correctly, please > only focus in the asynchronous problem. > > Thanks so much in advanced for your help. >