Sunday, April 4, 2010

Rogue comma in array

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%26lt;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

Rogue comma in array

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.

Rogue comma in array

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

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

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

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

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

No comments:

Post a Comment