6 Replies Latest reply on Jul 22, 2009 4:57 PM by dave cragg

    getCharBoundaries equivalent in spark text components

    dave cragg Level 2

      Is there an easy way in the new text components to do what getCharBoundaries (in flex.TextField) does? (i.e. get the position of a particular character within a text field)

       

      So far, all I've come across is getAtomBounds in the TextLine class. But I'm not sure how to make use of this from the starting position of a TextArea or other spark component. Before I go delving into this further, is there an obvious way to do this that I've missed. And if not, can anyone give me a lead on how to make use of getAtomBounds from a RichText or other component.

       

      Any help greatly appreciated.

        • 1. Re: getCharBoundaries equivalent in spark text components
          Peter deHaan Level 4

          Dave,

           

          Sorry, I haven't tried this yet myself, but is this post helpful? http://forums.adobe.com/thread/453085

           

          Feel free to file an enhancement request at http://bugs.adobe.com/flex/ if you think this is a common use case and should be made easier.

           

          Peter

          • 2. Re: getCharBoundaries equivalent in spark text components
            dave cragg Level 2

            Thanks Peter. The link was very helpful.

             

            I wasn't able to work directly from a RichText or RichEditableText component. I couldn't see how to get the flowComposer of the textFlow associated with either component. But I managed to construct a custom text layout component, and the procedure in the linked article worked as described. The y coordinate returned from getAtomBounds was a bit confusing. It was always a negative number. However, I could use the bounds rectangle of the textLine itself to get the y coordinate I needed.

            • 3. Re: getCharBoundaries equivalent in spark text components
              Peter deHaan Level 4

              dave,

               

              How about: richEdTxt.textFlow.flowComposer ?

               

              Peter

              • 4. Re: getCharBoundaries equivalent in spark text components
                dave cragg Level 2

                Sorry, Peter. I wasn't very clear when I said I couldn't get the flowComposer. I tried what you suggested, but it returned null. Same for RichText.

                • 5. Re: getCharBoundaries equivalent in spark text components
                  Peter deHaan Level 4

                  dave,

                   

                  Good catch! Can you please file a bug at http://bugs.adobe.com/flex/ and include a simple test case (actually, I was able to repro with the test case below if you want to use that code)? (and then post the bug number here so I can subscribe and assign to the correct person).

                  You can see from the code below that the flowComposer seems to be null by default, but if you edit the code you will get a flowComposer object back.

                   

                  <?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">
                      <s:layout>
                          <s:VerticalLayout paddingLeft="20" paddingTop="20" />
                      </s:layout>
                      <fx:Script>
                          <![CDATA[
                              import mx.utils.ObjectUtil;
                              private function init():void {
                                  debug.text = ObjectUtil.toString(richEdTxt.textFlow.flowComposer);
                                  btn.enabled = false;
                              }
                          ]]>
                      </fx:Script>
                      <s:RichEditableText id="richEdTxt" change="btn.enabled = true;">
                          <s:textFlow>
                              <s:TextFlow>
                                  <s:p>The quick brown <s:span fontWeight="bold">fox jumps over</s:span> the lazy dog</s:p>
                              </s:TextFlow>
                          </s:textFlow>
                      </s:RichEditableText>
                      <s:Button id="btn" label="get flowComposer" click="init();" />
                      <s:TextArea id="debug" width="550" height="300" />
                  </s:Application>
                  

                   

                  Thanks,

                  Peter

                  • 6. Re: getCharBoundaries equivalent in spark text components
                    dave cragg Level 2

                    Peter, I filed a report - SDK-22374

                     

                    Interestingly, I wasn't able to get your example to run. It stalled on startup (in debug mode) with the progress bar about half-way finished. I had to set the textFlow of the RET on creationComplete. I'm guessing your using a later SDK build than me. (I'm using 4.0.0.8469) So this may not be an issue any more. This was with Safari 4.0.2 (OS X).