2 Replies Latest reply on Feb 13, 2012 7:02 AM by Maximist

    How to get the selected text in a TextInput

    Maximist Level 1

      Hallo. I have a textinput and when the doubleclick event on part of the text is dispatched, i need to get the selected text and save it in a string.. How can i do that?

       

      Thx

       

      Max

        • 1. Re: How to get the selected text in a TextInput
          Pooja Kuber Level 2

          Hi Maximist,

           

          Please find below the code snippet to get selected text in TextInput on double click event:

           

          <?xml version="1.0" encoding="utf-8"?>

          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"

                  layout="vertical"

                  verticalAlign="middle"

                  backgroundColor="white">

           

              <mx:Script>

                  <![CDATA[

                      import mx.controls.Alert;

                      private function textInput_doubleClick(evt:MouseEvent):void {

                          Alert.show(String(evt.target.text).slice(evt.target.selectionBeginIndex,evt.target.select ionEndIndex));

                        

                      }

                  ]]>

              </mx:Script>

           

              <mx:TextInput id="textInput"

                      text="The toreador stepped out of the path of the charging bull at the last possible moment, drawing cheers from the spectators."

                      doubleClickEnabled="true"

                      doubleClick="textInput_doubleClick(event);" />

           

          </mx:Application>

           

          Hope this will help you.

           

          Thanks and Regards

          ------------------------------------------------------------------------------------

          Pooja Kuber | pkuber@infocepts.com | www.infocepts.com

          ------------------------------------------------------------------------------------

          • 2. Re: How to get the selected text in a TextInput
            Maximist Level 1

            Really really thx

             

            Max