TextArea在光标处插入字符串
文章分类:Flash编程
<?xml version="1.0" encoding="utf-8"?>
<!-- @author magicianzrh -->
<!-- @ignore www.actionscript3.cn/magicianzrh -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<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}"/>
<mx:Button x="316" y="20" label="Insert" click="insertHandler();"/>
<mx:TextInput id="insertInput" x="316" y="50" text="{insertString}" change="changeInsertHandler();"/>
</mx:Application>
文章分类:Flash编程
<?xml version="1.0" encoding="utf-8"?>
<!-- @author magicianzrh -->
<!-- @ignore www.actionscript3.cn/magicianzrh -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<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}"/>
<mx:Button x="316" y="20" label="Insert" click="insertHandler();"/>
<mx:TextInput id="insertInput" x="316" y="50" text="{insertString}" change="changeInsertHandler();"/>
</mx:Application>
本文介绍了一个简单的Flash应用程序,演示如何实现在TextArea组件的光标位置插入指定的字符串。通过监听按钮点击事件触发插入操作,并允许用户自定义要插入的文本。
1505

被折叠的 条评论
为什么被折叠?



