Using
International Characters
         by ptolemy

Ever tried importing text from an external file that contained international characters just to find that when testing your SWF, the accents and special characters didn't render properly or even at all? Well, for those of you who have, I feel your frustration. But there is no longer any need to fear as I have discovered a simple yet effective solution to this plague!

Format and Encoding of the External File
Formatting rules of a file containing variables with international characters are more strict than usual. This may seem a little strange but things will make sense later when I show you how to import the file into your SWF.

The first thing to know is that your file must begin with the following line of code:

//!-- UTF-8


n.b.: It is important to conserve all spaces as demonstrated

The second thing is to make sure your variables are properly declared. Unlike a file without international characters, the code

myvar = j'étire mes jambes

will have your SWF complaining that you have a syntax error. The reason for this is that we will make use of the #include function to import our variables. Because #include parses syntax-sensitive code, we must format our file like so:

myvar = "j'étire mes jambes";

It makes sense to do things this way and in fact, I prefer declaring variables this way - it just makes things cleaner.
 
Encoding
Unlike the norm, files containing international characters must be saved using UTF-8 encoding. I know for a fact that this can be done with Notepad but I'm confident that any text editor can do this as well. To save a file with UTF-8 encoding in Notepad, simply select Save-as and change the Encoding-type to UTF-8. That's it.


So to recap on formatting, here's how a 'well-formed' text file would look like:

//!-- UTF-8
myvar = "j'étire mes jambes";


Importing your International Text file into Your SWF
I am assuming that you already know how to properly setup a dynamic textfield to recieve external data so if you are unsure about this, take a look in the forums and you will surely find an answer.

Now this couldn't be easier. Instead of using the usual loadVariables() function, we will use the #include command. Let's say the file that contained the text we wanted in our dynamic textfield was located in the file c:/temp/test.txt. We would then put the following line in the movie clip (or _root) where the textfield existed:

#include "c:/temp/test.txt"

n.b.: I intentionally omitted the semi-colon from the end of the line. Flash will complain that you have a malformed #include statement if you decide to do otherwise.


The Easier Method
According to Macromedia,

System.useCodePage=true; 

will ensure that all international characters will be properly rendered. I tried this with MX and it works fine. Go ahead and read how to do it the long way below but now that I know this method, I'm sticking with it!


And that's it. Simple huh? I know how much frustration this caused me and am just glad now to have a solution. I hope this was as relieving to me as it was to you.

Cheers,
ptolemy

  




SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple.