6 Replies Latest reply on Sep 23, 2010 11:15 PM by Thorsten Kummer

    TLF in Flex 4: Textflowcomposer returns wrong number of lines

    Thorsten Kummer

      Hi,

       

      the TextFlowComposer returns a value for myTextArea.textFlow.flowComposer.numLines. It depends on the height of the control although there's much more text in it after an import of text. What's wrong here?

      best regards

      thorsten

       

      Sample code

      var myTextFlow:TextFlow

      this.myTextArea.text=TextConverter.export(this.anotherTextArea.textFlow,TextConverter.PLAIN_TEXT_FORMAT,ConversionType.STRING_TYPE).toSt ring();

      var nLines:uint = exportResult.textFlow.flowComposer.numLines

      Alert.show(nLines.toString());

        • 1. Re: TLF in Flex 4: Textflowcomposer returns wrong number of lines
          Thorsten Kummer Level 1

          Just an addition:

           

          When I code the Alert.show of NumLines in a buttonclick event and trigger that from my procedure after the import, it gives me a 9 which is wrong.

          The next time I call my proc it gives me 10 which is wrong too. When I scroll down the textArea and re-import the text it gives me 13 which is correct.

           

          Something's wrong here, isn't it?

           

          th

          • 2. Re: TLF in Flex 4: Textflowcomposer returns wrong number of lines
            Thorsten Kummer Level 1

            Hi, does nobody have an idea?

            I'm totally frustrated...

            Regards

             

            th

            • 3. Re: TLF in Flex 4: Textflowcomposer returns wrong number of lines
              Flex harUI Adobe Employee

              What is exportResult?

              1 person found this helpful
              • 4. Re: TLF in Flex 4: Textflowcomposer returns wrong number of lines
                Thorsten Kummer Level 1

                Oh sorry, bad code snippet...

                exportresult is a textarea

                 

                Here's a full test app:

                 

                <?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/mx" viewSourceURL="srcview/index.html">      

                <fx:Script>

                <![CDATA[

                import flashx.textLayout.conversion.ConversionType;

                import flashx.textLayout.conversion.TextConverter;

                import flashx.textLayout.elements.TextFlow;

                 

                import mx.controls.Alert;

                import mx.events.FlexEvent;

                 

                import spark.utils.TextFlowUtil;

                [Bindable]private var myTextFlow:TextFlow;

                [Bindable]private var myTextXML:XML;

                private var myText:String

                private var firstLine:String

                private var nLines:uint

                 

                protected function source_creationCompleteHandler(e:FlexEvent):void

                {

                 

                source.text = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."

                }

                 

                private function onComplete(e:Event):void

                {

                myTextFlow=TextConverter.importToFlow(e.target.data, TextConverter.PLAIN_TEXT_FORMAT);

                 

                }

                 

                 

                protected function button_clickHandler(e:MouseEvent):void

                {

                switch (e.target.label)

                {

                 

                case "1. Export as TLF":

                {

                var myTextFlow:TextFlow

                this.exportResult.text=TextConverter.export(this.source.textFlow, TextConverter.PLAIN_TEXT_FORMAT, ConversionType.STRING_TYPE).toString();

                 

                var event:MouseEvent

                msg_clickHandler(event)

                 

                break;

                }

                }

                }

                 

                protected function msg_clickHandler(event:MouseEvent):void

                {

                 

                exportResult.textFlow.invalidateAllFormats()

                nLines = exportResult.textFlow.flowComposer.numLines

                Alert.show(nLines.toString());

                }

                 

                ]]>

                </fx:Script>

                 

                <s:BorderContainer width="466" height="411">

                <s:RichText id="source"

                width="350"

                textFlow="{myTextFlow}"

                creationComplete="source_creationCompleteHandler(event)"

                paddingLeft="5"

                paddingRight="5"

                paddingTop="5" enabled="true" height="74" x="35" y="178"/>

                <s:TextArea width="281"

                paddingTop="20"

                id="exportResult" height="123" x="66" y="37"/>

                <s:Button label="1. Export as TLF"

                  click="button_clickHandler(event)" x="37" y="265"/>

                <s:Button x="42" y="303" label="2. Count Lines" id="msg" click="msg_clickHandler(event)"/>

                </s:BorderContainer>

                </s:Application>

                • 5. Re: TLF in Flex 4: Textflowcomposer returns wrong number of lines
                  Flex harUI Adobe Employee

                  IFlowComposer.numlines is documented as the number of lines composed, not

                  the total number of lines that the textflow would represent if the entire

                  thing was composed.

                  1 person found this helpful
                  • 6. Re: TLF in Flex 4: Textflowcomposer returns wrong number of lines
                    Thorsten Kummer Level 1

                    Hi,

                     

                    I did the following additionally:

                    theTextArea.textFlow.flowComposer.composeToPosition()                 
                    theTextArea.textFlow.flowComposer.updateAllControllers()

                     

                    After that everythings seems to be as espected.

                    Thank you so much!

                    th