Tutorial: Developing a Multi-Language Application with ActionScript 2.0

by Stefan Schmalhaus

There are many approaches on how to build a Flash application that supports multiple languages for the user interface. Basically there are two main methods of localizing an application: You can compile the language resources into the Flash movie and generate different SWF files for each language version. Or you can load the language resources dynamically at runtime. In this tutorial I'm going to show you a method of dynamically loading the language resources.

Although the example that is presented here is very simple, the general approach can be utilized for more complex Flash applications. The main advantages of this solution are:

If you want to follow the tutorial by examining the source files you can download them here (you must keep the directory structure when unzipping the archive!).

The Sample Application

To keep things simple we are going to populate a Flash ComboBox component with month names. The final result looks like this:

Admittedly, this doesn't look that interesting at first glance. But imagine an application with several complex forms, all with language-specific labels and content.

The XML Language Files

Let's assume we have a directory structure like this:

main.swf
languages/en.xml
languages/de.xml

Here are the language files:

en.xml

<?xml version="1.0" encoding="utf-8"?>
<language id="en" description="English">
   <april>April</april>
   <august>August</august>
   <december>December</december>
   <february>February</february>
   <january>January</january>
   <july>July</july>
   <june>June</june>
   <march>March</march>
   <may>May</may>
   <monthNames>Month Names</monthNames>
   <november>November</november>
   <october>October</october>
   <september>September</september>
</language>

de.xml

<?xml version="1.0" encoding="utf-8"?>
<language id="de" description="German">
   <april>April</april>
   <august>August</august>
   <december>Dezember</december>
   <february>Februar</february>
   <january>Januar</january>
   <july>Juli</july>
   <june>Juni</june>
   <march>März</march>
   <may>Mai</may>
   <monthNames>Monatsnamen</monthNames>
   <november>November</november>
   <october>Oktober</october>
   <september>September</september>
</language>

French, Italian, Spanish, etc. language files would look similar, of course. The XML tag identifiers are in English, and each tag contains a word or phrase in the particular language. Listing the XML tags in alphabetical order makes it easier to maintain the language resources.

  1 of 4 Next