4 Replies Latest reply on May 1, 2006 12:07 PM by Hipanda

    Addition of variables

      I have used _root.loadVariables to bring in two numerical values from text files to dynamic test fields-(Labeled T1 and S1).
      I want to add these two values together and load this value in another text field on the next frame (2).
      If anyone can help, I would appreciate it.
        • 1. Re: Addition of variables
          Assuming your text file looks like 'var1=12&var2=24' (minus the single quotes obviously) you can use Number(parseFloat(target_mc.var1)+ parseFloat(target_mc.var2)) and pass the value into the textfield as usual.

          I'm sure there is a more elegant solution, but this works.
          • 2. Re: Addition of variables
            Hipanda Level 1
            Thank you for your suggestion, Neo

            I incorporated the code you gave. The textfield (var3) shows a result "NaN"
            More than likely, I have done something wrong with my scripting:

            Frame one:*******************************************************



            var3 = Number(parseFloat(target_mc.var1)+ parseFloat(target_mc.var2));



            On Frame 2 there is only a stop() call
            I have a dynamic textfield (var3)

            Hope you can help,

            Thanks again,

            • 3. Re: Addition of variables
              Bishop[Neo] Level 1
              You've got at least 3 issues happening. 1) your movie is skipping ahead to frame 2 before frame 1 is done loading the variables. 2.) calling loadVariables() without a target. and 3.) calling _root.loadVariables().

              Here's what I did. Created a new movie with 2 keyframes. On frame 3 is a textfield named var3 and 'stop();' is the only AS.
              On frame 1 I put this:
              this.createEmptyMovieClip("target_mc", this.getNextHighestDepth());
              loadVariables("params.txt", target_mc);

              function checkParamsLoaded() {
              if (target_mc.done == undefined) {
              } else {
              var3 = Number(parseFloat(target_mc.var1)+ parseFloat(target_mc.var2));
              var param_interval = setInterval(checkParamsLoaded, 100);

              My params.txt looks like this:

              This forces it to keep looking back to see if the vars have been loaded. *Then* sets the textfield. Otherwise it will never get set because it gets passed by before the loading and parsing is done.
              • 4. Re: Addition of variables
                Hipanda Level 1
                Wow, so much to learn!

                Thanks Neo, it's perfect.
                I'll take some time and try to learn from your example.
                I spent around 12 hours trying to hunt the info down today. Never would have made it without your help.