因为目前的FLEX的RichTextEditor不支持图文混编,所以,只能自己动手了,实现最核心的部分,光标定位插入文本。
Code
1<?xml version="1.0" encoding="utf-8"?gt;
2<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"gt;
3 <mx:Script>
4 <![CDATA[
5
6 [Bindable]
7 private var textAreaString:String = "textAreaString";
8 [Bindable]
9 private var insertString:String = "|insert|";
10
11 private function insertHandler():void {
12 if (textArea.selectionBeginIndex == textArea.selectionEndIndex) {
13 var startPart:String = textAreaString.substring(0,textArea.selectionBeginIndex);
14 var endPart:String = textAreaString.substring(textArea.selectionEndIndex,textAreaString.length);
15 startPart+=insertString;
16 startPart+=endPart;
17 textAreaString = startPart;
18 }
19 }
20
21 private function changeInsertHandler():void {
22 insertString = insertInput.text;
23 }
24 ]]>
25 </mx:Script>
26 <mx:TextArea id="textArea" x="10" y="21" width="298" height="158" text="{textAreaString}"/gt;
27 <mx:Button x="316" y="20" label="Insert" click="insertHandler();"/gt;
28 <mx:TextInput id="insertInput" x="316" y="50" text="{insertString}" change="changeInsertHandler();"/gt;
29</mx:Application>
30
1<?xml version="1.0" encoding="utf-8"?gt;
2<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"gt;
3 <mx:Script>
4 <![CDATA[
5
6 [Bindable]
7 private var textAreaString:String = "textAreaString";
8 [Bindable]
9 private var insertString:String = "|insert|";
10
11 private function insertHandler():void {
12 if (textArea.selectionBeginIndex == textArea.selectionEndIndex) {
13 var startPart:String = textAreaString.substring(0,textArea.selectionBeginIndex);
14 var endPart:String = textAreaString.substring(textArea.selectionEndIndex,textAreaString.length);
15 startPart+=insertString;
16 startPart+=endPart;
17 textAreaString = startPart;
18 }
19 }
20
21 private function changeInsertHandler():void {
22 insertString = insertInput.text;
23 }
24 ]]>
25 </mx:Script>
26 <mx:TextArea id="textArea" x="10" y="21" width="298" height="158" text="{textAreaString}"/gt;
27 <mx:Button x="316" y="20" label="Insert" click="insertHandler();"/gt;
28 <mx:TextInput id="insertInput" x="316" y="50" text="{insertString}" change="changeInsertHandler();"/gt;
29</mx:Application>
30