0

I'm making simple editor. And I want that, let write replacing colorless text to color text from RichEditableText when I will write any text.

For example: PHP --> <s:span color="#FF0000">PHP<s:span>

This codes not work:

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

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

Click here and try

Source code:

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

A other problem; How do I send the pointer at the end? When I press any key, pointer going to deal. Try: http://samed.us/samples/ops3.swf

Thanks for your help...

zero323
  • 322,348
  • 103
  • 959
  • 935
SamedDeger
  • 39
  • 1
  • 11
  • 1
    I'm unclear whta you're trying to do. Is this a PHP Question or a Flex question? This line, in particular: "And I want that, let write replacing colorless text to color text from RichEditableText when I will write PHP." is particularly confusing. Also, you mention a code segment that does not work; please expand on 'does not work.' Do you get a compile time error? A runtime error? Or something else? – JeffryHouser Jun 01 '12 at 13:33
  • I'm sorry for my English. It's not good. It's flex question. PHP is sample text. Nevermind PHP. You think any text. For exampe 'melon'. When I'm write melon on RichEditableText, function change color text to 'melon'. – SamedDeger Jun 01 '12 at 14:06
  • Okay, based on your sample act it looks like it is properly replacing the typed text "melon" with the span which would give it color. That brings me to the second part of my original question; what exactly is the problem? – JeffryHouser Jun 01 '12 at 14:20
  • it's error: http://samed.us/samples/ops2.swf – SamedDeger Jun 01 '12 at 15:16
  • Share the source for your sample. – JeffryHouser Jun 01 '12 at 15:33

1 Answers1

0

Instead of this line:

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

Try something like this:

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

Basically, you need to convert the HTML into something that the TLF Framework will understand. Read some docs on textFlow and the TextConverter

JeffryHouser
  • 39,401
  • 4
  • 38
  • 59
  • 1
    Okay this code's work. A other problem; How do I send the pointer at the end? When I press any key, pointer going to deal. Try: http://samed.us/samples/ops3.swf – SamedDeger Jun 01 '12 at 20:15
  • 1
    If this post answers your question, be sure to mark it as such. If you have a new question, please post it as a new question. I assume you need to reset the cursor location after changing the textFlow. – JeffryHouser Jun 01 '12 at 20:56