如何使用ActionScript3和flash cs5捕获TLF域中的文本的潜在文本?例如,我使用以下命令获得了所选文本的偏移量
var zz:int = textpane.selectionBeginIndex;
var zzz:int = textpane.selectionEndIndex;其中文本窗格是TLF框的实例。我得到了选择的开始和结束位置的索引,但我找不到如何使用这些值来获取潜台词。
我的最终目标是动态地在文本之前添加一些内容,在文本之后添加一些内容,而不仅仅是替换它。
发布于 2012-07-13 08:55:38
使用开始和结束索引,从textpane.text调用substring
var start:int = textpane.selectionBeginIndex;
var end:int = textpane.selectionEndIndex;
var text:String = textpane.text.substring(start, end);TextField和TLFTextField实现了可以插入文本的replaceText()函数。
要替换起始索引,请执行以下操作:
textpane.replaceText(start, start, "-->");要替换末端索引,请执行以下操作:
textpane.replaceText(end, end, "<--");要同时在起始索引处和结束索引处插入,请确保补偿插入文本的长度。
end += insertedText.length;总而言之,这就是:
// find start and end positions
var start:int = textpane.selectionBeginIndex;
var end:int = textpane.selectionEndIndex;
// selected text
var text:String = textpane.text.substring(start, end);
// insert text at beginning of selection
var inseredtText:String = "-->";
textpane.replaceText(start, start, insertText);
// insert text at end of selection
end += insertedText.length;
textpane.replaceText(end, end, "<--");https://stackoverflow.com/questions/11462412
复制相似问题