Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

AS2 web call too slow

Posted on 2010-09-15
4
Medium Priority
?
364 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 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
The goal of the tutorial is to teach the user how to how to record live broadcast.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.
Suggested Courses

916 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