Я не учел, что фокус перемещается на кнопку. Нужно сохранять caretIndex.

Код AS1/AS2:
var app: Object = this;
var outputTextField: TextField;
var inputTextField: TextField;
var caretIndex: Number = -1;
Key.addListener(this);
this.button.onRelease = function():Void {
var result: String;
var inline: String = '<a href="' + app.inputTextField.text + '"></a>';
if ( app.caretIndex > -1 ) {
result =
app.outputTextField.text.slice(0, app.caretIndex) +
inline +
app.outputTextField.text.slice(app.caretIndex + 1);
} else {
result = app.outputTextField.text + inline;
}
app.outputTextField.text = result;
};
function storeCaretIndex():Void {
if ( Selection.getFocus() != String(this.outputTextField) ) return;
this.caretIndex = Selection.getCaretIndex();
trace(this.caretIndex);
}
//-----------------------------------
//
// Events handlers
//
//-----------------------------------
function onKeyUp():Void {
this.storeCaretIndex();
}
function onMouseDown():Void {
this.onEnterFrame = this.enterFrameHandler;
}
function enterFrameHandler():Void {
this.onEnterFrame = null;
this.storeCaretIndex();
}