Another good question/dilemma came up on FlexCoders the other day. A curious poster asked how you could embed a copyright symbol, ©, into a Flex application since using © did not seem to work. As it turns out, an easy way to do this is to use a character’s numeric value (©) instead of its code name (©).
Well, at any rate, here’s a handy little chart thing-a-ma-jig to hopefully help out if you’re looking for some specific codes. Granted, you could have probably found it on Google in a fraction of the time, but what fun would that be?
Full code after the jump.
Clicking on a row in the DataGrid control will display both the numeric and string values, for easy copy-paste goodness. Changing the values of the Slider control will change which characters are displayed. By default characters from   to Ȁ are displayed.
Download source (ZIP, 1K) | View MXML
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/08/02/using-special-characters-in-your-flex-applications/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white"
creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
private var charCodes:ArrayCollection;
private function init():void {
charCodes = new ArrayCollection();
var i:int;
for (i = slider.values[0]; i <= slider.values[1]; i++) {
charCodes.addItem({charCodeNum:i, charCodeValue:"" + formatString(i) + ";", charCodeStr:String.fromCharCode(i)});
}
}
private function formatString(str:Object, minLength:int = 4):String {
return ("000000000" + str.toString()).substr(-minLength);
}
]]>
</mx:Script>
<mx:VBox>
<mx:DataGrid id="dataGrid" dataProvider="{charCodes}" width="300">
<mx:columns>
<mx:DataGridColumn dataField="charCodeStr" />
<mx:DataGridColumn dataField="charCodeValue" />
</mx:columns>
</mx:DataGrid>
<mx:HBox width="100%">
<mx:HSlider id="slider" minimum="32" maximum="512" thumbCount="2" values="[0, 512]" liveDragging="true" snapInterval="1" tickInterval="32" dataTipPrecision="0" change="init()" />
<mx:Label text="`{dataGrid.selectedItem.charCodeStr}` = {dataGrid.selectedItem.charCodeValue}" selectable="true" />
</mx:HBox>
</mx:VBox>
<mx:Label text="© {new Date().fullYear} Flex Examples" />
</mx:Application>
View source is enabled in the following example.
Update 2007/09/01: I just discovered another trick today. You can use custom XML entities which allow you to use “©” from within your Flex applications instead of “©” or “©”:
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/08/02/using-special-characters-in-your-flex-applications/ -->
<!DOCTYPE example[
<!ENTITY copy "©">
]>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Label text="©" fontSize="64" />
</mx:Application>
Update 2008/08/19: You can also use special characters in your Flex applications using the following syntax: © (MXML), © (MXML), and \u00A9 (ActionScript), as seen in the following example:
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/08/02/using-special-characters-in-your-flex-applications/ -->
<mx:Application name="Button_label_Unicode_test"
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="horizontal"
verticalAlign="middle"
backgroundColor="white">
<mx:Script>
<![CDATA[
private function init():void {
btn3.label = "\\u00A9 - \u00A9 (ActionScript)";
}
]]>
</mx:Script>
<mx:Button id="btn1" label="© - © (MXML)" />
<mx:Button id="btn2" label="© - © (MXML)" />
<mx:Button id="btn3" creationComplete="init();" />
</mx:Application>
View source is enabled in the following example.





Nice to see this sample. Thanks!
But as I know we can directly use Unicode chars without any need of any kind of replacement if you have the right font.
The translation between &#xxxx; and characters seems to be done at compile time, most likely by the XML parser. This is a bummer if you load data from a database and want to display some special characters.
I’ve been desperately trying to create a currency formatter which gets it’s currency symbol via a remote object call to display a € (Euro symbol, char code 8364). Can’t get it to work… all I get is a â (a with circumflex).
Your method works fine if I do this:
But not if I do this:
(and because of that, loading a string containing “€″ obviously wouldn’t work either)
You would have to do this (which doesn’t work so well when you load your data externally, it’s not feasible to scan through all text looking for entities):
As it is I have given up, other currencies are written with their three-letter abbreviations anyway, so writing EUR 33.00 is perfectly fine. However, it would look so much better with a proper €. If you have any similiar ideas of how to get special characters to work in an even more general way I would be very interested.
Theo,
How is it not working?
If I try this in my MXML document it seems to work:
<mx:CurrencyFormatter id="cf" currencySymbol="€" precision="2" /> <mx:Text htmlText="{cf.format(100)}" />Also, if I load a remote document (content.txt) it looks like it parses that € character properly (as long as I set the
htmlTextproperty and not thetextproperty). Observe:<mx:HTTPService id="getText" url="content.txt" resultFormat="text" /> <mx:Text condenseWhite="true" creationComplete="getText.send()"> <mx:htmlText>{getText.lastResult}</mx:htmlText> </mx:Text>And my content.txt file looks like:
Is that roughly what you were looking for, or did I totally misunderstand?
Peter (who hopes the formatting for this turned out)
Yes, it works in a MXML document, because the XML parser translates € into €, but it doesn’t work if you put the € in ActionScript code, or if you load it using remote objects. Like this (in an .as or a script tag):
That will display the literal string in the text field, however
works fine.
I hadn’t considered htmlText though, good idea. It should work regardless.
To properly display the euro character from strings got via a RemoteObject (using AMFPHP) I simply used this line of code :
And oddly enough, this works…
Instead of a weird square character, I get the nice ‘€’ one!
nice! It is also critical that you have the special characters embedded in the font you’re using.
Well, no…
At least not for my snippet.
Hi.
Just looking for a special character for a “does not equal” eg. an equals sign with a slash going through it…do you have any idea if one exists? Thanks
Jack,
On Windows you can use charmap.exe to find all sorts of special characters and their unicode values (which may or may not be different/available, depending on which font you’re using).
The character you want is “Not Equal To”, and is U+2260: ࣔ
Peter