Solved

AS2 web call too slow

Posted on 2010-09-15
4
348 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
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

837 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