8 Replies Latest reply on Jul 2, 2007 5:31 AM by MotionMaker

    LoadVars Problem

    cds879
      What am I doing wrong here? Or is this a bug I can work around?

      var mainLoadVars:LoadVars = new LoadVars();

      mainLoadVars.onLoad = function()
      {
      inString = mainLoadVars.toString();
      trace(inString);
      }

      btnMain.onPress = function()
      {
      mainLoadVars.load(urlcut + "/lookup.php?func=lookupemp&empid=" + empid + "&nocache=" + rndNoCache()); //rndNoCache() gives a random number to prevent caching
      }

      The first time load is called, for each empid, inString comes back correctly. The second time, load is called with an already used empid, inString contains the latest data.

      For example:

      load('emp1'): returns emp1 data
      load('emp2'): returns emp2 data
      load('emp1'): returns emp2 data

      I've tested the PHP inside a web browser and the data comes back correctly every time.

      Thanks in advance for your help.
      -Craig
        • 1. Re: LoadVars Problem
          MotionMaker Level 1
          Assuming PHP script responds to values of empid correctly then the variable in Flash empid may be at fault.

          Where is empid declared?
          var emplid:String kinda of thing.
          Where is empid changed?
          • 2. Re: LoadVars Problem
            cds879 Level 1
            Thanks for your reply.

            empid comes from a text input field. When traced, the correct empid value is being passed to the load function.

            • 3. Re: LoadVars Problem
              MotionMaker Level 1
              Possibly a caching problem, errors in the concatenation expression of the load method arguments, a variable scoping issue.

              I would avoid concatenating the URL variables on the load method because there is a more structured arrangement for send and receive in Flash. See the LoadVars.sendAndLoad example in the Flash 8 help.
              • 4. Re: LoadVars Problem
                cds879 Level 1
                I've changed my code to the following, and I am having the same issue. Tracing the success variable comes back as true every call.

                var mainLoadVars:LoadVars = new LoadVars();
                var mainLoadVarsResult:LoadVars = new LoadVars();

                btnMain.onPress = function()
                {
                mainLoadVars.func="lookupemp";
                mainLoadVars.empid= empid;
                mainLoadVars.nocache = rndNoCache();
                //rndNoCache() gives a random number to prevent caching
                mainLoadVars.sendAndLoad(urlcut + "/lookup.php",mainLoadVarsResult, "POST");
                }

                mainLoadVarsResult.onLoad = function(success:Boolean)
                {
                inString = mainLoadVarsResult.toString();
                trace(inString);
                trace(success);
                }
                • 5. Re: LoadVars Problem
                  cayennecode Level 1
                  I recommend showing what's happening on the server side. You're asking for a solution and only showing half of the scenario.
                  • 6. Re: LoadVars Problem
                    MotionMaker Level 1
                    You still can add your cache killer to the query string if you want.

                    Success variable only means there was a successful communication with the server script. It does not account for the data received.

                    You have verified that using a html form to send data values returns expected values.

                    mainLoadVars.empid= empid;
                    //add trace here
                    trace ("empid:" + empid);

                    cayennecode makes a good point. If you cannot show code here, then try adding to the PHP script a write to a text file to record its data.
                    • 7. Re: LoadVars Problem
                      cds879 Level 1
                      Thank you for your help.

                      I think there is a problem with the toString() function in the LoadVars class.

                      I was just using the toString() function, to test what data was coming back. When I actually looked at the variables being returned, they were correct.
                      • 8. Re: LoadVars Problem
                        MotionMaker Level 1
                        I think for LoadVars you just need to trace the object.
                        trace(mainLoadVars);