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)";
See Also
Table A-1 in the Appendix lists the Unicode
escape sequences.
|