Apr 30, 2009

Custom color error in Flex RichTextEditor workaround.

There's a problem with RichTextEditor in Flex. Hitting 'Enter' in color picker (to apply custom color) deletes currently selected text (described here ). There's a simple workaround:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" initialize="init()" xmlns:local="*">
<mx:Script>
<![CDATA[
import mx.events.DropdownEvent;
private function init():void
{
rte.colorPicker.addEventListener(DropdownEvent.OPEN, colorPickerOpen);
rte.colorPicker.addEventListener(DropdownEvent.CLOSE, colorPickerClose);
}

private function colorPickerOpen(event:Event):void
{
this.rte.textArea.editable = false;
}

private function colorPickerClose(event:Event):void
{
this.rte.textArea.editable = true;
}

]]>
</mx:Script>

<mx:RichTextEditor id="rte" text="asdfasdf" width="100%" height="100%"/>

</mx:Application>