Previous Page
Next Page

Recipe 9.19. Displaying Unicode Text

Problem

You want to display Unicode text in your application, possibly including non-English characters.

Solution

Load the text from an external source. Optionally, use Unicode escape sequences for the characters within the assignment to the text field's text property.

Discussion

If you want to display Unicode text in a text field, there are several ways in which you can accomplish that:

  • Load the Unicode text from an external source (e.g., a text file, XML document, database).

  • Use the character directly within the ActionScript code as a string value.

  • Use a Unicode escape sequence.

If you load the text from an external source, you can load Unicode text and assign it to a text field. For more information regarding loading content from external sources, see Chapter 20.

Assuming you're using an editor that supports Unicode (such as Flex Builder), you can add the character directly within the code. Optionally, if you know the escape sequence for the character, you can assign it to a text field's text property. All Unicode escape sequences in ActionScript begin with \\u and are followed by a four-digit hexadecimal number. The escape sequences must be enclosed in quotes. The following example displays a registered mark (®) in both ways:

field.text = "Add a registered mark directly (®) or with a Unicode 
escape sequence (\u00AE)";

If you want a Unicode character reference online, under Windows, you can open up the Character Map utility using Start Programs Accessories System Tools Character Map. On Mac OS X, first enable the Input Menu in System Preferences International Input Menu, and turn on the checkbox next to Character Palette. To open the Character Palette, go to the menu bar, select the flag for your country (e.g., the Stars and Stripes for the U.S.), and select Show Character Palette.


See Also

Table A-1 in the Appendix lists the Unicode escape sequences.


Previous Page
Next Page
Converted from CHM to HTML with chm2web Pro 2.85 (unicode)