Escape Characters Confusion

Today I ran into a problem about character encoding. I saved text in a self developed flash desktop application in an external XML file. The text was escaped using the escape-function of Flash.
Another application had to load the text from the XML file and the special characters were broken although I unescaped the text.
What was the problem? After a bit of research and comparison of the encoding I saw that the first application which saved the text used “System.useCodepage = true”.
The difference is that with using the codepage the text is saved in the traditional codepage of the operating system and without in Unicode:

var str:String = “Sönke”;
(I had to remove this line from the syntax highlighted part because iG:Syntax Hiliter does not like my “ö”, too!)
[as]trace(escape(str));// output: S%C3%B6nke (Unicode)
System.useCodepage = true;
trace(escape(str));// output: S%F6nke[/as]

The recommendation in the Flash docs is to not use the codepage to “ensure that users on all platforms can view external text files used in your SWF files […]”.
I switched my apps to not use the codepage. Additional I had to encode other external files which I use in the application to be encoded in UTF-8 or Unicode.

Conclusion: Never use “System.useCodepage = true”. I am aware of the fact that this is known and now I agree 😉

Comments are closed.