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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.