Update: Workaround to JSFL FLfile.write ANSI bug
Jesse Warden and I spent some time trying to figure out a workaround for the FLfile.write bug.
First, we tried opening a script document via fl.openScript(), which opens a text document in Flash as a script document. Interestingly enough, what we discovered is that this method is utterly useless. After you open the document, you cannot do anything with it. You can't read its contents, you can't modify it, you can't save it, and you can't even close it because it doesn't show up in the list of open documents (fl.documents). Very strange, indeed.
Then, Jesse noticed that the outputPanel.save() method allows you to specify what type of encoding you want to use when you save it. Ends up, this solution works great, with a little bit of tweaking. If only FLfile.write() had an option to choose encoding, we wouldn't have this issue.
Once you're done modifying the text, you convert Windows carriage returns into newlines, strip extra newlines off the end of the text, clear the output panel, trace the text to it, save it with UTF-8, and then clear the output panel again. This happens so fast you never see it in the output panel.
function saveTextViaOutput(filePath, text)
{
text = text.split("\r\n").join("\n");
while (text.charAt(text.length - 1) == "\n")
{
text = text.substring(0, text.length - 1);
}
fl.outputPanel.clear();
fl.outputPanel.trace(text);
fl.outputPanel.save(filePath, false, false);
fl.outputPanel.clear();
}
Posted in Bugs, Flash, JSFL, Tips/Tricks
February 3rd, 2009 at 12:02 pm
nice fix!
What would I change for OS/X..?