Answers

Question and Answer:

  Home  Adobe Flex Actionscript

⟩ How do I make synchronous data calls in actionscript?

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:

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

 188 views

More Questions for you: