Update: Workaround to JSFL FLfile.write ANSI bug

January 2nd, 2009 by Steven Sacks

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

One Response

  1. michael

    nice fix!

    What would I change for OS/X..?

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

About Steven Sacks

I am a professional Flash developer with over 13 years of programming experience. I have consulted for high-profile agencies and companies in San Francisco, Los Angeles, Atlanta and New York, and developed numerous award-winning websites and rich internet applications for clients including Adobe, Fox Sports, FX Networks, Anheuser-Busch, GE, DirecTV, ESPN, The Weather Channel, Home Depot, and Coca-Cola.

I am the author of the open-source Gaia Framework for Adobe Flash, which dramatically reduces development time and makes developing Flash sites much easier.