Replace text in RichTextEditor with TextRange
<?xml version="1.0"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="600" height="500"> <mx:Script> import mx.controls.textClasses.TextRange; [Bindable] public var htmlData:String="<textformat leading='2'><p align='center'><b><font size='20'>HTML Formatted Text</font></b></p></textformat>"; public function changeSelectionText():void { var sel:TextRange = rte1.selection; var selLength:int = sel.endIndex - sel.beginIndex; if (selLength) { sel.text="This is replacement text. " sel.color="fuchsia"; sel.fontSize=20; sel.fontFamily="courier" t1.text+="\n\nNew text length: " + String(sel.endIndex - sel.beginIndex); t1.text+="\nNew Font Family: " + sel.fontFamily; t1.text+="\nNew Font Size: " + sel.fontSize; t1.text+="\nNew Font Color: " + sel.color; } } </mx:Script> <mx:RichTextEditor id="rte1" htmlText="{htmlData}" width="100%" height="100%" mouseUp="changeSelectionText()" /> <mx:TextArea editable="false" id="t1" fontSize="12" fontWeight="bold" width="300" height="180" /> </mx:Application>