TextField.replaceSel()
Availability
Flash Player 6.
Usage
my_txt.replaceSel(text:String) : Void
Parameters
A string.
text
Returns
Nothing.
Description
Method; replaces the current selection with the contents of the
inserted at the position of the current selection, using the current default character format and
default paragraph format. The text is not treated as HTML, even if the text field is an HTML
text field.
You can use the
and paragraph formatting of the rest of the text.
You must use
Selection.setFocus()
Example
The following example code creates a multiline text field with text on the Stage. When you select
some text and then right-click or Control-click over the text field, you can select Enter current
date from the context menu. This selection calls a function that replaces the selected text with the
current date.
this.createTextField("my_txt", this.getNextHighestDepth(), 10, 10, 320, 240);
my_txt.border = true;
my_txt.wordWrap = true;
my_txt.multiline = true;
my_txt.type = "input";
my_txt.text = "Select some sample text from the text field and then right-
click/control click and select 'Enter current date' from the context menu to
replace the currently selected text with the current date.";
var my_cm:ContextMenu = new ContextMenu();
my_cm.customItems.push(new ContextMenuItem("Enter current date", enterDate));
function enterDate(obj:Object, menuItem:ContextMenuItem) {
var today_str:String = new Date().toString();
var date_str:String = today_str.split(" ", 3).join(" ");
my_txt.replaceSel(date_str);
}
my_txt.menu = my_cm;
See also
Selection.setFocus()
method to insert and delete text without disrupting the character
replaceSel()
to focus the field before issuing this command.
parameter. The text is
text
TextField.replaceSel()
911
Need help?
Do you have a question about the FLASH MX 2004-ACTIONSCRIPT LANGUAGE and is the answer not in the manual?