Solved

AS2 web call too slow

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Text To Speech Reader For Adobe Flash Pages 4 959
Adobe Flash Free Transform Tool 2 149
High definition conversion videos in YouTube 12 296
Advertising design for my own Purpose 5 92
This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
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.

763 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