Append a flow to an existing TextFlow?

有些话、适合烂在心里 提交于 2019-12-11 07:30:14

问题


I'm looking to simply append the following text to an existing spark.components.TextArea's text flow:

<b>something</b>: hello world

I have attempted to do this using the following code, but nothing happens:

this.textarea.textFlow.addChild(TextConverter.importToFlow(
        "<b>something</b>: hello world", 
        TextConverter.TEXT_FIELD_HTML_FORMAT));

How can I accomplish this? I know in the old mx.controls.TextArea component, I could simply do:

this.textarea.htmlText += "<b>something</b>: hello world";

How can I do this with the new TLF/FTE API expressed in the spark.components.TextArea component?


回答1:


I understand your pain with this one. This is the workaround I came up with:

var tf:TextFlow = TextConverter.importToFlow("<b>something</b>: hello world", TextConverter.TEXT_FIELD_HTML_FORMAT);
var pe:ParagraphElement = tf.mxmlChildren[0];
for each (var fe:FlowElement in pe.mxmlChildren)
    some_paragraph_element.addChild(fe);

Ultimately, you need to grab all the objects in the generated TextFlow. For simplicity, I'm not doing that here. But you see how I still iterate over all objects in the first and only paragraph in the generated TextFlow?

Hope this helps and good luck.




回答2:


Another and ugly way to do could be : - Export the existing TextFlow into an HTML String. - Append to the another HTML String - Re-Import the Result

var helloWorldStr : String = "<b>something</b>: hello world";
var export : Object = TextConverter.export(textFlow,TextConverter.TEXT_FIELD_HTML_FORMAT, ConversionType.STRING_TYPE);
textFlow = TextConverter.importToFlow((export as String) + helloWorldStr, TextConverter.TEXT_FIELD_HTML_FORMAT);


来源:https://stackoverflow.com/questions/6024012/append-a-flow-to-an-existing-textflow

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