4 Replies Latest reply on Sep 26, 2006 1:14 AM by leewilson86

    Displaying Arrays in text boxes - URGENT!!

    leewilson86
      Hello i am wanting to display the full content of an array in a text field. However this displays a comma between each array value which i dont not want.

      How do i get rid of this?

      The follow is the code i am using:

      for (i=0; i<gNumOfQuestions; i++) {
      if (gCorrectAnswers == gUserAnswers) {
      gScore += 1;
      userResult = (i+1)+" ("+gUserAnswers +") "+"= right\n";
      textOutput.push(userResult);
      if (i>1) {
      userResult;
      }
      } else {
      userResult = (i+1)+" ("+gUserAnswers
      +") "+"= wrong\n";
      textOutput.push(userResult);
      }
      }
      results_mc.results_txt.text = textOutput.join();

      please note that my text box is held within a movie clip and the "i" has 1 added to it to giv the correct question number because of the way arrays are indexed from 0 upwards.

      The following is the output i get:

      1 (d) = wrong
      ,2 (d) = right
      ,3 (d) = right
      ,4 (d) = wrong
      ,5 (d) = wrong
      ,6 (d) = wrong
      ,7 (d) = wrong
      ,8 (d) = wrong
      ,9 (d) = wrong
      ,10 (d) = wrong
      ,11 (d) = wrong
      ,12 (d) = wrong
      ,13 (d) = right
      ,14 (d) = right
      ,15 (d) = right
      ,16 (d) = right
      ,17 (d) = wrong
      ,18 (d) = wrong
      ,19 (d) = wrong
      ,20 (d) = wrong
      ,21 (d) = wrong
      ,22 (d) = wrong
      ,23 (d) = wrong
      ,24 (d) = wrong
      ,25 (d) = wrong
      ,26 (b) = wrong
      ,27(d) = wrong
      ,28(b) = wrong

      it is the commas at the start of each line i want to lose.

      i was thinkin about using the substr function but not sure how i could use this as i dont know how to use it to delete the first char from a line.

      any help would be greatly appreciated.

      thanks

      lee


        • 1. Re: Displaying Arrays in text boxes - URGENT!!
          DazFaz Level 1
          var myReturningString:String = new String("");// Creates an empty string
          for (i = 0; i < gNumOfQuestions; i++) {
          if (gCorrectAnswers == gUserAnswers) {
          gScore += 1;
          userResult = (i + 1) + " (" + gUserAnswers + ") " + "= right\n";
          textOutput.push (userResult);
          if (i > 1) {
          userResult;
          }
          } else {
          userResult = (i + 1) + " (" + gUserAnswers + ") " + "= wrong\n";
          textOutput.push (userResult);
          }
          myReturningString += textOutput ;// on each time around will add the contents of the "i" array onto the end of the string
          }
          results_mc.results_txt.text = myReturningString;

          Quick fix not tested it but should work.
          • 2. Re: Displaying Arrays in text boxes - URGENT!!
            rich.leach
            ... i also ran into this problem and ended up creating a new var and appended the new array value to the end of it. I did this right after I added the new value to the end of my array. Not very cool, but it worked. And when I added the value to my var, I added "+" "" (2 spaces to the end of the last value) and my formatting was more controlled. Would love to find a better way to do this....


            rich

            • 3. Re: Displaying Arrays in text boxes - URGENT!!
              TimSymons Level 1
              The default delimiter for the join() method is the comma ",". To use a different one just specify it in the method call.

              The change to the following line should give you what you need:

              results_mc.results_txt.text = textOutput.join();

              change it to:

              results_mc.results_txt.text = textOutput.join(" ");

              This will use a space " " as the demliniter instead of the comma. If you don't even want the space then use an empty string, like this:

              results_mc.results_txt.text = textOutput.join("");


              Tim
              • 4. Re: Displaying Arrays in text boxes - URGENT!!
                leewilson86 Level 1
                thank you for all your replies. they all been helpful. i managed to get it working from the notes you gave.

                thanks for taking the time to help me

                cheers


                leej_W