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>
