Adobe Flex Actionscript Question:

How do I make synchronous data calls in actionscript?

Answers:

Answer #1You cannot make synchronous calls. You must use the result event. No, you can't use a loop, setInterval, or even doLater. This paradigm is quite aggravating at first. Take a deep breath, surrender to the inevitable, resistance is futile.
There is a generic way to handle the asynchronous nature of data service calls, called ACT (Asynchronous Call Token). Search for this in the Developing Flex Applications LiveDocs for a full description.
Here it is in a nutshell. This example uses HTTPService but will be similar for RemoteObject and WebService:
1. Create a function to handle the data return, like onResult().
2. In the HTTPService tag, put this function name in the result property and pass "event" in too.
3. Invoke the call in the script:
//invokes the call to the HTTP data service
var oRequestCallbject = app.mxdsGetData.send(oRequest);
//Next, define a string to identify the call. We will use this string value in the result handler.

oRequestCall.MyQueryId = "WhateverIWanttoUseToIdentifyThisCall" ;
//Yes, you CAN set this AFTER you invoke send()
4. In the result handler, which will be called every time the data service call returns, identify what the returned data contains, as follows:
var callResponse = oEvent.call; //get the call object
//gets the value of this property you set in the call
var sQueryId = callResponse.MyQueryId; //will be "WhateverIWanttoUseToIdentifyThisCall";
trace(sQueryId);

Answer #2You can use the sQueryId value in a switch to do the correct processing. Alternatively, you can pass reference to a handler function directly.

Download Adobe Flex Actionscript PDF Read All 84 Adobe Flex Actionscript Questions
Previous QuestionNext Question
I am sending my request, and I see the data traffic in the command window, but why is the result always empty?When I have only a single record, why does not it appear in my DataGrid?