Your code can be simplified as follows. Pay attention to *addImageButton_clickHandler*
<?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"
minWidth="955" minHeight="600"
creationComplete="application1_creationCompleteHandler(event)"
>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:layout>
<s:VerticalLayout
horizontalAlign="center"
paddingTop="20"
/>
</s:layout>
<s:TextArea
id="richText"
width="800"
height="300"
horizontalCenter="0"
verticalCenter="0"
textFlow="{textFlow}"
/>
<s:Button
id="addImageButton"
label="Add image"
click="addImageButton_clickHandler(event)"
/>
<fx:Script>
<![CDATA[
import flashx.textLayout.edit.IEditManager;
import flashx.textLayout.elements.InlineGraphicElement;
import flashx.textLayout.elements.ParagraphElement;
import flashx.textLayout.elements.TextFlow;
import flashx.textLayout.formats.WhiteSpaceCollapse;
import mx.events.FlexEvent;
import spark.utils.TextFlowUtil;
[Bindable]
private var inputString:String = "The Dow Jones industrial average lost more than 100 points Tuesday after Japan raised the severity of its nuclear crisis and Alcoa Inc. reported disappointing sales. A drop in oil prices pulled down energy stocks.";
[Bindable]
private var textFlow:TextFlow;
[Embed(source="assets/images/math.png")]
[Bindable]
public var imgCls:Class;
protected function application1_creationCompleteHandler(event:FlexEvent):void {
textFlow = TextFlowUtil.importFromXML(XML(inputString), WhiteSpaceCollapse.PRESERVE);
}
protected function addImageButton_clickHandler(event:MouseEvent):void {
var editManager:IEditManager = textFlow.interactionManager as IEditManager;
editManager.insertInlineGraphic(imgCls, 174, 44, null, editManager.getSelectionState());
}
]]>
</fx:Script>
</s:Application>
