Flex Spark将文本替换为彩色文本

时间:2012-06-01 13:20:04

标签: flex mobile replace flex-spark

我正在制作简单的编辑器。我想要的是,当我写任何文本时,让我们写一下将无色文本替换为RichEditableText中的彩色文本。

例如: PHP - &gt; <s:span color="#FF0000">PHP<s:span>

此代码不起作用:

editorum.text = editorum.text.replace('PHP','<s:span color="#FF0000">php<s:span>');

Editorum是:<s:RichEditableText id="editorum" ></s:RichEditableText>

Click here and try

源代码:

<?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"
               width="319" height="198" minWidth="955" minHeight="600">
    <fx:Style source="ops.css"/>
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <fx:Script>
        <![CDATA[
            import flashx.textLayout.formats.TextLayoutFormat;
            import mx.collections.ArrayCollection;
            import mx.events.FlexEvent;
            import spark.events.TextOperationEvent;
            import spark.utils.TextFlowUtil;
            protected function editorum_changeHandler(event:TextOperationEvent):void
            {
                editorum.text = editorum.text.replace('melon','<s:span color="#FF0000">melon<s:span>');
            }
        ]]>
    </fx:Script>
    <s:RichEditableText id="editorum" x="10" y="28" width="299" height="159"
                        change="editorum_changeHandler(event)">

    </s:RichEditableText>
    <s:Label x="10" y="10" width="119" text="Write 'melon' :"/>
</s:Application>

另一个问题;如何在结尾发送指针?当我按任意键时,指针就会处理。尝试:http://samed.us/samples/ops3.swf

感谢您的帮助......

1 个答案:

答案 0 :(得分:0)

而不是这一行:

editorum.text = editorum.text.replace('melon','<s:span color="#FF0000">melon<s:span>');

尝试这样的事情:

var text : String = editorum.text.replace('melon','<s:span color="#FF0000">melon<s:span>')
editorum.textFlow = TextConverter.importToFlow(text, TextConverter.TEXT_FIELD_HTML_FORMAT);

基本上,您需要将HTML转换为TLF Framework将理解的内容。 textFlow上的Read some docs和TextConverter