Actionscript – Loading Acute and UTF-8 Characters from XML into Dynamic Text with Flash
19th June, 2008 – 10:17 amWriting flexible applications in Flash is easy, (/me points in the direction of my XML Configuration Class) and there’s few reasons why all your text strings should not be read in at run time to allow for easy internationalization.
However, one pitfall to be aware of is trying to use Acutes and other “non-latin” characters in dynamic text fields (é, etc). I was having a problem when these characters were not only not showing up, but all characters after the acute were being truncated! Here’s my configuration XML:
<configuration>
<textValue>armén</textValue>
</configuration>
Side Note: Flash Player 9 appears to ignore the XML Encoding value specified in XML files, however it’s good practice to adhere to web standards, so make sure your XML’s encoding is set to UTF-8
The next obvious set is to ensure that you embedding all the required glyphs in your .fla file, you do this by clicking on the Embed… button for your Dynamic Textfield – make sure you embed all the Latin characters you need and then specify the acutes and other UTF-8 characters seperatley in the “include these characters:” textbox:

Now this is where the problem comes in – when I try to compile and run this flash movie, instead of getting the text armén in my textfield, I get arm with both the acute (é) and any trailing characters truncated (in some cases (as in the screen shot below), I even get some of the trailing XML… eek!)

After a bit of head scratching I finally managed to track down the problem: The XML file must be saved as UTF-8 encoding! (d’oh!) However, in tracking down the problem I also discovered another workaround using System.useCodepage. Setting this value to ‘true’ in the first frame of your actionscript will force flash to ignore the character encoding of the XML document.
Hope this saves someone some time.
3 Responses to “Actionscript – Loading Acute and UTF-8 Characters from XML into Dynamic Text with Flash”
Setting the useCodepage to true can lead to some other problems. Since flash will be using the user’s codepage, he will still see everything fine, but any and all forms he needs to fill or any other data that Flash Player needs to send anywhere else other than Flash Player itself, will be encoded with the user’s codepage.
So, for example, if u got a contact form on you flash, it’ll be sent with the user’s encoding, and therefore, can be truncated to you. (Just think of a japanese guy trying to send you an e-mail through it.)
By Filipe Cunha on Feb 5, 2009
Hi there!
Thanks for the solution, I just bought a template from the Flahoo site and couldn’t translate to spanish (we use a lot of special characters: á é í ó ú ñ, etc…) In this particular case, I saved the XML with an UTF-8 enconding, and also added the System.useCodepage = true; to the very first line of the main SWF file, despite the XML being parsed by external actionscript file.
By Elias on Nov 6, 2009
Hey,
You Rock.. You just saved my day. Wonderful.. bookmarked your site
By Bobin on Mar 23, 2010