How can I read a spark TextArea implicit line breaks?

僤鯓⒐⒋嵵緔 提交于 2019-12-11 18:25:19

问题


I have a TextArea where the user can enter text and also change the width and height of the TextArea. When resizing, the text is breaking where expected. I need to find where the TextArea skin added the implicit line breaks after resizing.

ENVIRONMENT

  • FlexBuilder 4.6
  • Flex SDK 4.6.0
  • Flash Player 11.1

EXAMPLE

This is just plain text that
breaks after the word "that".

Any ideas on how to find the position of the line break when the TextArea lineBreak property is toFit and the text has no CR or LF characters? In the example above, it would be position 28.


回答1:


You can split up the text into line components and return their individual text lengths pretty easily, but you'll have to use some 'text layout framework' magic.

  • First access your TextArea's textFlow property (not the text property), which will return a TextFlow instance. This is a model for the text inside your TextArea.
  • This object has a flowComposer which takes care of the layout of the text and carries a lot of information with it.
  • Its type is IFlowComposer, but you'll have to cast it to a StandardFlowComposer in order to access the individual lines.
  • Now you have access to the lines property, which is a collection of TextFlowLine
  • Each of these lines has a textLength property.

So the following

var composer:StandardFlowComposer = 
    myTextArea.textFlow.flowComposer as StandardFlowComposer;
for each (var line:TextFlowLine in composer.lines) 
    trace(line.textLength)

would yield (with your example)

29
30


来源:https://stackoverflow.com/questions/10705762/how-can-i-read-a-spark-textarea-implicit-line-breaks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!