<?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; isColorName()</title>
	<atom:link href="http://blog.flexexamples.com/tag/iscolorname/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>Checking whether a color name is a valid color in Flex using the StyleManager class</title>
		<link>http://blog.flexexamples.com/2007/09/13/checking-whether-a-color-name-is-a-valid-color-in-flex-using-the-stylemanager-class/</link>
		<comments>http://blog.flexexamples.com/2007/09/13/checking-whether-a-color-name-is-a-valid-color-in-flex-using-the-stylemanager-class/#comments</comments>
		<pubDate>Fri, 14 Sep 2007 03:11:49 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[StringUtil]]></category>
		<category><![CDATA[StyleManager]]></category>
		<category><![CDATA[isColorName()]]></category>
		<category><![CDATA[registerColorName()]]></category>
		<category><![CDATA[trim()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/09/13/checking-whether-a-color-name-is-a-valid-color-in-flex-using-the-stylemanager-class/</guid>
		<description><![CDATA[<p>The following example shows how to use the static StyleManager.isColorName() method to check whether a color name is valid or not. This method takes a single parameter, colorName, and returns a Boolean value representing whether the parameter is a valid alias for a color.</p> <p>Full code after the jump.</p> <p></p> <p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/StyleManager_isColorName_test/main.mxml">View MXML</a></p> &#60;?xml [...]]]></description>
			<content:encoded><![CDATA[<p>The following example shows how to use the static <code>StyleManager.isColorName()</code> method to check whether a color name is valid or not. This method takes a single parameter, <code>colorName</code>, and returns a Boolean value representing whether the parameter is a valid alias for a color.</p>
<p>Full code after the jump.</p>
<p><span id="more-176"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/StyleManager_isColorName_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/13/checking-whether-a-color-name-is-a-valid-color-in-flex-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;
            import mx.utils.StringUtil;

            private function button_click(evt:MouseEvent):void {
                /* Remove leading and trailing whitespace. */
                var str:String = StringUtil.trim(textInput.text);
                var isColor:Boolean = StyleManager.isColorName(str);

                /* If it is a valid color, set the background color
                   and remove the error string, if any. Else, set the
                   background color to the constant NOT_A_COLOR from
                   the StyleManager class and set the error string. */
                if (isColor) {
                    box.setStyle("backgroundColor", str);
                    textInput.errorString = "";
                } else {
                    box.setStyle("backgroundColor", StyleManager.NOT_A_COLOR);
                    textInput.errorString = "NOT A COLOR";
                }
            }
        ]]&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 label="isColorName()"
                fontFamily="_sans"
                click="button_click(event);" /&gt;
    &lt;/mx:ApplicationControlBar&gt;

    &lt;mx:Box id="box" width="100%" height="100%" /&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/StyleManager_isColorName_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_isColorName_test/bin/main.html" width="100%" height="200"></iframe></p>
<p class="note">If you want to add your own custom color aliases, you can use the StyleManager class&#8217;s <code>registerColorName()</code> method, as seen in the following snippet:</p>
<pre class="code">
StyleManager.registerColorName('peter', 0x0BCDEF);
trace(StyleManager.isColorName('peter')); // true
</pre>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Checking whether a color name is a valid color in Flex using the StyleManager class on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/09/13/checking-whether-a-color-name-is-a-valid-color-in-flex-using-the-stylemanager-class/',contentID: 'post-176',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'isColorName(),registerColorName(),trim()',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/13/checking-whether-a-color-name-is-a-valid-color-in-flex-using-the-stylemanager-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

