因为目前的FLEX的RichTextEditor不支持图文混编,所以,只能自己动手了,实现最核心的部分,光标定位插入文本。
MXML代码
- <?xml version="1.0" encoding="utf-8"?gt;
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"gt;
- <mx:Script>
- <![CDATA[
- [Bindable]
- private var textAreaString:String = "textAreaString";
- [Bindable]
- private var insertString:String = "|insert|";
- private function insertHandler():void {
- if (textArea.selectionBeginIndex == textArea.selectionEndIndex) {
- var startPart:String = textAreaString.substring(0,textArea.selectionBeginIndex);
- var endPart:String = textAreaString.substring(textArea.selectionEndIndex,textAreaString.length);
- startPart+=insertString;
- startPart+=endPart;
- textAreaString = startPart;
- }
- }
- private function changeInsertHandler():void {
- insertString = insertInput.text;
- }
- ]]>
- </mx:Script>
- <mx:TextArea id="textArea" x="10" y="21" width="298" height="158" text="{textAreaString}"/gt;
- <mx:Button x="316" y="20" label="Insert" click="insertHandler();"/gt;
- <mx:TextInput id="insertInput" x="316" y="50" text="{insertString}" change="changeInsertHandler();"/gt;
- </mx:Application>