1.

How Do I Make Synchronous Data Calls In Actionscript?

Answer»

You 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:

  • Create a function to handle the data return, like onResult().
  • In the HTTPService tag, put this function name in the result property and pass "event" in too.
  • 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()

  • 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);

You 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:

//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()

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);



Discussion

No Comment Found