PDA

View Full Version : check for swear words



marywait
April 24th, 2005, 06:41 PM
Hello,

I will very much appreciate any help or suggestions. I'm creating a little interactive art game in Flash MX 2004 that is based on the old ZORK type interactive text only games, although mine has visual content as well. I've got the script working as far as sending the user to my chosen frames when a reply is typed and the enter key is pressed, but I'm having trouble with my "curse words" feature. What is want is that when the user types a swear word and hits Enter, they will go to the "swear" frame where they are scolded and sent back to the beginning of the game.

I can guess the most likely swear words to be typed, but I'm not sure how to write the script to make Flash watch the input field (variable name is reply) and know when one of the target words is typed, and then send the user to my "swear" frame. This functionality needs to be on just about every frame.

Sample script or simple advice on how to figure this out very welcome!
Thanks,
MaryW

charlie_su1986
April 25th, 2005, 02:50 AM
Hi there,
I'm not sure what is that ZORK, swear word thingy, Anyway, to watch a textfield and check its content, you may use TextField.onChanged.



my_txt.onChanged = function(){
//here just use a simple if statement to check for a word
//also, you can use String.indexOf() to check for a specific word in a sentence
}






For example, the following code uses textfield_txt as the parameter that is passed to the onChanged event handler. The parameter is then used in a trace() statement to send the instance name of the text field to the Output panel:


this.createTextField("myInputText_txt", 99, 10, 10, 300, 20);
myInputText_txt.border = true;
myInputText_txt.type = "input";

myInputText_txt.onChanged = function(textfield_txt:TextField) {
trace("the value of "+textfield_txt._name+" was changed. New value is: "+textfield_txt.text);
};



hope that helps :)

marywait
April 25th, 2005, 08:12 AM
Thanks much charlie. I'll try this.
Mary