JSFL Bug: FLfile.write uses ANSI not UTF-8
According to the JSFL documentation, FLfile.write() is supposed to save as UTF-8.
Description
Method; writes the specified string to the specified file (as UTF-8).
However, this is not the case. On Windows, all files that are written using FLfile.write() use ANSI encoding not UTF-8. This happens even when you FLfile.read() a UTF-8 encoded text file and modify it and then save it with FLfile.write().
Why is this a problem?
First and foremost, this means that international Flash developers can't compile class files that are modified using JSFL. Ouch. If they try to write text files with FLfile.write() they will not have "special" characters saved correctly because garbage gets injected in the files wherever those characters exist. If they use JSFL to write or modify a class, Flash will not compile the class correctly until they manually change the .as file encoding to UTF-8 in a text editor that can do that.
Next, it means that garbage characters get injected into files (no matter what country) when extended characters such as © are written. Here's what I get when I modify a UTF-8 file that I read in using FLfile.read() and then save with FLfile.write(). I'm not modifying this portion of the file, but the conversion from UTF-8 to ANSI causes this.
This:
Gaia Framework for Adobe Flash ©2007-2008
Becomes this:
Gaia Framework for Adobe Flash ©2007-2008
Yuck. Anywhere that © appears, I get ©. There are other examples, but they're merely symptomatic of the underlying problem, which is JSFL is supposed to write in UTF-8 (according to the documentation), but it doesn't. Because the documentation states it's supposed to be using UTF-8, this definitely qualifies as a bug (it should use UTF-8 even if the documentation didn't say so, but I digress).
My framework is used internationally, and developers outside the US have to manually encode all scaffolded class files as UTF-8 after they are generated as ANSI, even though the original file being modified for scaffolding is UTF-8. I have had numerous reports from my international users that their scaffolded class files were ANSI not UTF-8, and, until today, I thought they had something wonky on their end, or there was something different about non-US versions of Windows. Ends up, it's a Flash bug.
Please fix this, Adobe-wan. You're our only hope.
January 1st, 2009 at 4:52 pm
Have you thought of using the FileSystem JSFL API over at Flash Guru (http://www.flashguru.co.uk/jsfl-filesystem-api)?
I'm not on a machine now with Flash and this extension installed, so I can't verify the encoding capability, but I seem to remember that you can specify the text encoding on both the read and write methods of the API.
I've used this rather than FLFile in my custom JSFL stuff several times. The runCommandLine functionality is cool as well.