Hello again.
I've been looking for a way to censor words inputed into the input text box. for example:
If the user types "wipididoo" with some other words or alone and then presses Enter (proceeds to the next frame), flash will load into a dynamic text box on a new frame: "That's not a nice thing to write."
How can I do that?
I realize it has something to do with strings... But I didn't quite understand how to use them.
To check if a string contains a word, you can use indexOf. When you use indexOf, if the word isn't in there, it returns the number -1. So you could do something like:
Code:
bannedWords = new Array("bob", "bobo");
function checkString() {
for (i=0; i<bannedWords.length; i++) {
if (textString.text.indexOf(bannedWords[i])>-1) {
trace("Shame on you.");
break;
}
}
}
That code works, though it'll also trigger if a banned word is part of another word. So if you wanted it to trigger on "bob" but not "bobby", you'd need to make some adjustments.
I'm sorry :P
I didn't understand the code...
-This code goes on the first frame of the timeline?
-textString is the Var of the Input Text Box?
-And the "trace" what does it do? Where will "Shame on you." appear?
Yes, on the first frame of the timeline. textString is the instance name of the input textbox. textString.text gives you the text in the input box. "trace" is just used when you do Control>Test Movie in Flash. It appears in the Output window. If you want "Shame on you" to appear somewhere else, just replace that line:
I see.. Thanks!
And just one more thing, if it's not too hard, how can I make the dynamic text box show "You didn't write anything" if the user left the input box empty and pressed Enter to continue?
It can't be the same code you gave me because then it would locate spaces between words, right?
Code:
bannedWords = new Array("", " ");
I tried this code:
Code:
if (input.text="") {
dynamic text="You didn't write anything"
}
also tried " "
but neither worked... Flash automatically left Input empty, and wrote You didn't write anything in the Dynamic...