Flex60460
Flex60460

Reputation: 993

Insert text in RichTextEditor on cursor position

I'd to insert date on a richtexteditor when the user click on a button. This part is easy, more difficult, how to insert this on cursor position. Cursor position may be on the beginning, middle or end of the text.

Thanks for helping

Upvotes: 0

Views: 2057

Answers (1)

randomUser56789
randomUser56789

Reputation: 936

Simple as that:

    protected function richText_keyDownHandler(event:KeyboardEvent):void
    {
        if (event.keyCode == 66) //or remove if statement
            richText.insertText("Really?");
    }


    <s:RichEditableText id="richText" text="Lorem ipsum dolor sit amet"   
keyDown="richText_keyDownHandler(event)"/>

EDIT: for mx RichTextEditor

        protected function richText_keyDownHandler(event:KeyboardEvent):void
        {
            var ind:int = richEdit.selection.beginIndex;
            richEdit.text = richEdit.text.substring(0, ind) +   
            "Your text variable here" +   
            richEdit.text.substring(ind, richEdit.text.length);     
        }

and mx rich text editor:

    <mx:RichTextEditor id="richEdit" text="Lorem ipsum dolor sit amet"  
 keyDown="richText_keyDownHandler(event)"/>

Maybe there is more effective method, but this is the only I could think of.

Upvotes: 1

Related Questions