11 November 2008

Setting a Flex Label to a Special Character

When setting a label's text property dynamically, you can't use the ASCII code for special characters; you must use the HEX value instead. For example, the following will not have the desired effect,

var date:Date = new Date();
lblFooter.text = "© " + date.fullYear.toString() + " MyOrganization.";

This will produce the following result:

© 2008 MyOrganization.

To correct this, use the HEX value instead,

var date:Date = new Date();
lblFooter.text = "\u00A9 " + date.fullYear.toString() + " MyOrganization.";

which gives you,

© 2008 MyOrganization.

Note that the HEX code must be 4 digits. If, as in this case, the code is only 2, you'd precede it with 0's. To look up the codes, go here.

2 comments:

Anonymous said...

Ahhhh knew there must have been a way! Wicked thanks for that

Alex C said...

Glad it's helpful!