<s:RichEditableText editable="false" styleName="chatWin" height="550" width="100%">
<s:textFlow>
<s:TextFlow>
<s:p>Inline<s:br />TextFlow</s:p>
</s:TextFlow>
</s:textFlow>
</s:RichEditableText>
我想动态添加此<s:p>
标记,从而进行聊天...我试过这个:
var p:p = new p();
但这不起作用
答案 0 :(得分:1)
您可以通过附加到字符串变量并使用TextConverter.importToFlow()
进行回流来编程方式更新文本,而不是MXML中的声明性文本流。
示例:
在输入时,附加并重排输入字段中的文本:
<?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"
minWidth="955"
minHeight="600">
<fx:Script>
<![CDATA[
import flashx.textLayout.conversion.TextConverter;
import flashx.textLayout.elements.TextFlow;
import mx.events.FlexEvent;
[Bindable]
public var text:String = "<p>Inline<br />TextFlow</p>";
protected function input_enterHandler(event:FlexEvent):void
{
text += input.text;
input.text = null;
}
]]>
</fx:Script>
<s:layout>
<s:VerticalLayout />
</s:layout>
<s:TextInput id="input"
enter="input_enterHandler(event)" />
<s:RichEditableText editable="false"
selectable="true"
textFlow="{TextConverter.importToFlow(text, TextConverter.TEXT_FIELD_HTML_FORMAT)}"
buttonMode="true"
width="100%"
height="100%" />
</s:Application>