无闪动动态在TextArea中添加HTML文本

首先引用以下TextArea的帮助文档http://docs.huihoo.com/flex/4/spark/components/TextArea.html

TextArea is a text-entry control that lets users enter and edit multiple lines of richly formatted text. It can display horizontal and vertical scrollbars for scrolling through the text and supports vertical scrolling with the mouse wheel. 

伴随着Flex4的出现,Spark的全新改版,在使用TextArea的时候,发现HTMLText标签不见了。

由此产生了困惑,HTMLText没有了,那S:TextArea岂不是反而退步了么,但我相信Adobe不会这么傻,不进步反而后退。

S:TextArea要想显示HTMLText要简单也会很简单就这样就ok

textArea.textFlow = TextConverter.importToFlow(string, TextConverter.TEXT_FIELD_HTML_FORMAT); 

string还能实现动态绑定。

可如果你按这样的方式去做,你会发现每改变以下string的值,整个textArea都在刷新,如果仅仅是想在string后面再加内容,只需要追加显示而不是全部刷新这样的方式就显得很不爽了。

如下方式完美解决:动态增加string,而不照成任何的闪动

public function addParagraphElement(tf:TextFlow,content:String,color:uint=0x333333,startIndent:int = 20):void

{

var p:ParagraphElement = new ParagraphElement;

p.paragraphStartIndent = startIndent;

var se:SpanElement=new SpanElement();

se.text = content;

se.color = color;

p.addChild(se);

tf.addChild(p);

tf.flowComposer.updateAllControllers();

<s:TextArea id="textArea"

width="100%"  editable="false" height="100%">

<s:textFlow>

<s:TextFlow id="tf" updateComplete="area.textDisplay.verticalScrollPosition=area.textDisplay.contentHeight">

</s:TextFlow>

</s:textFlow>

</s:TextArea>

原文地址:https://www.cnblogs.com/anfeind/p/1877688.html