<?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; adjustBrightness2()</title>
	<atom:link href="http://blog.flexexamples.com/tag/adjustbrightness2/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>Adjusting a color&#8217;s brightness using the ColorUtil class</title>
		<link>http://blog.flexexamples.com/2007/08/24/adjusting-a-colors-brightness-using-the-colorutil-class/</link>
		<comments>http://blog.flexexamples.com/2007/08/24/adjusting-a-colors-brightness-using-the-colorutil-class/#comments</comments>
		<pubDate>Sat, 25 Aug 2007 06:16:53 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[ColorUtil]]></category>
		<category><![CDATA[adjustBrightness()]]></category>
		<category><![CDATA[adjustBrightness2()]]></category>
		<category><![CDATA[selectedColor]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/08/24/adjusting-a-colors-brightness-using-the-colorutil-class/</guid>
		<description><![CDATA[<p>Here&#8217;s a handy little trick, compliments of the ColorUtil class. The ColorUtil class has a couple useful methods if you ever need to change a color&#8217;s brightness using either a linear brightness adjustment (ColorUtil.adjustBrightness()) or a scaled brightness adjustment (ColorUtil.adjustBrightness2()). Mind you, I have no idea what that linear brightness versus scaled brightness actually means, [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a handy little trick, compliments of the ColorUtil class. The ColorUtil class has a couple useful methods if you ever need to change a color&#8217;s brightness using either a linear brightness adjustment (<code>ColorUtil.adjustBrightness()</code>) or a scaled brightness adjustment (<code>ColorUtil.adjustBrightness2()</code>). Mind you, I have no idea what that linear brightness versus scaled brightness actually means, so I&#8217;ll show both methods side-by-side.</p>
<p><span id="more-128"></span></p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- http://blog.flexexamples.com/2007/08/24/adjusting-a-colors-brightness-using-the-colorutil-class/ --&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Application</span> xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span></span>
<span style="color: #000000;">        layout=<span style="color: #ff0000;">&quot;vertical&quot;</span></span>
<span style="color: #000000;">        verticalAlign=<span style="color: #ff0000;">&quot;top&quot;</span></span>
<span style="color: #000000;">        backgroundColor=<span style="color: #ff0000;">&quot;white&quot;</span></span>
<span style="color: #000000;">        creationComplete=<span style="color: #ff0000;">&quot;changeColorChip()&quot;</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;">        &lt;![CDATA[</span>
<span style="color: #339933;">            import mx.utils.ColorUtil;</span>
&nbsp;
<span style="color: #339933;">            private function changeColorChip():void {</span>
<span style="color: #339933;">                /* ColorUtil.adjustBrightness() takes a bright</span>
<span style="color: #339933;">                    parameter between -255 and +255. */</span>
<span style="color: #339933;">                brite1 = slider.value;</span>
<span style="color: #339933;">                /* ColorUtil.adjustBrightness2() takes a bright</span>
<span style="color: #339933;">                    parameter between -100 and +100. */</span>
<span style="color: #339933;">                brite2 = int(slider.value / 255 * 100);</span>
&nbsp;
<span style="color: #339933;">                var adjustedColor1:uint = ColorUtil.adjustBrightness(rgb, brite1);</span>
<span style="color: #339933;">                var adjustedColor2:uint = ColorUtil.adjustBrightness2(rgb, brite2);</span>
&nbsp;
<span style="color: #339933;">                colorStr1 = rgbToHex(adjustedColor1);</span>
<span style="color: #339933;">                box1.setStyle(&quot;backgroundColor&quot;, adjustedColor1);</span>
&nbsp;
<span style="color: #339933;">                colorStr2 = rgbToHex(adjustedColor2);</span>
<span style="color: #339933;">                box2.setStyle(&quot;backgroundColor&quot;, adjustedColor2);</span>
<span style="color: #339933;">            }</span>
&nbsp;
<span style="color: #339933;">            private function rgbToHex(value:uint):String {</span>
<span style="color: #339933;">                var str:String = value.toString(16).toUpperCase();</span>
<span style="color: #339933;">                str = String(&quot;000000&quot; + str).substr(-6);</span>
<span style="color: #339933;">                return str;</span>
<span style="color: #339933;">            }</span>
&nbsp;
<span style="color: #339933;">            private function reset():void {</span>
<span style="color: #339933;">                colorPicker.selectedIndex = 0;</span>
<span style="color: #339933;">                slider.value = 0;</span>
<span style="color: #339933;">                changeColorChip();</span>
<span style="color: #339933;">            }</span>
<span style="color: #339933;">        ]]&gt;</span>
<span style="color: #339933;">    &lt;/mx:Script&gt;</span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Number</span> id=<span style="color: #ff0000;">&quot;rgb&quot;</span><span style="color: #7400FF;">&gt;</span></span>{colorPicker.selectedColor}<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Number</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Number</span> id=<span style="color: #ff0000;">&quot;brite1&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Number</span> id=<span style="color: #ff0000;">&quot;brite2&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:String</span> id=<span style="color: #ff0000;">&quot;colorStr1&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:String</span> id=<span style="color: #ff0000;">&quot;colorStr2&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:String</span> id=<span style="color: #ff0000;">&quot;lbl1&quot;</span><span style="color: #7400FF;">&gt;</span></span>adjustBrightness(0x{rgbToHex(rgb)}, {brite1}) = 0x{colorStr1}<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:String</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:String</span> id=<span style="color: #ff0000;">&quot;lbl2&quot;</span><span style="color: #7400FF;">&gt;</span></span>adjustBrightness2(0x{rgbToHex(rgb)}, {brite2}) = 0x{colorStr2}<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:String</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:ApplicationControlBar</span> dock=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Label</span> text=<span style="color: #ff0000;">&quot;RGB:&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:ColorPicker</span> id=<span style="color: #ff0000;">&quot;colorPicker&quot;</span></span>
<span style="color: #000000;">                change=<span style="color: #ff0000;">&quot;changeColorChip()&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Spacer</span> width=<span style="color: #ff0000;">&quot;20&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Label</span> text=<span style="color: #ff0000;">&quot;Brightness:&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:HSlider</span> id=<span style="color: #ff0000;">&quot;slider&quot;</span></span>
<span style="color: #000000;">                minimum=<span style="color: #ff0000;">&quot;-255&quot;</span></span>
<span style="color: #000000;">                maximum=<span style="color: #ff0000;">&quot;255&quot;</span></span>
<span style="color: #000000;">                value=<span style="color: #ff0000;">&quot;0&quot;</span></span>
<span style="color: #000000;">                liveDragging=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #000000;">                snapInterval=<span style="color: #ff0000;">&quot;1&quot;</span></span>
<span style="color: #000000;">                tickInterval=<span style="color: #ff0000;">&quot;5&quot;</span></span>
<span style="color: #000000;">                dataTipPrecision=<span style="color: #ff0000;">&quot;0&quot;</span></span>
<span style="color: #000000;">                width=<span style="color: #ff0000;">&quot;100%&quot;</span></span>
<span style="color: #000000;">                change=<span style="color: #ff0000;">&quot;changeColorChip()&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Spacer</span> width=<span style="color: #ff0000;">&quot;20&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> label=<span style="color: #ff0000;">&quot;Reset&quot;</span></span>
<span style="color: #000000;">            click=<span style="color: #ff0000;">&quot;reset()&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:ApplicationControlBar</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:HBox</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:VBox</span> width=<span style="color: #ff0000;">&quot;50%&quot;</span> height=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Label</span> text=<span style="color: #ff0000;">&quot;{lbl1}&quot;</span></span>
<span style="color: #000000;">                selectable=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Box</span> id=<span style="color: #ff0000;">&quot;box1&quot;</span></span>
<span style="color: #000000;">                    width=<span style="color: #ff0000;">&quot;100%&quot;</span></span>
<span style="color: #000000;">                    height=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:VBox</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:VBox</span> width=<span style="color: #ff0000;">&quot;50%&quot;</span> height=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Label</span> text=<span style="color: #ff0000;">&quot;{lbl2}&quot;</span></span>
<span style="color: #000000;">                selectable=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Box</span> id=<span style="color: #ff0000;">&quot;box2&quot;</span></span>
<span style="color: #000000;">                    width=<span style="color: #ff0000;">&quot;100%&quot;</span></span>
<span style="color: #000000;">                    height=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:VBox</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:HBox</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/ColorUtil_adjustBrightness_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/ColorUtil_adjustBrightness_test/bin/main.html" width="100%" height="300"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Adjusting a color\&#039;s brightness using the ColorUtil class on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/08/24/adjusting-a-colors-brightness-using-the-colorutil-class/',contentID: 'post-128',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'adjustBrightness(),adjustBrightness2(),selectedColor',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/24/adjusting-a-colors-brightness-using-the-colorutil-class/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

