5 Replies Latest reply on Oct 12, 2007 5:54 AM by Greg Dove

    LoadVars Problem

    shibili
      I don't know whether I have missed some of the "actionscript 101" points, but this is my question.

      I have a function which have a return value. And it gets that value from a loadvars object. I want the function to wait until the loadvars finish loading data since I cannot have the return statement in LoadVars object onLoad.

      In my experiments, the function returns data even before the loadvars load the data. How will I avoid this?

      Please see what I have done so far...

        • 1. Re: LoadVars Problem
          Greg Dove Level 4
          That's normal behaviour.

          You cannot have a function return the value of a loadVars load like that. Flash doesn't wait for loading to happen before executing further code. So return resultString will probably return undefined.
          If you really want to put it inside a function you could do it like this I guess:
          • 2. Re: LoadVars Problem
            shibili Level 1
            What I want to do is running a for loop and loading data each time. This cannot be done in such a stage. Is there an event fired, when the data finished loading, a status change?

            Where can I have a look at the LoadVariables class?
            • 3. Re: LoadVars Problem
              Greg Dove Level 4
              A for loop doesn't really make sense. It needs to be event based.

              If you want to repeatedly load data from the same php script you would use LoadVars also. The onLoad event handler gives you the values after each load - they are only available after it has run and you should only consider making another request to the same script sometime after this point. You can do something with the values and then use setTimeout to trigger the next load request if you want a polling behaviour. You could use a variable to count the number of loads and do something other than the setTimeout if you wanted it to repeat only a set number of times.

              • 4. Re: LoadVars Problem
                shibili Level 1
                Thanks a lot for your help. I think setTimeout / setInterval combined with the test function you mentioned in the last post will solve my problem. I am going to try that out. Will post the results.
                • 5. Re: LoadVars Problem
                  Greg Dove Level 4
                  No problems. setTimeout is the one you really want. You only want to trigger a delayed call once after each onLoad "event". If you use setInterval it could end up running more than once before a subsequent onLoad occurs - so your 'loop' is just onLoad establishing a setTimeout for the next load request... it will keep doing that unless you you tell it to stop and there's no risk of the requests piling up in between.