A journal that focuses on Flash Platform development, and a little bit about what I am up to on any given day.

Thursday, June 23, 2005

FLfile.write()"`\n" stripped

It seems to me that the traditional "\n" does not work with the FLfile.write method properly.

I was working on a little extension, and I would be passing String data up from a SWF using MMExecute(). IN JSFL, when i did a few alert or traces to check the string, eveything seemed fine, but when written to disk, all line breaks were removed.

For this extenion it was crucial that I have the line breaks, so I had to keep trying to figure out the issue. I determined that 100% FLFile was stripping them out. If i write the string to a file using the fl.ouputPanel.save(), they were in there.

So at the end of the day I just ended up doing a character code output and comparing the edifference between a file that was properly written vs one that was stripped. The difference was the missing char 10.

So instead of using newline(in AS) or \n in my string generation, I used this instead String.fromCharCode(13,10). Pretty simple, but it is annoying when documented examples of using this functionality fail, making you search through your own code trying to find the issue. A note should be made in the official documentation for FLfile.write().

3 Comments:

Anonymous Anonymous said...

Bumped in to this problem yesterday, thanks for the solution.

/Ted

12:46 AM

 
Anonymous Anonymous said...

I hit this too, with no warning of it on the Macromedia site. I couldn't believe Flash has such a bug. It's like they don't want you to make tools with it.

2:26 PM

 
Anonymous Anonymous said...

I found the clue. FLfile.write uses ANSI not UTF-8. So
In UNIX, '\n' in Windows, '\r\n' and in Mac, '\r' is put at the end of each line.

Thats why \n doesnt work in windows, but this works:

FLfile.write(filePath, "A line with linebreak.\r\n", "append");

2:28 AM

 

Post a Comment

<< Home