Solved

AS2 web call too slow

Posted on 2010-09-15
4
355 Views
Last Modified: 2013-11-11
The following code is what I had been using:
function getFlav(tp) {
  switch (tp) {
    case "71690" :
    case "72592" :
      return "bgAssets/l_1dollar_Almond.png";
    break;
    case "71749" :
    case "72602" :
      return "bgAssets/l_1dollar_PMC.png";
    break;
}

I updated to the code attached.

It worked well and the image path sent was able to place the image needed into the SWF without any delay. Here's my dilemma: Now that I am getting the value via a webservice call, it seems to take too long. The value being returned is correct, but I believe it never has enough time to actually place the graphic into the SWF. Am I missing a step? I don't want to use setInterval if possible.
function getFlav(tp) {
    var myValue:String = tp+",ModuleBackgroundPath";
    var myFlavXML = myGift.GetItemModuleVariableByCustProductID(myValue);
    myFlavXML.onResult = function(result) {
    var myFlav:XMLNode = myFlavXML.response;
    myFlav = myFlav.firstChild.firstChild.firstChild.firstChild.firstChild;
    var myFlavString = String(myFlav);
    return myFlavString;
  };
}

Open in new window

0
Comment
Question by:msukow
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 20

Accepted Solution

by:
ChristoferDutz earned 500 total points
ID: 33682713
This is a classic problem of asynchron applications.
The main problem is that in line 4 you define a function that will be called as soon as there is a result from the server. You are not actually executing it. Let me explain what is happening:

in line 3 you are propably querying a webservice and as a result of this you get a myFlavXML object (don't know what that is, as you don't have a type on it). In line 4 you tell that object to call your custom function as soon as the result is available (but it isn't yet available as this will eventually take a few seconds). After this you return nothing as the getFlav function has no return statement (your internal function does have a return value, but this is never read anywhere).

After the server has processed the reuqest and has sent back the result, the function is called and a return string is returned ... unfortunately to nowhere.

In general you cannot translate a synchronous application into an asynchronous one without major refactorings. I don't know enough about your application go give you a tip. Just have a look at this function. I hope it helps you understand what's happening (You'll get a lot of alerts, but they will help you see the order in which things happen).
function getFlav(tp) {
    var myValue:String = tp+",ModuleBackgroundPath";
    Alert.show("before ws call");
    var myFlavXML = myGift.GetItemModuleVariableByCustProductID(myValue);
    Alert.show("after ws call");
    myFlavXML.onResult = onResult;
    Alert.show("getFlav finished");
}

function onResult(result) {
    Alert.show("got ws result");
    var myFlav:XMLNode = myFlavXML.response;
    myFlav = myFlav.firstChild.firstChild.firstChild.firstChild.firstChild;
    var myFlavString = String(myFlav);
    Alert.show("result was:" + myFlavString);
}

Open in new window

0
 

Author Comment

by:msukow
ID: 33683837
I found I actually had to move some of the additional calls into the onResult to ensure the items were being loaded correctly.
0
 

Author Closing Comment

by:msukow
ID: 33683850
ChristoferDutz was correct in the breakdown of the issues. I used that to determine that I had to move some additional functions into the onResult.
0
 

Author Comment

by:msukow
ID: 33683867
Update the function to the following:
function getFlav(tp) {
      var myValue:String = tp+",ModuleBackgroundPath";
      var myFlavXML = myGift.GetItemModuleVariableByCustProductID(myValue);

      myFlavXML.onResult = function(result) {
            var myFlav:XMLNode = myFlavXML.response;
            myFlav = myFlav.firstChild.firstChild.firstChild.firstChild.firstChild;
            var myFlavString = String(myFlav);
            thisBox.createEmptyMovieClip("flavstripe",80);
            var fs_mcl:MovieClipLoader = new MovieClipLoader();
            fs_mcl.loadClip(myFlavString,workBox.flavstripe);
      };
      myFlavXML.onFault = function(fault) {
            trace("CONTROLS getFlav myFlavXML: "+fault.faultstring);
            trace("");
      };
}
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to how to record live broadcast.

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question