<?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; RGB</title>
	<atom:link href="http://blog.flexexamples.com/category/rgb/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>Converting and formatting colors</title>
		<link>http://blog.flexexamples.com/2007/08/13/converting-and-formatting-colors/</link>
		<comments>http://blog.flexexamples.com/2007/08/13/converting-and-formatting-colors/#comments</comments>
		<pubDate>Tue, 14 Aug 2007 06:15:32 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Color]]></category>
		<category><![CDATA[ColorPicker]]></category>
		<category><![CDATA[HEX]]></category>
		<category><![CDATA[RGB]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/08/13/converting-and-formatting-colors/</guid>
		<description><![CDATA[<p>Here&#8217;s a quick post on converting some colors from strings to integers, and splitting colors into separate red/green/blue values, and formatting colors using Flex.</p> <p>Full code after the jump.</p> <p></p> <p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/ColorPicker_selectedColor_test/main.mxml">View MXML</a></p> &#60;?xml version="1.0" encoding="utf-8"?&#62; &#60;!-- http://blog.flexexamples.com/2007/08/13/converting-and-formatting-colors/ --&#62; &#60;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white"&#62; &#60;mx:Script&#62; &#60;![CDATA[ private function fixedInt(value:int, mask:String):String { return String(mask + [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quick post on converting some colors from strings to integers, and splitting colors into separate red/green/blue values, and formatting colors using Flex.</p>
<p>Full code after the jump.</p>
<p><span id="more-84"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/ColorPicker_selectedColor_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/13/converting-and-formatting-colors/ --&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[
            private function fixedInt(value:int, mask:String):String {
                return String(mask + value.toString(16)).substr(-mask.length).toUpperCase();
            }

            private function rChannel(value:int):int {
                return value &gt;&gt; 16 &#038; 0xFF;
            }

            private function gChannel(value:int):int {
                return value &gt;&gt; 8 &#038; 0xFF;
            }

            private function bChannel(value:int):int {
                return value &gt;&gt; 0 &#038; 0xFF;
            }

            private function rgbToInt(r:int, g:int, b:int):int {
                return r &lt;&lt; 16 | g &lt;&lt; 8 | b &lt;&lt; 0;
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:Model id="colorObj"&gt;
        &lt;root&gt;
            &lt;color&gt;{colorPicker.selectedColor}&lt;/color&gt;
            &lt;red&gt;{rChannel(colorObj.color)}&lt;/red&gt;
            &lt;green&gt;{gChannel(colorObj.color)}&lt;/green&gt;
            &lt;blue&gt;{bChannel(colorObj.color)}&lt;/blue&gt;
        &lt;/root&gt;
    &lt;/mx:Model&gt;

    &lt;mx:Form&gt;
        &lt;mx:FormItem label="Color:" direction="horizontal"&gt;
            &lt;mx:ColorPicker id="colorPicker" /&gt;
            &lt;mx:Label text="0x{fixedInt(colorPicker.selectedColor, '000000')}" width="100" /&gt;
        &lt;/mx:FormItem&gt;
        &lt;mx:FormItem label="Red:" direction="horizontal"&gt;
            &lt;mx:Label text="{colorObj.red}" /&gt;
            &lt;mx:Label text="(0x{fixedInt(colorObj.red, '00')})" /&gt;
        &lt;/mx:FormItem&gt;
        &lt;mx:FormItem label="Green:" direction="horizontal"&gt;
            &lt;mx:Label text="{colorObj.green}" /&gt;
            &lt;mx:Label text="(0x{fixedInt(colorObj.green, '00')})" /&gt;
        &lt;/mx:FormItem&gt;
        &lt;mx:FormItem label="Blue:" direction="horizontal"&gt;
            &lt;mx:Label text="{colorObj.blue}" /&gt;
            &lt;mx:Label text="(0x{fixedInt(colorObj.blue, '00')})" /&gt;
        &lt;/mx:FormItem&gt;
        &lt;mx:FormItem label="Color:" direction="horizontal"&gt;
            &lt;mx:Label text="{colorObj.color}" /&gt;
            &lt;mx:Label text="(0x{fixedInt(rgbToInt(colorObj.red, colorObj.green, colorObj.blue), '000000')})" /&gt;
        &lt;/mx:FormItem&gt;
    &lt;/mx:Form&gt;

    &lt;mx:Label text="{int(0xFF00FF)}" /&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/ColorPicker_selectedColor_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/ColorPicker_selectedColor_test/bin/main.html" width="100%" height="250"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Converting and formatting colors on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/08/13/converting-and-formatting-colors/',contentID: 'post-84',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: '',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/13/converting-and-formatting-colors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

