3 Replies Latest reply on Oct 27, 2009 10:18 PM by osurikiran

    Flex 4

    osurikiran

      Hi

      I am working with TextLayoutFramework , i am rendering text using text flow and sprite component data is loading from the xml file.

      My problem is how to get the functionality like MSoffice powerpoint presentation text block, when i click on a text block the all words in the highlighted ,should be selected and when i type the new words should be replace the all words in the highlighter text block

       

      Thanks & regards

      Kiran

        • 1. Re: Flex 4
          matthew horn Level 3

          You can use the selectAll() method, triggered off of the click event, like this:

           

          <?xml version="1.0"?>
          <!-- textcontrols/SparkSelectionExample.mxml -->
          <s:Application
              xmlns:fx="http://ns.adobe.com/mxml/2009"
              xmlns:mx="library://ns.adobe.com/flex/halo"
              xmlns:s="library://ns.adobe.com/flex/spark">

           

              <fx:Script>
                  <![CDATA[
                      private function selectAllText():void {
                          richTxt1.selectAll();
                      }
                  ]]>
              </fx:Script>
             
                  <s:RichEditableText id="richTxt1" textAlign="justify" percentWidth="100" click="selectAllText()">
                      <s:textFlow>
                          <s:TextFlow>
                              <s:p>1) Lorem ipsum dolor sit amet, consectetur adipiscing elit.</s:p>
                              <s:p>2) Cras posuere posuere sem, eu congue orci mattis quis.</s:p>
                              <s:p>3) Curabitur pulvinar tellus venenatis ipsum tempus lobortis.</s:p>
                          </s:TextFlow>
                      </s:textFlow>
                  </s:RichEditableText>
          </s:Application>

           

          hth,

          matt horn

          flex docs

          1 person found this helpful
          • 2. Re: Flex 4
            matthew horn Level 3

            I worked up a slightly better example, that shows how you can use the selection and TLF API to select individual spans within a single textflow. Here it is:

             

            <?xml version="1.0"?>
            <!-- textcontrols/SparkSelectionExample.mxml -->
            <s:Application
                xmlns:fx="http://ns.adobe.com/mxml/2009"
                xmlns:mx="library://ns.adobe.com/flex/halo"
                xmlns:s="library://ns.adobe.com/flex/spark">

                <s:layout>
                    <s:VerticalLayout/>
                </s:layout>

                <fx:Script>
                    <![CDATA[
                        import flashx.textLayout.elements.TextRange;
                        import flashx.textLayout.elements.*;

                        private function selectSomeText(e:Event):void {
                            var activePos:int = richTxt1.selectionActivePosition;

                            var leaf:SpanElement = new SpanElement();
                            leaf = SpanElement(richTxt1.textFlow.getFirstLeaf());
                            var spanStart:int = leaf.getParagraph().parentRelativeStart;
                            var spanEnd:int = leaf.getParagraph().parentRelativeEnd;
                           
                            if (activePos >= spanStart && activePos <= spanEnd) {
                                selectSpan(spanStart, spanEnd);
                                return;
                            }

                            while(leaf = SpanElement(leaf.getNextLeaf())) {                   
                                spanStart = leaf.getParagraph().parentRelativeStart;
                                spanEnd = leaf.getParagraph().parentRelativeEnd;
                                if (activePos >= spanStart && activePos <= spanEnd) {
                                    selectSpan(spanStart, spanEnd);                       
                                    return;
                                }
                            }
                        }

                        private function selectSpan(i1:int, i2:int):void {
                            richTxt1.selectRange(i1, i2);           
                        }
                                           
                    ]]>
                </fx:Script>
               
                <s:Panel>
                    <s:RichEditableText id="richTxt1" click="selectSomeText(event)" selectable="true" editable="true" textAlign="justify" percentWidth="100">
                        <s:textFlow>
                            <s:TextFlow>
                                <s:p><s:span>1) Lorem ipsum dolor sit amet, consectetur adipiscing elit.</s:span></s:p>
                                <s:p><s:span>2) Cras posuere posuere sem, eu congue orci mattis quis.</s:span></s:p>
                                <s:p><s:span>3) Curabitur pulvinar tellus venenatis ipsum tempus lobortis.</s:span></s:p>
                            </s:TextFlow>
                        </s:textFlow>
                    </s:RichEditableText>
                </s:Panel>

            </s:Application>

             

             

            hth,

             

            matt horn

            flex docs

            1 person found this helpful
            • 3. Re: Flex 4
              osurikiran Level 1

              Thank you for replying

               

              your explanation is close to my problem. can you try with the Sprite, and TextFlow  instead of  S:RichEditableText  because i am using the Sprite  as container and text flow imports data from the xml file.

               

              my current TLF information is

              TLF version: 1.0

              TLF Build number: 427 (699527)

              TLF Audit id: <AdobeIP 0000486>

               

              Thanks & Regards

              kiran