<?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; TextRange</title>
	<atom:link href="http://blog.flexexamples.com/category/textrange/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 the TextRange class to hightlight text</title>
		<link>http://blog.flexexamples.com/2007/08/01/using-the-textrange-class-to-hightlight-text/</link>
		<comments>http://blog.flexexamples.com/2007/08/01/using-the-textrange-class-to-hightlight-text/#comments</comments>
		<pubDate>Thu, 02 Aug 2007 04:30:53 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[ColorPicker]]></category>
		<category><![CDATA[Slider]]></category>
		<category><![CDATA[SliderEvent]]></category>
		<category><![CDATA[TextRange]]></category>
		<category><![CDATA[textDecoration]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/08/01/using-the-textrange-class-to-hightlight-text/</guid>
		<description><![CDATA[<p>I was working on a mini-app the other night, and was trying to figure out how to color only certain words in a text-based control. After a bit of poking around, I discovered that the TextRange class seems to be the right tool for the job.</p> <p>Full code after the jump.</p> <p></p> <p>The following example [...]]]></description>
			<content:encoded><![CDATA[<p>I was working on a mini-app the other night, and was trying to figure out how to color only certain words in a text-based control. After a bit of poking around, I discovered that the TextRange class seems to be the right tool for the job.</p>
<p>Full code after the jump.</p>
<p><span id="more-44"></span></p>
<p>The following example uses a two-thumb Slider control to let you select a range of text to apply some formatting to. The text color can be controlled using the handy ColorPicker control, and feel free to erase my filler text and try something else. As the text in the TextArea changes, the TextRange and slider gets recalcuated.</p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/TextRange_color_test/main.mxml">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" verticalAlign="middle" backgroundColor="white"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.events.SliderEvent;
            import mx.controls.textClasses.TextRange;

            private var tr:TextRange;

            private function slider_change(evt:SliderEvent):void {
                updateTextRange();
            }

            private function textArea_change(evt:Event):void {
                // Recalculate length.
                slider.maximum = textArea.length;

                updateTextRange();
            }

            private function updateTextRange():void {
                try {
                    /* Default the TextArea control's text color back to black. */
                    tr = new TextRange(textArea);
                    tr.color = "black";
                    tr.textDecoration = "normal";

                    /* Set the text color to red for the values in the Slider. */
                    tr = new TextRange(textArea, false, slider.values[0], slider.values[1]);
                    tr.color = colorPicker.selectedColor;
                    tr.textDecoration = "underline";
                } catch (err:RangeError) {
                    /* Somethin' ain't right! I dare say you have no text, son! */
                }
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:VBox width="380"&gt;
        &lt;mx:HBox&gt;
            &lt;mx:Label text="Text selection color:" /&gt;
            &lt;mx:ColorPicker id="colorPicker" selectedColor="red" /&gt;
        &lt;/mx:HBox&gt;

        &lt;mx:HBox&gt;
            &lt;mx:Label text="Text selection range:" /&gt;
            &lt;mx:HSlider id="slider" thumbCount="2" liveDragging="true" snapInterval="1" dataTipPrecision="0" minimum="0" maximum="{textArea.length}" change="slider_change(event)" /&gt;
            &lt;mx:Label text="({slider.values[0]}, {slider.values[1]})" /&gt;
        &lt;/mx:HBox&gt;

        &lt;mx:TextArea id="textArea" width="100%" height="120" change="textArea_change(event)"&gt;
            &lt;mx:text&gt;&lt;![CDATA[The quick brown fox jumped over the lazy dog.]]&gt;&lt;/mx:text&gt;
        &lt;/mx:TextArea&gt;
    &lt;/mx:VBox&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information">View source enabled in the following example</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/TextRange_color_test/bin/main.html" width="100%" height="250"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Using the TextRange class to hightlight text on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/08/01/using-the-textrange-class-to-hightlight-text/',contentID: 'post-44',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'textDecoration',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/01/using-the-textrange-class-to-hightlight-text/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

