Multilanguage text and ActionScript



You can control multilanguage text and import multilanguage XML files with ActionScript®.

Use ActionScript to load external files

To load existing XML data, or use a different format for the XML file, use the loadVariables action, the getURL action, the LoadVars object, or the XML object to create a document that contains multilanguage text by placing the text in an external text or XML file and loading the file into the movie clip at runtime.

Save the external file in UTF‑8 (recommended), UTF‑16BE, or UTF‑16LE format, using an application that supports the format. If you are using UTF‑16BE or UTF‑16LE format, the file must begin with a BOM to identify the encoding format to Flash Player. The following table lists the BOM to include to identify the encoding:
Note: Most text editors that can save files in UTF‑16BE or LE automatically add the BOMs to the files.

UTF Format

First Byte

Second Byte

UTF‑16BE

OxFE

OxFF

UTF‑16LE

OxFF

OxFE

Note: If the external file is an XML file, you cannot use an XML encoding tag to change the file encoding. Save the file in a supported Unicode format.
  1. In the Flash authoring application, create a dynamic or input text field to show the text in the document.
  2. In the Property inspector, with the text field selected, assign an instance name to the text field.
  3. Outside of Flash, create a text or XML file that defines the value for the text field variable.
  4. Save the XML file in UTF‑8 (recommended), UTF‑16BE, or UTF‑16LE format.
  5. Use one of the following ActionScript procedures to reference the external file and load it into the dynamic or input text field:
    • Use the loadVariables action to load an external file.

    • Use the getURL action to load an external file from a specified URL.

    • Use the LoadVars object (a predefined client-server object) to load an external text file from a specified URL.

    • Use the XML object (a predefined client-server object) to load an external XML file from a specified URL. For more information, see XML in the ActionScript 2.0 Language Reference.

Create multilanguage documents using the #include action

To create a document that contains multiple languages, use the #include action.

Use an application that supports UTF‑8 encoding, such as Dreamweaver, to save the text file in UTF‑8 format.

To identify the file as Unicode to the Flash authoring tool, include the following header as the first line of the file:

//!-- UTF8
Note: Include a space after the second dash (-).

By default, the Flash authoring application assumes that external files that use the #include action are encoded in the traditional code page of the operating system running the authoring tool. Using the //!-- UTF8 header in a file tells the authoring tool that the external file is encoded as UTF‑8.

  1. In the Flash authoring tool, create a dynamic or input text field to display the text in the document.
  2. In the Property inspector, with the text field selected, assign an instance name to the text field.
  3. Outside of Flash, create a text file that defines the value for the text field variable. Add the //!-- UTF8 header at the beginning of the file.
  4. Save the text file in UTF‑8 format.
  5. To include the external file in the dynamic or input text field, use the #include directive. For more information, see #include directive in the ActionScript 2.0 Language Reference.

Creating multilanguage documents by using text variables

To include Unicode-encoded contents in text variables, use the syntax \uXXXX, where XXXX is the four-digit hexadecimal code point, or escape character, for the Unicode character. The Flash authoring tool supports Unicode escape characters through \uFFFF. To find the code points for Unicode characters, see the Unicode Standard at Unicode.org.

You can use Unicode escape characters only in text field variables. You cannot include Unicode escape characters in external text or XML files; Flash Player 6 does not recognize Unicode escape characters in external files.

For example, to set a dynamic text field (with the myTextVar instance name) that contains Japanese, Korean, Chinese, English, and Greek characters and the Euro sign, enter the following:

myTextVar.text = "\u304B\uD55C\u6C49hello\u03BB\u20AC";

When the SWF file plays, the following characters appear in the text field:

Example that shows the resulting characters in the text field.

For best results when creating a text field that contains multiple languages, use a font that includes all the glyphs your text needs.

Using the XMLConnector component to connect to external XML files

Use the version 2 XMLConnector component to connect to an external XML document to bind to properties in the document. Its purpose is to read or write XML documents by using HTTP GET operations, POST operations, or both. It acts as a connector between other components and external XML documents. The XMLConnector communicates with components in your application by using either data-binding features in the Flash authoring environment or ActionScript code. For more information, see XML Connector component in the ActionScript 2.0 Components Language Reference.