<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Flex Examples &#187; String.fromCharCode()</title>
	<atom:link href="http://blog.flexexamples.com/tag/string-fromcharcode/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.flexexamples.com</link>
	<description>Just a bunch of Adobe Flex Examples</description>
	<lastBuildDate>Wed, 26 Jan 2011 18:09:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using special characters in your Flex applications</title>
		<link>http://blog.flexexamples.com/2007/08/02/using-special-characters-in-your-flex-applications/</link>
		<comments>http://blog.flexexamples.com/2007/08/02/using-special-characters-in-your-flex-applications/#comments</comments>
		<pubDate>Fri, 03 Aug 2007 04:15:00 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[fromCharCode()]]></category>
		<category><![CDATA[String.fromCharCode()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/08/02/using-special-characters-in-your-flex-applications/</guid>
		<description><![CDATA[<p>Another good question/dilemma came up on FlexCoders the other day. A curious poster asked how you could embed a copyright symbol, &#169;, into a Flex application since using &#38;copy; did not seem to work. As it turns out, an easy way to do this is to use a character&#8217;s numeric value (&#38;#169;) instead of its [...]]]></description>
			<content:encoded><![CDATA[<p>Another good question/dilemma came up on FlexCoders the other day. A curious poster asked how you could embed a copyright symbol, &copy;, into a Flex application since using &amp;copy; did not seem to work. As it turns out, an easy way to do this is to use a character&#8217;s numeric value (&amp;#169;) instead of its code name (&amp;copy;).</p>
<p>Well, at any rate, here&#8217;s a handy little chart thing-a-ma-jig to hopefully help out if you&#8217;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?</p>
<p>Full code after the jump.</p>
<p><span id="more-51"></span></p>
<p class="note">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 &amp;#0032; to &amp;#0512; are displayed.</p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/SpecialChars_test/bin/srcview/SpecialChars_test.zip">Download source (ZIP, 1K)</a> | <a href="http://blog.flexexamples.com/wp-content/uploads/SpecialChars_test/main.mxml">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2007/08/02/using-special-characters-in-your-flex-applications/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        creationComplete="init()"&gt;

    &lt;mx:Script&gt;
        &lt;![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 &lt;= 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);
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:VBox&gt;
        &lt;mx:DataGrid id="dataGrid" dataProvider="{charCodes}" width="300"&gt;
            &lt;mx:columns&gt;
                &lt;mx:DataGridColumn dataField="charCodeStr" /&gt;
                &lt;mx:DataGridColumn dataField="charCodeValue" /&gt;
            &lt;/mx:columns&gt;
        &lt;/mx:DataGrid&gt;

        &lt;mx:HBox width="100%"&gt;
            &lt;mx:HSlider id="slider" minimum="32" maximum="512" thumbCount="2" values="[0, 512]" liveDragging="true" snapInterval="1" tickInterval="32" dataTipPrecision="0" change="init()" /&gt;
            &lt;mx:Label text="`{dataGrid.selectedItem.charCodeStr}` = {dataGrid.selectedItem.charCodeValue}" selectable="true" /&gt;
        &lt;/mx:HBox&gt;
    &lt;/mx:VBox&gt;

    &lt;mx:Label text="&amp;#169; {new Date().fullYear} Flex Examples" /&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information">View source is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/SpecialChars_test/bin/main.html" width="100%" height="300"></iframe></p>
<p class="new">Update 2007/09/01: I just discovered another trick today. You can use custom XML entities which allow you to use &#8220;&amp;copy;&#8221; from within your Flex applications instead of &#8220;&amp;#169;&#8221; or &#8220;&amp;#xA9;&#8221;:</p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2007/08/02/using-special-characters-in-your-flex-applications/ --&gt;
&lt;!DOCTYPE example[
    &lt;!ENTITY copy "&amp;#xA9;"&gt;
]&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"&gt;

    &lt;mx:Label text="&amp;copy;" fontSize="64" /&gt;

&lt;/mx:Application&gt;
</pre>
<p class="new">Update 2008/08/19: You can also use special characters in your Flex applications using the following syntax: <code>&amp;#169;</code> (MXML), <code>&amp;#xA9;</code> (MXML), and <code>\u00A9</code> (ActionScript), as seen in the following example:</p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2007/08/02/using-special-characters-in-your-flex-applications/ --&gt;
&lt;mx:Application name="Button_label_Unicode_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="horizontal"
        verticalAlign="middle"
        backgroundColor="white"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            private function init():void {
                btn3.label = "\\\\u00A9 - \\u00A9 (ActionScript)";
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:Button id="btn1" label="&amp;#169; - &#169; (MXML)" /&gt;
    &lt;mx:Button id="btn2" label="&amp;#xA9; - &#xA9; (MXML)" /&gt;
    &lt;mx:Button id="btn3" creationComplete="init();" /&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/Button_label_Unicode_test/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/Button_label_Unicode_test/bin/main.html" width="100%" height="100"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Using special characters in your Flex applications on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/08/02/using-special-characters-in-your-flex-applications/',contentID: 'post-51',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'fromCharCode(),String.fromCharCode()',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2007/08/02/using-special-characters-in-your-flex-applications/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
	</channel>
</rss>

