ActionScript ExternalInterface, jQuery, Web Service

I'm having some problems with calling a javascript function which calls a web service.

I am trying to get a return value from a javascript function, but its not working out.

I suspect the problem is that, when I call the js function it calls the webservice and there is a delay. So the actionscript carrys on without waiting for the result.

So when I do: StateTextBox.text = String(retData); - it appears as undefined. The web service carrys out its functionality just fine and the database is updated as it should be.

Is there a way I can make the flash ( wait for the result ? All help would be greatly appreciated - thanks.

The code:


CompletedButton.onRelease = function(){ UpdateGame(3); }

function UpdateGame(gameState) {

 var DBSaveSuccess:Boolean;
 if (ExternalInterface.available) {

   var retData:Object = retData ="GameUpdate", "param1", "param1", gameState);

   StateTextBox.text = String(retData);

   if(Boolean(retData)) {

      ResultTextBox.text = "saved successfully";
   else {
      ResultTextBox.text = "error saving, please contact";



function GameUpdate(svt, gg, st) {
    var webMethod = '';
    var parameters = "{'svt':'" + svt + "','gg':'" + gg + "','st':'" + st + "'}"

        type: "POST",
        url: webMethod,
        data: parameters,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {

            return msg.d;

        error: function(e) {
            return false;


Open in new window

Who is Participating?
no.  you can use "synchronous" ajax instead, and not use success listeners.  otherwise, you'll need to send the data from javascript back to flash in your success/error handlers, and move the reaction to the return to another function that's called from there (with an addCallback invocation).
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.