ActionScript performance tests
Auto Snapshot Extension
Central Apps
AIMWatcher
Fire
Buzzword Bingo
Blog
News
Contact

Tutorials
Detecting the
stage size -
distortion free
images in Flash


Scaling Flash movies

Unicode in FlashMX

Not caching SWFs

JavaScript/Flash w/Firefox and Opera

Books



 

Getting Unicode into Flash

Introduction - the SWF file

This tutorial teaches one way to include unicode characters into Flash movies. The text is loaded in as variable/value pairs from text files.

Tutorial requirements: knowledge of loadVariables action; basic Flash: dynamic text fields, UI Components, adding frames, adding keyframes.

 

Background information

One of the features in the new Flash MX that I was looking forward to using was the full support for unicode. Now that MX is out and I've had a chance to work with it one of the first projects I had involved displaying text in different languages. I saw the Macromedia tutorial and then saw all of the messages on flashkit.com from folks who were frustrated because they couldn't get the Japanese character set to display.

From the messages on Flashkit it looks like folks are simply pasting Japanese, Chinese, etc. characters into the text files that come with the example from Macromedia. When they try to view them through the Flash player they see garbage instead of the characters they expect.

Another problem people are running into is trying to paste unicode characters directly into Flash. It doesn't work. In order to put Japanese characters (for example) directly into Flash you must have your system default language set as Japanese and be using the Japanese version of Flash. A couple of ways you can get Japanese characters into the Flash player is either to load them in from text files as variables, or paste the text into a graphics application and export them in an image that you can then import into Flash.

I came across this:

"To create Japanese content, for example, authors needed to use a third party tool for double-byte integration, or a Japanese OS and the Japanese version of the Flash authoring environment (and therefore a native-speaking Japanese author). But with Flash MX, all you need to do is install and set the proper language encoding (Control Panel > Regional Options on Windows 2000/XP, System Preferences > International on Mac OS X), and type text directly into any Flash element."

here

Make sure you look at the Using Macromedia Flash MX as a multilingual authoring tool techtip on the Macromedia web site as it's a great resource.


 

Creating the text files.

First, open up Notepad, or any other text editor that will save as UTF-8 and type in dynamic_text= followed by the text you want to display. Save the file as dynamic.txt with UTF-8 encoding as shown in the image

Create two more files - dynamic_de.txt and dynamic_jp.txt for the German and Japanese text. If you need text to paste into these files you can select the text from the swf on the first step of this tutorial and copy it.


 

Creating the buttons

Next open up FlashMX and drop three UI Component PushButtons onto the stage.

In the properties box change their labels from "Push Button" to English, German, and Japanese

Note: Save the .fla file in the same directory in which you saved the text files.

Select the English button and add the following actions to it:
on (release) {
_parent.gotoAndStop(5);
}

Select the German button and add the following actions to it:
on (release) {
_parent.gotoAndStop(10);
}

Select the Japanese button and add the following actions to it:
on (release) {
_parent.gotoAndStop(15);
}


 

Creating the dynamic text area

Now use the text tool to create a large text box filling the bottom half of the stage. Set the properties of the text box as shown below:

Note:
  • The text area is Dynamic Text rather than Static Text.
  • The variable is set to dynamic_text (the variable used in the very beginning of each of your text files)
  • The font is set to _sans

The font can be set to other fonts, but be careful. If you use a font other than the system fonts you should experiment with what characters from that font should be embedded (all, lowercase only, etc.). The system fonts (_sans, _serif, etc) are the safest bet, however I've found that about a third of the fonts that I have installed contain the full unicode character set and will display unicode characters just fine.


 

Adding frames

Insert frames so that there are a total of 15 frames as shown below.
Insert keyframes at frames 5, 10, and 15.

Select the keyframe in the first frame and add a stop() action.


Select frame 5 and add the loadVariables action as shown below.


Select frame 10 and add the loadVariables action shown below.


Select frame 15 and add the loadVariables action shown below.


Export and options

Be sure that you export the .swf to be viewed only with the Flash 6 player.

You can load more than one variable from the text file at a time by separating them with an & as shown below:
myFirstVariable=something&mySecondVariable=more&myThirdVariable=even more

You can use less frames in the timeline. I added more frames just to spread it out and make it easier to read. If you remove frames remember to change the actions on the buttons which point to the keyframes (5, 10, 15).


Oh.. but you have to export for Flash 5???

If you're trolling through here looking for a way to get Japanese characters into Flash 5 Dynamic text fields.. well.

First do this (Win XP example.. )

Then you'll see three new fonts.. use the first one (just under _typewriter)..

 


 

Other considerations & Links

If you load the text in from an external file as a name/value pair be aware that there are reserved characters such as % so you will need to URLencode it as %25

So instead of
dynamic_text01=Save up to 20% on Footwear products
you'll need to use
dynamic_text01=Save up to 20%25 on Footwear products

More about URL encoding can be found here

Another option is to place the text in an XML document rather than loading it from a name/value pair text file.

Great info on Unicode for the web (including samples of Greek, Arabic, etc and links to download fonts) is here

Great info on how to use special characters (unicode) in Flash MX from Colin Moock is here

You can also use the unicode Escape Sequence directly in your ActionScript like so.. trace("hello world\u00A9")
which would produce: hello world©

I found this listing in the ActionScript Dictionary and it might be of interest.. System.useCodepage. Make sure you aren't setting it to true if you're trying to load in unicode.

If you have to embed fonts in your SWF... make sure you read Quasimondo's note on font encoding for internationalization.
If you choose to embed a font.. make sure it contains the unicode characters you are going to use. Many do not.

 

11/06/03 - Take a look at the image below.. I went to babelfish and translated some english text into chinese then copy and pasted it directly into the Flash MX 2004 IDE. Sweet.

1/29/04 - I just came across this.. http://www.swfx.org/generator/index.jsp
"swfx.org unicode flash generator is a 100% pure Java flash generator. It provides support for dynamic unicode text in flash movies through generation of swf files, much like Macromedia Generator. "

2/16/04 - If you are pasting unicode characters into the Actions panel and they are showing up as ??? or boxes then you need to try changing the font used to display the ActionScript. To do that in MX04 go to Edit>Preferences and click the ActionScript tab. Pull down the dropdown for "Text" and choose something different. Microsoft Sans Serif allowed me to see the unicode characters for superscript and subscript..

4/17/04 - If you are using PHP to pass unicode text into Flash you should read the urlencode information here http://www.php.net/urlencode

2/4/05 - nice new technote "Reading special characters from a text file" added here: http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=tn_14143

8/11/05 - make sure you get the "special character" panel from bit-101 (it's free.. he's cool) here http://www.bit-101.com/blog/?p=653 if you're doing much work with unicode characters in Flash.

2/14/06 - I had quite a time with some unicode text getting mangled after it was sent into a SWF from JavaScript. Here's what I found

 

last updated 2/14/06

.. shoo.. this page is getting out of hand.. and no time to redo it.. sorry.

 

 

 

 

tutorial