Multilanguage in Actionscript 3 via Flash/Flex

4 min read
Multilanguage in Actionscript 3 via Flash/Flex
Multilanguage in Actionscript 3 via Flash/Flex

I am here to share with you a solution to a problem that came out when I was coping the multi-language need for a flash web site.

I'll be exhaustive as well as concise to get the point. When you move from AS2 to AS3 and so to OOP you change definitely the way you use Flash forever. You now can use  Flex to write down tons of classes and do everything with Flash. Since in Flex you can develop your stand-alone application, communication between Flash and Flex can be weird.

If you are here I guess you are developing a multi-language website in Flex yet you are not able to control the language at runtime from Flex to Flash and the other way around.

The example


Basically we have a dynamic text on Flash and want to change the language previously set in the string panel via Flex. Have a look to the screenshot up here. Set the text variable name to "myText" and open the Strings panel from the menu "Window > Other Panels > Strings". This panel lets you assign as many text as many languages you need. Simply choose your text, go to settings and choose your languages then move to the panel and give a name to this control on the ID box. Down there set the text for the different languages.

Add a new layer on Flash where to put the code below.
import fl.lang.*;

import in9;
var l:Language = new Language();
addChildAt(l, 1);
Locale.loadLanguageXML( l.getLanguage() );

function localeListener(success:Boolean):void {
if (success) {
myText.text = Locale.loadString("IDS_TEST");
} else {
myText.text = "unable to load language XML file.";

addEventListener("onChangeLanguage", onChangeLanguage);

function onChangeLanguage( event:Event ):void {
Locale.loadLanguageXML( l.getLanguage() );

Shortly you have here the fl.lang class for working with languages and the SharedObject for working with cookies. I use a cookie indeed to keep track of a user preference concerning the language.
Object "l" is the following class "":
import flash.display.MovieClip;
import flash.system.Capabilities;

public class Language extends MovieClip
private var _so:SharedObject;

public function Language()
_so = SharedObject.getLocal("","/");

public function setLanguage( s:String ):void {
_so = SharedObject.getLocal("","/"); = s;

public function getLanguage():String {

public function getLanguageToWholeString():String {
switch( ) {
case "fr":
return "FRANÇAIS";
case "en":
return "ENGLISH";
case "it":
return "ITALIANO";

return "ENGLISH";

You can copy and paste to use it as is. Instead of "" set the name you want to give to your own cookie. That's it.
The function "localeListener" is the callback function that is called after the XML file is loaded, so whenever you then call "Locale.loadLanguageXML( l.getLanguage() );"

And what about changing language from Flex?
Suppose to have a button or an object where you set this up:
myMenu.addEventListener(MouseEvent.CLICK, onClickLanguage);
then you simply put:
private function onClickLanguage( event:MouseEvent ):void {
yourLoader.content.dispatchEvent(new Event("onChangeLanguage"));

This will cause an event dispatch that will be afterwards caught at runtime from the code I earlier wrote on Flash.
When the function is called I dare say that you have already changed the language on your cookie via another method.

If you have troubles with the fl.lang class, here it is how to import into your workspace:
1. Preferences -> Flex -> Editors -> ActionScritp Code -> uncheck Remove unused imports when organizing

2. First add reference to flex builder
Preferences -> General -> Workspace -> Linked Resources -> New -> Folder

Name: fl

Location: C:\Program Files (x86)\Adobe\Adobe Flash CS3\en\Configuration\ActionScript 3.0\Classes

Then add references to each project: Project Properties -> Actionscript Build Path -> Source path Tab -> new -> enter ${fl}

A useful example ( despite it is only in Italian ) for the multilanguage restricted to Flash is:

Ciao, Matt
This website uses cookies. By continuing to browse the site you are agreeing to our privacy policy.By closing this banner or clicking on any other item of this page, you agree to the use of such cookies.