3 Replies Latest reply on Apr 28, 2006 9:45 PM by jondro

    Conditional statement variable change

    jondro Level 1
      I want a button called "next_btn" to change a variable called "pres" to whatever variable is next in the sequence. So on the first click it will change pres=vice and then the second time it is clicked it will change it to pres=vice2 and the third time pres=sec and the fourth pres=trea.

      I am sure there are many ways to do this. My first thought was an if statement where if(pres=vice) {pres=vice2;} and so on. An easier way would be a switch statement but I am not sure of the syntax. Another way would be to change the variables to numbers and do a loop so that every time the next button is clicked it adds 1 or something but again I am not sure how to write this out. Please help...this is what I have so far:

      loadVariablesNum("bio.txt", 0);
      var pres = new Array(vice, vice2, sec, trea);
      var n = 0;
      var presn;
      next_btn.onRelease = function() {
      nextImage();
      presn = pres[n];
      n++;
      if (n == pres.length) {
      n = 0;
      }
      trace(presn);
      };

      In the bio.txt document it has the following:
      &presn=blah
      &vice= blah2
      etc.

      The dynamic text box variable is set to "presn" and when first loaded it displays the blah but when you click the button blah2 does not appear. Instead it says undefined.