Solved

AS2 web call too slow

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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 …
Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to how to record live broadcast.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now