1 Reply Latest reply on Apr 20, 2006 2:40 AM by blemmo

    While loops & variables

    Soc4me3
      Hi,
      I was having troubl writing some actionscript. My objective is to check all the letters in the alphabet if the letter is a then the movie clip for letter a will be played and so on. So if someone entered bob the movie clip for b should play then the mc for o then for b again. Here is the following while loop:

      _root.bike.stop();
      total = name.length
      answer = "";
      help = "";
      i = 0;

      while(i < name.length) {
      hello = name.toUpperCase().substring(i, i + 1);
      xpos = -65 + i * 15;
      if (hello eq "A") {
      setProperty("_root.Graffiti.aLetter", _x, xpos);
      setProperty("_root.Graffiti.aLetter", _y, 31.4);
      _root.Graffiti.aLetter.play();
      answer = answer + "A";
      }
      if (hello eq "B"){
      setProperty("_root.Graffiti.bLetter", _x, xpos);
      setProperty("_root.Graffiti.bLetter", _y, 31.4);
      _root.Graffiti.bLetter.play();
      answer = answer + "B";
      }
      if (hello eq "C"){
      setProperty("_root.Graffiti.cLetter", _x, xpos);
      setProperty("_root.Graffiti.cLetter", _y, 31.4);
      _root.Graffiti.cLetter.play();
      }
      if (hello eq "D"){
      setProperty("_root.Graffiti.dLetter", _x, xpos);
      setProperty("_root.Graffiti.dLetter", _y, 31.4);
      _root.Graffiti.dLetter.play();
      }
      if (hello eq "E"){
      setProperty("_root.Graffiti.eLetter", _x, xpos);
      setProperty("_root.Graffiti.eLetter", _y, 31.4);
      _root.Graffiti.eLetter.play();
      }
      if (hello eq "F"){
      setProperty("_root.Graffiti.eLetter", _x, xpos);
      setProperty("_root.Graffiti.eLetter", _y, 31.4);
      _root.Graffiti.dLetter.play();
      }
      if (hello eq "G"){
      setProperty("_root.Graffiti.eLetter", _x, xpos);
      setProperty("_root.Graffiti.eLetter", _y, 31.4);
      _root.Graffiti.dLetter.play();
      }
      if (hello eq "H"){
      setProperty("_root.Graffiti.eLetter", _x, xpos);
      setProperty("_root.Graffiti.eLetter", _y, 31.4);
      _root.Graffiti.dLetter.play();
      }
      if (hello eq "I"){
      setProperty("_root.Graffiti.eLetter", _x, xpos);
      setProperty("_root.Graffiti.eLetter", _y, 31.4);
      _root.Graffiti.dLetter.play();
      }
      if (hello eq "J"){
      setProperty("_root.Graffiti.eLetter", _x, xpos);
      setProperty("_root.Graffiti.eLetter", _y, 31.4);
      _root.Graffiti.dLetter.play();
      }
      if (hello eq "K"){
      setProperty("_root.Graffiti.eLetter", _x, xpos);
      setProperty("_root.Graffiti.eLetter", _y, 31.4);
      _root.Graffiti.dLetter.play();
      }
      if (hello eq "L"){
      setProperty("_root.Graffiti.eLetter", _x, xpos);
      setProperty("_root.Graffiti.eLetter", _y, 31.4);
      _root.Graffiti.dLetter.play();
      }
      if (hello eq "M"){
      setProperty("_root.Graffiti.eLetter", _x, xpos);
      setProperty("_root.Graffiti.eLetter", _y, 31.4);
      _root.Graffiti.dLetter.play();
      }
      if (hello eq "N"){
      setProperty("_root.Graffiti.eLetter", _x, xpos);
      setProperty("_root.Graffiti.eLetter", _y, 31.4);
      _root.Graffiti.dLetter.play();
      }
      if (hello eq "O"){
      setProperty("_root.Graffiti.eLetter", _x, xpos);
      setProperty("_root.Graffiti.eLetter", _y, 31.4);
      _root.Graffiti.dLetter.play();
      }
      if (hello eq "P"){
      setProperty("_root.Graffiti.eLetter", _x, xpos);
      setProperty("_root.Graffiti.eLetter", _y, 31.4);
      _root.Graffiti.dLetter.play();
      }
      if (hello eq "Q"){
      setProperty("_root.Graffiti.eLetter", _x, xpos);
      setProperty("_root.Graffiti.eLetter", _y, 31.4);
      _root.Graffiti.dLetter.play();
      }
      if (hello eq "R"){
      setProperty("_root.Graffiti.eLetter", _x, xpos);
      setProperty("_root.Graffiti.eLetter", _y, 31.4);
      _root.Graffiti.dLetter.play();
      }
      if (hello eq "S"){
      setProperty("_root.Graffiti.eLetter", _x, xpos);
      setProperty("_root.Graffiti.eLetter", _y, 31.4);
      _root.Graffiti.dLetter.play();
      }
      if (hello eq "T"){
      setProperty("_root.Graffiti.eLetter", _x, xpos);
      setProperty("_root.Graffiti.eLetter", _y, 31.4);
      _root.Graffiti.dLetter.play();
      }
      if (hello eq "U"){
      setProperty("_root.Graffiti.eLetter", _x, xpos);
      setProperty("_root.Graffiti.eLetter", _y, 31.4);
      _root.Graffiti.dLetter.play();
      }
      if (hello eq "V"){
      setProperty("_root.Graffiti.eLetter", _x, xpos);
      setProperty("_root.Graffiti.eLetter", _y, 31.4);
      _root.Graffiti.dLetter.play();
      }
      if (hello eq "W"){
      setProperty("_root.Graffiti.eLetter", _x, xpos);
      setProperty("_root.Graffiti.eLetter", _y, 31.4);
      _root.Graffiti.dLetter.play();
      }
      if (hello eq "X"){
      setProperty("_root.Graffiti.eLetter", _x, xpos);
      setProperty("_root.Graffiti.eLetter", _y, 31.4);
      _root.Graffiti.dLetter.play();
      }
      if (hello eq "Y"){
      setProperty("_root.Graffiti.yLetter", _x, xpos);
      setProperty("_root.Graffiti.yLetter", _y, 31.4);
      _root.Graffiti.yLetter.play();
      }
      if (hello eq "Z"){
      setProperty("_root.Graffiti.eLetter", _x, xpos);
      setProperty("_root.Graffiti.eLetter", _y, 31.4);
      _root.Graffiti.dLetter.play();
      }
      }
      stop();

      As you can see I never increase the value of i. This is because I need the "i++;" code in each letter movie clip. So in a frame in the movie clip for a will read "i++;". If anyone understands what I'm trying to ask I would appreciate some help. Sorry for it sounding confusing.
        • 1. While loops &amp; variables
          blemmo Level 1
          Hello,

          I'd recommend writing a function that gets the actual 'i' as parameter and can be called from inside the letter movies. A while loop isn't a good choice here. Something like in the attached code. I also changed the code so it doesn't need 26 'if's and doesn't contain the depreceated 'eq'. Hope it helps.

          cheers,
          blemmo