1 Reply Latest reply on Mar 15, 2012 6:52 AM by Patel Bharat

    How to calculate actual number of lines and textwidth in mobile s:TextArea ?

    mob_eng_at_edt

      We have a need to dynamically size a container of a spark textarea for a custom panel in a mobile tablet app and desktop app.

       

      We need to know how many actual lines of text so we can grow the container holding the textarea, and the width of the longest line so we can center left justified content within the continer.

       

      It was fairly easy to do both with the mx:Textarea, but the mx textarea is not available in a mobile app.

       

      We have tried txtArea.textFlow.flowComposer.numLines in a desktop app with success, but the same code just wont work in a android mobile app(null object reference on flowComposer).

       

      As far as finding the longest line in a s:TextArea, we cant seem to find a way to do that at all for a desktop or mobile app.

       

      Any clues on how to go about this?

       

      Thanks in advance.

       

      Bob,

      EDT

        • 1. Re: How to calculate actual number of lines and textwidth in mobile s:TextArea ?
          Patel Bharat Level 2

          Hi Friend,

           

          Try the below code, might be this would be helpful to you.

           

          <s:View xmlns:fx="http://ns.adobe.com/mxml/2009"

                  xmlns:s="library://ns.adobe.com/flex/spark" title="HomeView"

                  >

              <fx:Script>

                  <![CDATA[

                      import spark.events.TextOperationEvent;

           

                      [Bindable]

                      protected static var lineCount:uint = 0;

           

                      protected function richEdTxt_changeHandler(evt:TextOperationEvent):void {

                          lineCount = richEdTxt.mx_internal::textContainerManager.numLines;

                      }

                  ]]>

              </fx:Script>

           

              <s:Panel id="pnl"

                       title="Total Lines: {lineCount}"

                       horizontalCenter="0" verticalCenter="0">

           

                  <s:RichEditableText id="richEdTxt"

                                      widthInChars="20" heightInLines="10"

                                      change="richEdTxt_changeHandler(event);" />

           

              </s:Panel>

          </s:View>

           

          Regards,

          Bharat Patel