如何在 textFlow 中动态添加文本和标签 [英] How to add dynamically text and tags inside textFlow

查看:19
本文介绍了如何在 textFlow 中动态添加文本和标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<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> 标签,从而进行聊天......我已经试过了:

I want to add this <s:p> tag dynamically, thus making a chat...i've tried this:

var p:p = new p();

但这不起作用

推荐答案

代替 MXML 中的声明性文本流,您可以通过附加到字符串变量并使用 TextConverter.importToFlow().

Instead of a declarative text flow within MXML, you could programmatically update the text by appending to a string variable and reflowing with TextConverter.importToFlow().

示例:

在输入时,输入字段中的文本被附加并重排:

On enter, text from the input field is appended and reflowed:

<?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>

这篇关于如何在 textFlow 中动态添加文本和标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆