all groups > flash actionscript > september 2005 >
You're in the

flash actionscript

group:

detecting a group of selected words in a string


detecting a group of selected words in a string shabazz05
9/30/2005 9:33:52 PM
flash actionscript: I have a text field with about 5 lines of text. Is it possible to have the user
select any given word on any given line and change the font color of just that
word?

Or does anybody know how to detect the first and last character of a
selection? Example:

"The quick brown fox jumped over the lazy dog"

Suppose the user selects the words "quick brown".
The first character position of the selection would be 4 and the last would be
14. If I could get that I would know where to place my html tags.

Any suggestions?
Re: detecting a group of selected words in a string funkme
9/30/2005 9:48:38 PM
Re: detecting a group of selected words in a string NSurveyor
10/1/2005 12:15:46 AM
Give your textfield the instance name: x. Type in whatever you want in it.
Then, click on the current frame, and add this to the frame actions:

TextField.prototype.selectableWords = function(color) {
this.html = true;
if (this.otext == undefined) {
this.otext = this.text;
}
this.text = this.otext;
var b = 0;
for (var c = 0; c<this.length; c++) {
var char = this.text.charAt(c);
if (char == ' ') {
var e = c;
var t_fmt = new TextFormat();
t_fmt.url = 'asfunction:'+this._name+'.'+'selWord,'+b+','+e+','+color;
this.setTextFormat(b, e, t_fmt);
b = e+1;
}
}
this.selWord = function(indices) {
trace(this);
var begin = Number(indices.split(',')[0]);
var end = Number(indices.split(',')[1]);
var color = Number(indices.split(',')[2]);
this.selectableWords(color);
this.setTextFormat(begin, end, new TextFormat(null, null, color));
};
};
x.selectableWords(0xFF0000);

AddThis Social Bookmark Button