6 Replies Latest reply on Sep 2, 2009 6:30 AM by MarionMacDonald

    Rogue comma in array

    MarionMacDonald Level 1

      Perhaps someone can spot what I'm doing wrong, please.  I'm using CS3.

       

      I have a movieclip, mcMenu, on the timeline which contains a dynamic textbox, txtMenu.   I'm using this code:

       

      var arrMenu:Array = new Array();
      arrMenu[0]="item one\n";
      arrMenu[1]="item two\n";
      arrMenu[2]="item three\n";
      arrMenu[3]="item four\n";

      for (i=1; i<4; i++) {   
      mcMenu.txtMenu.text = mcMenu.txtMenu.text+arrMenu[i];
      }

       

      When I trace the array, it appears correctly in the output window.  In the textbox, there is a comma at the start of every line except line1.

       

      The dynamic textbox is set to Multiline no wrap, although I find that results are the same with Multiline.  If I remove \n from the lines of text, it is wrapped in the textbox.   I've tried removing the \n with the following code but it still wraps:

      mcMenu.txtMenu.text = mcMenu.txtMenu.text+newline+arrMenu[i];

       

      I don't really know if the comma indicates a blank line but there are no commas in the text at all.

       

      Head starting to spin.   (not used Flash for a couple of years)

       

      Thanks

      Marion

        • 1. Re: Rogue comma in array
          Ned Murphy Adobe Community Professional & MVP

          For the code you show, except for missing the first element of the array in your textfield listing due to starting at i=1, there are no commas showing up for me.  Maybe you should show the code you are using that involves the trace command you mention.  Traces will include commas between array elements if you trace an an array as a whole.

          1 person found this helpful
          • 2. Re: Rogue comma in array
            MarionMacDonald Level 1

            Thanks Ned.

             

            I was using trace(arrMenu[i]); within the loop.  The output was correct, ie no comma but it did have a blank line between each line of text.  I'm baffled.

             

            Marion

            • 3. Re: Rogue comma in array
              Ned Murphy Adobe Community Professional & MVP

              For that trace inside the loop that would be the case.  Each trace command starts on a new line, so with the \n at the end of each array element, you are tracing the text and the new line that \n creates.

               

              line 1

               

              line 2

               

              line 3

              • 4. Re: Rogue comma in array
                MarionMacDonald Level 1

                Ned

                 

                I see what you mean.  When I use trace(arrMenu); with the loop, I do get a comma at the start of every line which is what is happening with my textbox.  So I need to remove that, but I had earlier  checked some old sample files and didn't see anything different to what I'm doing now.

                 

                Marion

                • 5. Re: Rogue comma in array
                  Ned Murphy Adobe Community Professional & MVP

                  You shouldn't be seeing the commas in the textfield unless you are not looping thru the array.  The code you showed in your first post is the proper way to display the contents of the array, assuming you want to display the array contents one line after another.  If you were to assign the complete array to the textfield, as in...

                   

                  mcMenu.txtMenu.text = arrMenu;

                   

                  then you will see the commas

                  1 person found this helpful
                  • 6. Re: Rogue comma in array
                    MarionMacDonald Level 1

                    I appreciate your help.  I copied and pasted the code into a new file and it works fine.  I still don't see anything wrong with the first file but there must be something.

                     

                    Regards

                    Marion