<?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; setSelection()</title>
	<atom:link href="http://blog.flexexamples.com/tag/setselection/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>Programmatically selecting text in an FxTextArea control in Flex Gumbo</title>
		<link>http://blog.flexexamples.com/2008/11/16/programmatically-selecting-text-in-an-fxtextarea-control-in-flex-gumbo/</link>
		<comments>http://blog.flexexamples.com/2008/11/16/programmatically-selecting-text-in-an-fxtextarea-control-in-flex-gumbo/#comments</comments>
		<pubDate>Mon, 17 Nov 2008 07:57:29 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[beta]]></category>
		<category><![CDATA[FxTextArea]]></category>
		<category><![CDATA[Gumbo]]></category>
		<category><![CDATA[selectionActivePosition]]></category>
		<category><![CDATA[selectionAnchorPosition]]></category>
		<category><![CDATA[setSelection()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2008/11/16/programmatically-selecting-text-in-an-fxtextarea-control-in-flex-gumbo/</guid>
		<description><![CDATA[<p>The following example shows how you can use ActionScript to select text in a Flex Gumbo FxTextArea control by calling the setSelection() method. This example also shows how you can determine the current text selection&#8217;s anchor position and active position by using the selectionAnchorPosition and selectionActivePosition properties.</p> <p>Full code after the jump.</p> <p></p> <p class="download"><a [...]]]></description>
			<content:encoded><![CDATA[<p>The following example shows how you can use ActionScript to select text in a Flex Gumbo FxTextArea control by calling the <code>setSelection()</code> method. This example also shows how you can determine the current text selection&#8217;s anchor position and active position by using the <code>selectionAnchorPosition</code> and <code>selectionActivePosition</code> properties.</p>
<p>Full code after the jump.</p>
<p><span id="more-866"></span></p>
<p class="download"><a href="">View MXML</a></p>
<pre class="code">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;!-- http://blog.flexexamples.com/2008/11/16/programmatically-selecting-text-in-an-fxtextarea-control-in-flex-gumbo/ --&gt;
&lt;Application name=&quot;FxTextArea_setSelection_test&quot;
        xmlns=&quot;http://ns.adobe.com/mxml/2009&quot;
        layout=&quot;vertical&quot;
        verticalAlign=&quot;middle&quot;
        backgroundColor=&quot;white&quot;&gt;

    &lt;Script&gt;
        &lt;![CDATA[
            import mx.events.FlexEvent;
            import mx.events.SliderEvent;

            private function slider_change(evt:SliderEvent):void {
                var anchorIdx:uint = slider.values[0];
                var activeIdx:uint = slider.values[1];
                textArea.setSelection(anchorIdx, activeIdx);
            }

            private function textArea_selectionChange(evt:FlexEvent):void {
                var anchorIdx:uint = textArea.selectionAnchorPosition;
                var activeIdx:uint = textArea.selectionActivePosition;
                slider.values = [anchorIdx, activeIdx];
            }
        ]]&gt;
    &lt;/Script&gt;

    &lt;ApplicationControlBar dock=&quot;true&quot;&gt;
        &lt;Form styleName=&quot;plain&quot;&gt;
            &lt;FormItem label=&quot;setSelection():&quot;&gt;
                &lt;HSlider id=&quot;slider&quot;
                        minimum=&quot;0&quot;
                        maximum=&quot;{textArea.text.length}&quot;
                        thumbCount=&quot;2&quot;
                        snapInterval=&quot;1&quot;
                        liveDragging=&quot;true&quot;
                        allowThumbOverlap=&quot;true&quot;
                        showTrackHighlight=&quot;true&quot;
                        change=&quot;slider_change(event);&quot; /&gt;
            &lt;/FormItem&gt;
            &lt;FormItem label=&quot;selectionAnchorPosition:&quot;&gt;
                &lt;Label text=&quot;{textArea.selectionAnchorPosition}&quot; /&gt;
            &lt;/FormItem&gt;
            &lt;FormItem label=&quot;selectionActivePosition:&quot;&gt;
                &lt;Label text=&quot;{textArea.selectionActivePosition}&quot; /&gt;
            &lt;/FormItem&gt;
        &lt;/Form&gt;
    &lt;/ApplicationControlBar&gt;

    &lt;FxTextArea id=&quot;textArea&quot;
            text=&quot;The quick brown fox jumps over the lazy dog&quot;
            selectionVisibility=&quot;always&quot;
            unfocusedSelectionColor=&quot;0xFF0000&quot;
            selectionChange=&quot;textArea_selectionChange(event);&quot; /&gt;

&lt;/Application&gt;
</pre>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Programmatically selecting text in an FxTextArea control in Flex Gumbo on FlexExamples.com',url: 'http://blog.flexexamples.com/2008/11/16/programmatically-selecting-text-in-an-fxtextarea-control-in-flex-gumbo/',contentID: 'post-866',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'Gumbo,selectionActivePosition,selectionAnchorPosition,setSelection()',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/2008/11/16/programmatically-selecting-text-in-an-fxtextarea-control-in-flex-gumbo/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Setting text selection on a TextArea control in Flex</title>
		<link>http://blog.flexexamples.com/2008/04/25/setting-text-selection-on-a-textarea-control-in-flex/</link>
		<comments>http://blog.flexexamples.com/2008/04/25/setting-text-selection-on-a-textarea-control-in-flex/#comments</comments>
		<pubDate>Sat, 26 Apr 2008 06:50:41 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[TextArea]]></category>
		<category><![CDATA[alwaysShowSelection]]></category>
		<category><![CDATA[getTextField()]]></category>
		<category><![CDATA[selectionBeginIndex]]></category>
		<category><![CDATA[selectionEndIndex]]></category>
		<category><![CDATA[setSelection()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2008/04/25/setting-text-selection-on-a-textarea-control-in-flex/</guid>
		<description><![CDATA[<p>The following example shows how you can set the selected text in a Flex TextArea control by using the setSelection() method.</p> <p>Full code after the jump.</p> <p></p> <p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/TextArea_setSelection_test/bin/srcview/source/main.mxml.html">View MXML</a></p> &#60;?xml version="1.0" encoding="utf-8"?&#62; &#60;!-- http://blog.flexexamples.com/2008/04/25/setting-text-selection-on-a-textarea-control-in-flex/ --&#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[ import mx.core.IUITextField; import mx.events.SliderEvent; import mx.controls.sliderClasses.Slider; private function slider_change(evt:SliderEvent):void { var [...]]]></description>
			<content:encoded><![CDATA[<p>The following example shows how you can set the selected text in a Flex TextArea control by using the <code>setSelection()</code> method.</p>
<p>Full code after the jump.</p>
<p><span id="more-608"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/TextArea_setSelection_test/bin/srcview/source/main.mxml.html">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2008/04/25/setting-text-selection-on-a-textarea-control-in-flex/ --&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.core.IUITextField;
            import mx.events.SliderEvent;
            import mx.controls.sliderClasses.Slider;

            private function slider_change(evt:SliderEvent):void {
                var value1:int = Slider(evt.currentTarget).values[0];
                var value2:int = Slider(evt.currentTarget).values[1];
                var min:int = Math.min(value1, value2);
                var max:int = Math.max(value1, value2);
                textArea.setSelection(min, max);
            }

            private function init():void {
                var tf:IUITextField = textArea.mx_internal::getTextField();
                tf.alwaysShowSelection = true;
                textArea.verticalScrollPosition = 0;
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:String id="lorem" source="lorem.html" /&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;
        &lt;mx:Form styleName="plain"&gt;
            &lt;mx:FormItem label="setSelection():"&gt;
                &lt;mx:HSlider id="slider"
                        minimum="0"
                        maximum="{textArea.htmlText.length}"
                        thumbCount="2"
                        liveDragging="true"
                        allowThumbOverlap="true"
                        snapInterval="1"
                        dataTipPrecision="0"
                        change="slider_change(event);" /&gt;
            &lt;/mx:FormItem&gt;
        &lt;/mx:Form&gt;
    &lt;/mx:ApplicationControlBar&gt;

    &lt;mx:TextArea id="textArea"
            htmlText="{lorem}"
            textAlign="justify"
            condenseWhite="true"
            width="100%"
            height="100%"
            creationComplete="init();" /&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/TextArea_setSelection_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/TextArea_setSelection_test/bin/main.html" width="100%" height="350"></iframe></p>
<p>You can also set the selected text in a TextArea control by setting the <code>selectionBeginIndex</code> and <code>selectionEndIndex</code> properties, as seen in the following example:</p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/TextArea_selectionBeginIndex_test/bin/srcview/source/main.mxml.html">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2008/04/25/setting-text-selection-on-a-textarea-control-in-flex/ --&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.core.IUITextField;
            import mx.events.SliderEvent;
            import mx.controls.sliderClasses.Slider;

            private function slider_change(evt:SliderEvent):void {
                textArea.selectionBeginIndex = beginSlider.value;
                textArea.selectionEndIndex = endSlider.value;

                textArea.validateNow();
                beginLabel.text = textArea.selectionBeginIndex.toString();
                endLabel.text = textArea.selectionEndIndex.toString();
            }

            private function init():void {
                var tf:IUITextField = textArea.mx_internal::getTextField();
                tf.alwaysShowSelection = true;
                textArea.verticalScrollPosition = 0;
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:String id="lorem" source="lorem.html" /&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;
        &lt;mx:Form styleName="plain"&gt;
            &lt;mx:FormItem label="selectionBeginIndex:"
                    direction="horizontal"&gt;
                &lt;mx:HSlider id="beginSlider"
                        minimum="0"
                        maximum="{textArea.htmlText.length}"
                        value="0"
                        liveDragging="true"
                        change="slider_change(event);" /&gt;
                &lt;mx:Label id="beginLabel" /&gt;
            &lt;/mx:FormItem&gt;
            &lt;mx:FormItem label="selectionEndIndex:"
                    direction="horizontal"&gt;
                &lt;mx:HSlider id="endSlider"
                        minimum="0"
                        maximum="{textArea.htmlText.length}"
                        value="0"
                        snapInterval="1"
                        liveDragging="true"
                        change="slider_change(event);" /&gt;
                &lt;mx:Label id="endLabel" /&gt;
            &lt;/mx:FormItem&gt;
        &lt;/mx:Form&gt;
    &lt;/mx:ApplicationControlBar&gt;

    &lt;mx:TextArea id="textArea"
            htmlText="{lorem}"
            textAlign="justify"
            condenseWhite="true"
            width="100%"
            height="100%"
            creationComplete="init();" /&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/TextArea_selectionBeginIndex_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/TextArea_selectionBeginIndex_test/bin/main.html" width="100%" height="350"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Setting text selection on a TextArea control in Flex on FlexExamples.com',url: 'http://blog.flexexamples.com/2008/04/25/setting-text-selection-on-a-textarea-control-in-flex/',contentID: 'post-608',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'alwaysShowSelection,getTextField(),selectionBeginIndex,selectionEndIndex,setSelection()',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/2008/04/25/setting-text-selection-on-a-textarea-control-in-flex/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Converting an ImageSnapshot object into a Base-64 encoded string in Flex 3</title>
		<link>http://blog.flexexamples.com/2007/12/07/converting-an-imagesnapshot-object-into-a-base-64-encoded-string-in-flex-3/</link>
		<comments>http://blog.flexexamples.com/2007/12/07/converting-an-imagesnapshot-object-into-a-base-64-encoded-string-in-flex-3/#comments</comments>
		<pubDate>Sat, 08 Dec 2007 06:32:25 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[ImageSnapshot]]></category>
		<category><![CDATA[captureImage()]]></category>
		<category><![CDATA[encodeImageAsBase64()]]></category>
		<category><![CDATA[setClipboard()]]></category>
		<category><![CDATA[setSelection()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/12/07/converting-an-imagesnapshot-object-into-a-base-64-encoded-string-in-flex-3/</guid>
		<description><![CDATA[<p>The following example shows how you can convert an ImageSnapshot object into a Base-64 encoded string using Flex 3&#8242;s cleverly named encodeImageAsBase64() method.</p> <p>Full code after the jump.</p> <p></p> <p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/ImageSnapshot_encodeImageAsBase64_test/main.mxml">View MXML</a></p> &#60;?xml version="1.0" encoding="utf-8"?&#62; &#60;!-- http://blog.flexexamples.com/2007/12/07/converting-an-imagesnapshot-object-into-a-base-64-encoded-string-in-flex-3/ --&#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[ import flash.events.FocusEvent; import flash.system.System; import mx.graphics.ImageSnapshot; private function button_click(evt:MouseEvent):void [...]]]></description>
			<content:encoded><![CDATA[<p>The following example shows how you can convert an ImageSnapshot object into a Base-64 encoded string using Flex 3&#8242;s cleverly named <code>encodeImageAsBase64()</code> method.</p>
<p>Full code after the jump.</p>
<p><span id="more-354"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/ImageSnapshot_encodeImageAsBase64_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/12/07/converting-an-imagesnapshot-object-into-a-base-64-encoded-string-in-flex-3/ --&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 flash.events.FocusEvent;
            import flash.system.System;
            import mx.graphics.ImageSnapshot;

            private function button_click(evt:MouseEvent):void {
                var ohSnap:ImageSnapshot = ImageSnapshot.captureImage(img);
                textArea.text = ImageSnapshot.encodeImageAsBase64(ohSnap);
            }

            private function textArea_focusIn(evt:FocusEvent):void {
                textArea.setSelection(0, textArea.text.length);
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;
        &lt;mx:Button label="Capture and encode"
                click="button_click(event);" /&gt;
    &lt;/mx:ApplicationControlBar&gt;

    &lt;mx:Form&gt;
        &lt;mx:FormItem label="source:"&gt;
            &lt;mx:Image id="img"
                    source="@Embed('images/flex_logo.jpg')" /&gt;
        &lt;/mx:FormItem&gt;
        &lt;mx:FormItem label="Base64:"&gt;
            &lt;mx:TextArea id="textArea"
                    editable="false"
                    showScrollTips="true"
                    width="320"
                    height="160"
                    focusIn="textArea_focusIn(event);" /&gt;
        &lt;/mx:FormItem&gt;
        &lt;mx:FormItem&gt;
            &lt;mx:Button label="Copy to clipboard"
                    enabled="{textArea.text.length &gt; 0}"
                    click="System.setClipboard(textArea.text);" /&gt;
        &lt;/mx:FormItem&gt;
    &lt;/mx:Form&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/ImageSnapshot_encodeImageAsBase64_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/ImageSnapshot_encodeImageAsBase64_test/bin/main.html" width="100%" height="400"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Converting an ImageSnapshot object into a Base-64 encoded string in Flex 3 on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/12/07/converting-an-imagesnapshot-object-into-a-base-64-encoded-string-in-flex-3/',contentID: 'post-354',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'captureImage(),encodeImageAsBase64(),setClipboard(),setSelection()',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/12/07/converting-an-imagesnapshot-object-into-a-base-64-encoded-string-in-flex-3/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

