A tutorial on using international characters in dynamic textfields

[–BEGIN EDIT–]
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 sitcking with it!

I feel like a fool now :slight_smile:
[–END EDIT–]

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! :slight_smile:

There are a few things to consider when you’re planning on including international characters in a dynamic text box. The first is the formatting and encoding of your external file. The second is the method you use to import the data from the file into your SWF.

  1. [color=blue]Format and encoding of the external file[/color]

Format
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";

  1. [color=blue]Importing your international text file into your SWF[/color]

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.

And that’s it. Simple huh? Seems a little strange that Flash doesn’t include support by default for all ASCII characters. 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. :slight_smile:

Cheers,
ptolemy

Nice :slight_smile:

pom :asian:

Hey ptolemy,
That is an interesting read. Would it be possible for me to use your info and make it into a tutorial You will be given full credit of course :slight_smile:

Cheers!
Kirupa :asian:

Go right ahead, I’d be honoured :slight_smile:

–ptolemy

This is really a super thread. Thank you!

What I’ve been doing so far is to specifically embed the special characters. But I’ve run into a problem with that - I’m wondering if any of you have also come across this:

In the box where I add newly needed special characters, (ñ, é, etc in addition to others already specified), I click done, export the movie, and save the fla as usual.

However, when I close and then go back to the fla later, the additions are gone. I’m not sure it happens every time, but I’ve seen this in both Flash 5 and Flash MX.

Does anyone know a work-around?

Thanks
Karen

PS… Does this tutorial also work on cryllic alphabets, such as polish or russian? Would I need to make any changes to the UTF specified?

*Originally posted by kirupa *
**Hey ptolemy,
That is an interesting read. Would it be possible for me to use your info and make it into a tutorial You will be given full credit of course :slight_smile:

Cheers!
Kirupa :asian: **

Don’t think that would necessary, IMHO. For Flash 5 maybe (even though there are many better ways of doing it), but for MX it’s as plain as day : System.UseCodePage = true.

Also remember that special characters, often used in languages other than English, do not translate through text files.

I am trying to integrate vietnamese, but it is not working.

I used both methods you guys suggested. I can see the text properly on the text file, but not on the .swf

Any suggestions?

This article is from moock.org, relates to the topic, so it might be of interest to you guys. It gets a little detailed by worth a read.

The System.useCodePage property is suggested by many as a magical cure to character display problems in Flash. Unfortunately, while useCodePage may appear to fix a problem on a single machine, it can create problems on others. This technote is an excerpt from ASDG2 explaining why you should avoid System.useCodePage unless you know exactly what you’re doing. If you just want to use a special character in Flash and you are exporting to Flash Player 6 or later, you should [URL=http://www.moock.org/asdg/technotes/usingSpecialCharacters/]follow these instructions.

Full article here