【发布时间】:2012-06-06 17:50:08
【问题描述】:
我正在制作简单的编辑器。我想要这样,当我写任何文本时,让我们将 RichEditableText 中的无色文本替换为彩色文本。
例如:
PHP --> <s:span color="#FF0000">PHP<s:span>
此代码无效:
editorum.text = editorum.text.replace('PHP','<s:span color="#FF0000">php<s:span>');
编辑为:<s:RichEditableText id="editorum" ></s:RichEditableText>
源代码:
<?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
感谢您的帮助...
【问题讨论】:
-
我不清楚你想做什么。这是 PHP 问题还是 Flex 问题?尤其是这一行:“我想要这样,当我将编写 PHP 时,让我们将 RichEditableText 中的无色文本替换为彩色文本。”尤其令人困惑。另外,您提到了一个不起作用的代码段;请扩大“不起作用”。你有编译时错误吗?运行时错误?还是别的什么?
-
对不起我的英语。这样不好。这是弹性问题。 PHP 是示例文本。没关系PHP。你认为任何文本。例如“瓜”。当我在 RichEditableText 上写瓜时,函数将颜色文本更改为“瓜”。
-
好的,根据您的示例行为,看起来它正确地将键入的文本“melon”替换为可以赋予其颜色的跨度。这使我想到了原始问题的第二部分;究竟是什么问题?
-
分享您的样本来源。
标签: apache-flex mobile replace flex-spark