<?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; getColorName()</title>
	<atom:link href="http://blog.flexexamples.com/tag/getcolorname/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>Changing default line colors in a Flex LineChart control</title>
		<link>http://blog.flexexamples.com/2007/11/13/changing-default-line-colors-in-a-flex-linechart-control/</link>
		<comments>http://blog.flexexamples.com/2007/11/13/changing-default-line-colors-in-a-flex-linechart-control/#comments</comments>
		<pubDate>Tue, 13 Nov 2007 16:06:35 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[Charting]]></category>
		<category><![CDATA[LineSeries]]></category>
		<category><![CDATA[StyleManager]]></category>
		<category><![CDATA[getColorName()]]></category>
		<category><![CDATA[lineStroke]]></category>
		<category><![CDATA[stroke]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/11/13/changing-default-line-colors-in-a-flex-linechart-control/</guid>
		<description><![CDATA[<p>The following example shows how you can change the line colors in a LineChart in Flex by setting the lineStroke style in MXML or ActionScript, as seen in the following snippets:</p> <p>MXML:</p> &#60;mx:LineSeries id="closeSeries" yField="@close" form="curve" displayName="Close"&#62; &#60;mx:lineStroke&#62; &#60;mx:Stroke color="haloGreen" weight="2" alpha="0.6" /&#62; &#60;/mx:lineStroke&#62; &#60;/mx:LineSeries&#62; <p>ActionScript:</p> &#60;mx:LineSeries id="closeSeries" yField="@close" form="curve" displayName="Close" /&#62; ... closeSeries.setStyle("lineStroke", new [...]]]></description>
			<content:encoded><![CDATA[<p>The following example shows how you can change the line colors in a LineChart in Flex by setting the lineStroke style in MXML or ActionScript, as seen in the following snippets:</p>
<p>MXML:</p>
<pre class="code">
&lt;mx:LineSeries id="closeSeries" yField="@close" form="curve" displayName="Close"&gt;
    &lt;mx:lineStroke&gt;
        &lt;mx:Stroke color="haloGreen" weight="2" alpha="0.6" /&gt;
    &lt;/mx:lineStroke&gt;
&lt;/mx:LineSeries&gt;
</pre>
<p>ActionScript:</p>
<pre class="code">
&lt;mx:LineSeries id="closeSeries" yField="@close" form="curve" displayName="Close" /&gt;
...
closeSeries.setStyle("lineStroke", new Stroke(0xFF0000, 2, 0.4));
</pre>
<p>Full code after the jump.</p>
<p><span id="more-294"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/LineSeries_lineStroke_test/main.mxml">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0"?&gt;
&lt;!-- http://blog.flexexamples.com/2007/11/13/changing-default-line-colors-in-a-flex-linechart-control/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.styles.StyleManager;
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:XMLListCollection id="dp"&gt;
        &lt;mx:source&gt;
            &lt;mx:XMLList&gt;
                &lt;quote date="8/27/2007" open="40.38" close="40.81" /&gt;
                &lt;quote date="8/24/2007" open="40.5" close="40.41" /&gt;
                &lt;quote date="8/23/2007" open="40.82" close="40.6" /&gt;
                &lt;quote date="8/22/2007" open="40.4" close="40.77" /&gt;
                &lt;quote date="8/21/2007" open="40.41" close="40.13" /&gt;
                &lt;quote date="8/20/2007" open="40.55" close="40.74" /&gt;
                &lt;quote date="8/17/2007" open="40.18" close="40.32" /&gt;
                &lt;quote date="8/16/2007" open="39.83" close="39.96" /&gt;
                &lt;quote date="8/15/2007" open="40.22" close="40.18" /&gt;
                &lt;quote date="8/14/2007" open="41.01" close="40.41" /&gt;
                &lt;quote date="8/13/2007" open="41" close="40.83" /&gt;
                &lt;quote date="8/10/2007" open="41.3" close="41.06" /&gt;
                &lt;quote date="8/9/2007" open="39.9" close="40.75" /&gt;
                &lt;quote date="8/8/2007" open="39.61" close="40.23" /&gt;
                &lt;quote date="8/7/2007" open="39.08" close="39.42" /&gt;
                &lt;quote date="8/6/2007" open="38.71" close="39.38" /&gt;
                &lt;quote date="8/3/2007" open="39.47" close="38.75" /&gt;
                &lt;quote date="8/2/2007" open="39.4" close="39.52" /&gt;
                &lt;quote date="8/1/2007" open="40.29" close="39.58" /&gt;
            &lt;/mx:XMLList&gt;
        &lt;/mx:source&gt;
    &lt;/mx:XMLListCollection&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;
        &lt;mx:Button label="0xFF0000" click="closeSeries.setStyle('lineStroke', new Stroke(0xFF0000, 2, 0.4));" /&gt;
        &lt;mx:Button label="0xFF00FF" click="closeSeries.setStyle('lineStroke', new Stroke(0xFF00FF, 2, 1.0));" /&gt;
        &lt;mx:Button label="haloSilver" click="closeSeries.setStyle('lineStroke', new Stroke(StyleManager.getColorName('haloSilver'), 2, 1.0));" /&gt;

        &lt;mx:Spacer width="100%" /&gt;

        &lt;mx:Legend dataProvider="{lineChart}" /&gt;
    &lt;/mx:ApplicationControlBar&gt;

    &lt;mx:LineChart id="lineChart"
            showDataTips="true"
            dataProvider="{dp}"
            width="100%"
            height="100%"&gt;

        &lt;!-- series filters --&gt;
        &lt;mx:seriesFilters&gt;
            &lt;mx:Array /&gt;
        &lt;/mx:seriesFilters&gt;

        &lt;!-- vertical axis --&gt;
        &lt;mx:verticalAxis&gt;
            &lt;mx:LinearAxis baseAtZero="false" title="Price" /&gt;
        &lt;/mx:verticalAxis&gt;

        &lt;!-- horizontal axis --&gt;
        &lt;mx:horizontalAxis&gt;
            &lt;mx:CategoryAxis id="ca" categoryField="@date" title="Date" /&gt;
        &lt;/mx:horizontalAxis&gt;

        &lt;!-- horizontal axis renderer --&gt;
        &lt;mx:horizontalAxisRenderers&gt;
            &lt;mx:AxisRenderer axis="{ca}" canDropLabels="true" /&gt;
        &lt;/mx:horizontalAxisRenderers&gt;

        &lt;!-- series --&gt;
        &lt;mx:series&gt;
            &lt;mx:LineSeries id="closeSeries" yField="@close" form="curve" displayName="Close"&gt;
                &lt;mx:lineStroke&gt;
                    &lt;mx:Stroke color="haloGreen" weight="2" alpha="0.6" /&gt;
                &lt;/mx:lineStroke&gt;
            &lt;/mx:LineSeries&gt;
            &lt;mx:LineSeries yField="@open" form="curve" displayName="Open"&gt;
                &lt;mx:lineStroke&gt;
                    &lt;mx:Stroke color="haloOrange" weight="2" alpha="0.6" /&gt;
                &lt;/mx:lineStroke&gt;
            &lt;/mx:LineSeries&gt;
        &lt;/mx:series&gt;
    &lt;/mx:LineChart&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/LineSeries_lineStroke_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/LineSeries_lineStroke_test/bin/main.html" width="100%" height="500"></iframe></p>
<p>When setting a stroke in ActionScript, note that you must pass the stroke color as a numeric value (like 0xFF0000), not as a color name (like &#8220;red&#8221;):</p>
<pre class="code">
closeSeries.setStyle("lineStroke", new Stroke(0xFF0000, 2, 0.4));
</pre>
<p>If you want to use a named color, you can use the static StyleManager.getColorName() method, as shown in the following snippet:</p>
<pre class="code">
closeSeries.setStyle("lineStroke", new Stroke(StyleManager.getColorName("red"), 2, 1.0));
</pre>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Changing default line colors in a Flex LineChart control on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/11/13/changing-default-line-colors-in-a-flex-linechart-control/',contentID: 'post-294',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'getColorName(),lineStroke,stroke',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/11/13/changing-default-line-colors-in-a-flex-linechart-control/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Converting color names to numbers using the StyleManager class</title>
		<link>http://blog.flexexamples.com/2007/09/06/converting-color-names-to-numbers-using-the-stylemanager-class/</link>
		<comments>http://blog.flexexamples.com/2007/09/06/converting-color-names-to-numbers-using-the-stylemanager-class/#comments</comments>
		<pubDate>Fri, 07 Sep 2007 06:00:46 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[StringUtil]]></category>
		<category><![CDATA[StyleManager]]></category>
		<category><![CDATA[getColorName()]]></category>
		<category><![CDATA[getColorNames()]]></category>
		<category><![CDATA[trimArrayElements()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/09/06/converting-color-names-to-numbers-using-the-stylemanager-class/</guid>
		<description><![CDATA[<p>The following examples show how you can convert color names (such as &#8220;red&#8221;, &#8220;haloSilver&#8221;, &#8220;#FFFFFF&#8221;, and &#8220;0xFFFF00&#8243;) into numeric values, using the StyleManager class&#8217;s static getColorName() method and getColorNames() method.</p> <p>Full code after the jump.</p> <p></p> <p>The following example shows how you can convert a single color name into an integer using the static StyleManager.getColorName() [...]]]></description>
			<content:encoded><![CDATA[<p>The following examples show how you can convert color names (such as &#8220;red&#8221;, &#8220;haloSilver&#8221;, &#8220;#FFFFFF&#8221;, and &#8220;0xFFFF00&#8243;) into numeric values, using the StyleManager class&#8217;s static <code>getColorName()</code> method and <code>getColorNames()</code> method.</p>
<p>Full code after the jump.</p>
<p><span id="more-158"></span></p>
<p>The following example shows how you can convert a single color name into an integer using the static <code>StyleManager.getColorName()</code> method:</p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/StyleManager_getColorName_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/09/06/converting-color-names-to-numbers-using-the-stylemanager-class/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.styles.StyleManager;

            private function toHex(item:Object):String {
                var hex:String = Number(item).toString(16);
                return ("00000" + hex.toUpperCase()).substr(-6);
            }

            private function button_click():void {
                var colorInt:uint = StyleManager.getColorName(textInput.text);
                if (colorInt == StyleManager.NOT_A_COLOR) {
                    swatch.setStyle("backgroundColor", StyleManager.NOT_A_COLOR);
                    lbl.text = "NOT A COLOR";
                } else {
                    swatch.setStyle("backgroundColor", colorInt);
                    lbl.text = "#" + toHex(colorInt);
                }
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;
        &lt;mx:Label text="Color name:" /&gt;
        &lt;mx:TextInput id="textInput" /&gt;
        &lt;mx:Button id="button"
                label="Submit"
                click="button_click()" /&gt;
    &lt;/mx:ApplicationControlBar&gt;

    &lt;mx:HBox&gt;
        &lt;mx:Box id="swatch"
                width="{lbl.height}"
                height="{lbl.height}" /&gt;

        &lt;mx:Label id="lbl"
                selectable="true"
                fontFamily="_typewriter"
                fontSize="64" /&gt;
    &lt;/mx:HBox&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/StyleManager_getColorName_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/StyleManager_getColorName_test/bin/main.html" width="100%" height="160"></iframe></p>
<p>The following example takes a comma separated list of color names and converts them into color values using the static <code>StyleManager.getColorName()</code> method within a data grid column&#8217;s label function:</p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/StyleManager_getColorName_test_2/main.mxml">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2007/09/06/converting-color-names-to-numbers-using-the-stylemanager-class/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.controls.dataGridClasses.DataGridColumn;
            import mx.styles.StyleManager;
            import mx.utils.StringUtil;

            private const DELIM:String = ",";

            private function toHex(item:Object):String {
                var hex:String = Number(item).toString(16);
                return ("00000" + hex.toUpperCase()).substr(-6);
            }

            private function button_click():void {
                var colorStr:String = StringUtil.trimArrayElements(textInput.text, DELIM);
                dataGrid.dataProvider = colorStr.split(DELIM);
            }

            private function nameFunc(item:Object, column:DataGridColumn):String {
                return item.toString();
            }

            private function colorFunc(item:Object, column:DataGridColumn):String {
                var colorInt:uint = StyleManager.getColorName(item);
                if (colorInt == StyleManager.NOT_A_COLOR) {
                    return "NOT A COLOR";
                } else {
                    return "#" + toHex(colorInt);
                }
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;
        &lt;mx:Label text="Color names:" /&gt;
        &lt;mx:TextInput id="textInput" /&gt;
        &lt;mx:Button id="button"
                label="Submit"
                click="button_click()" /&gt;
    &lt;/mx:ApplicationControlBar&gt;

    &lt;mx:DataGrid id="dataGrid" rowHeight="22"&gt;
        &lt;mx:columns&gt;
            &lt;mx:DataGridColumn labelFunction="nameFunc"
                    headerText="Color name:" /&gt;
            &lt;mx:DataGridColumn labelFunction="colorFunc"
                    headerText="Color value:" /&gt;
        &lt;/mx:columns&gt;
    &lt;/mx:DataGrid&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/StyleManager_getColorName_test_2/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/StyleManager_getColorName_test_2/bin/main.html" width="100%" height="250"></iframe></p>
<p>Finally, the following example shows how you can convert an entire array of color names to integers at once using the static <code>StyleManager.getColorNames()</code> method:</p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/StyleManager_getColorNames_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/09/06/converting-color-names-to-numbers-using-the-stylemanager-class/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.controls.dataGridClasses.DataGridColumn;
            import mx.styles.StyleManager;
            import mx.utils.StringUtil;

            private const DELIM:String = ",";

            private function toHex(item:Object):String {
                var hex:String = Number(item).toString(16);
                return ("00000" + hex.toUpperCase()).substr(-6);
            }

            private function button_click():void {
                var colorStr:String = StringUtil.trimArrayElements(textInput.text, DELIM);
                var colorArr:Array = colorStr.split(DELIM);
                StyleManager.getColorNames(colorArr);

                dataGrid.dataProvider = colorArr;
            }

            private function nameFunc(item:Object, column:DataGridColumn):String {
                return item.toString();
            }

            private function colorFunc(item:Object, column:DataGridColumn):String {
                if (isNaN(Number(item))) {
                    return "NOT A COLOR";
                } else {
                    return "#" + toHex(item);
                }
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;
        &lt;mx:Label text="Color names:" /&gt;
        &lt;mx:TextInput id="textInput" /&gt;
        &lt;mx:Button id="button"
                label="Submit"
                click="button_click()" /&gt;
    &lt;/mx:ApplicationControlBar&gt;

    &lt;mx:DataGrid id="dataGrid" rowHeight="22"&gt;
        &lt;mx:columns&gt;
            &lt;mx:DataGridColumn labelFunction="nameFunc"
                    headerText="Color value (int):"
                    width="140" /&gt;
            &lt;mx:DataGridColumn labelFunction="colorFunc"
                    headerText="Color value (hex):"
                    width="140" /&gt;
        &lt;/mx:columns&gt;
    &lt;/mx:DataGrid&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/StyleManager_getColorNames_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/StyleManager_getColorNames_test/bin/main.html" width="100%" height="250"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Converting color names to numbers using the StyleManager class on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/09/06/converting-color-names-to-numbers-using-the-stylemanager-class/',contentID: 'post-158',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'getColorName(),getColorNames(),trimArrayElements()',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/09/06/converting-color-names-to-numbers-using-the-stylemanager-class/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

