Skip to main content
JabbyPandaUA
Inspiring
February 2, 2010
Question

Cannot select text via TLF API by using SelectionManager "selectRange" method

  • February 2, 2010
  • 1 reply
  • 2017 views

I am on Flex 4.0.13654 SDK from Jan 20 2010.

The following 50 lines of code illustrate 4 different methods to select text, including

1)  calling "selectAll" method on s:TextInput component creation,

2)  calling "selectRange" method on SelectionManager

3) applying instance of SelectionState to SelectionManager

4) calling "selectAll" method on SelectionManager

all failed

<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"                xmlns:s="library://ns.adobe.com/flex/spark"                xmlns:mx="library://ns.adobe.com/flex/halo"                minWidth="1024" minHeight="768">     <fx:Script>         <![CDATA[             import flashx.textLayout.edit.EditManager;             import flashx.textLayout.edit.SelectionManager;             import flashx.textLayout.edit.SelectionState;             import flashx.textLayout.elements.TextRange;             import flashx.textLayout.events.SelectionEvent;             import flashx.textLayout.formats.ITextLayoutFormat;             import flashx.textLayout.formats.TextLayoutFormat;             import flashx.textLayout.operations.ApplyFormatOperation;             import flashx.undo.UndoManager;                         protected function button1_clickHandler(event:MouseEvent):void             {                 rt.textFlow.interactionManager = new SelectionManager();                 rt.textFlow.addEventListener(SelectionEvent.SELECTION_CHANGE, setSelectionRange);                                                                 rt.textFlow.interactionManager.selectRange(0, 2);                                rt.textFlow.interactionManager.refreshSelection();                                                 rt2.textFlow.interactionManager = new SelectionManager();                 rt2.textFlow.addEventListener(SelectionEvent.SELECTION_CHANGE, setSelectionRange);                                 var format:TextLayoutFormat = new TextLayoutFormat();                 format.backgroundColor      = 0xFF99CC;                 format.color                = 0x000000;                                                          var currentSelectionState : SelectionState = new SelectionState(rt2.textFlow, 0, 2, format);                                rt2.textFlow.interactionManager.setSelectionState(currentSelectionState);                                rt2.textFlow.interactionManager.refreshSelection();                                                                 ret.textFlow.interactionManager = new EditManager(new UndoManager());                 ret.textFlow.addEventListener(SelectionEvent.SELECTION_CHANGE, setSelectionRange);                 ret.textFlow.interactionManager.selectAll();                                            }                         private function setSelectionRange(event:SelectionEvent):void             {                 trace ("trace setSelectionRange", event.target.toString());                            }                                            ]]>     </fx:Script>     <fx:Declarations>         <!-- Place non-visual elements (e.g., services, value objects) here -->     </fx:Declarations>        <s:Group left="100" top="100">         <s:layout>             <s:HorizontalLayout>                             </s:HorizontalLayout>         </s:layout>                 <s:TextInput id="ti"                      text="Sample text-1"                      creationComplete="ti.selectAll();"/>                 <s:RichText id="rt" text="Sample text-2">                     </s:RichText>                 <s:RichText id="rt2" text="Sample text-3">                     </s:RichText>         <s:RichEditableText id="ret" text="Sample text-4">                     </s:RichEditableText>         <s:Button label="Apply" click="button1_clickHandler(event)">                     </s:Button>     </s:Group> </s:Application>

This topic has been closed for replies.

1 reply

Adobe Employee
February 2, 2010

As Designed.

From the RichText documentation:

RichText is a low-level UIComponent that can display one or more lines   of richly-formatted text and embedded images.

For performance reasons, it does not support scrolling,   selection, editing, clickable hyperlinks, or images loaded from URLs.   If you need those capabilities, please see the RichEditableText   class.

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/spark/components/RichText.html

JabbyPandaUA
Inspiring
February 2, 2010

This fact expains why case #2 and case #3 had failed because both of them had involved RichText.

But case #1 uses <s:TextInput> components which extends from SkinnableTextBase class that has the following variable declared inside that actually displays  the text:

public var textDisplay:RichEditableText; 

Also, my case#4 uses direct instance of RichEditableText class, but still the programmed selection does not work.

Adobe Employee
February 2, 2010

I believe you should use selectAll and selectRange functions of RichEditableText - the TextFlow returned is not necessarily the one that's actually in use - it may be a transient or a copy.