Swear Jar by Warrior
Swear Jar
by Warrior
 
As the title says, we are going to ban certain words in this form so that it cannot be submitted if certain words exist. An obvious application for this is stopping the use of swear-words in community forums and other unmediated posting systems. Open Flash and make three layers like the picture below. One for ActionScript, one for the InputBox and one for the button.
 
 
Right click on the ActionScript Keyframe and paste this code inside it.
 
  1. stop();
  2. // We do not list legitimate swear-words below for professional reasons
  3. // but you get the idea... Just change these words into a swear word…
  4. badWords = ["cat", "dogs", "bunnies", "cats"];
 
We have just created an array of words we do not want the user to submit. Now make a text field and turn it in to an input text. Make the line type multiline and give it the variable name “Box”. You can give it any name but for this tutorial we will use the name “Box”. Make another text field but keep it small because that will be the box that informs us if we have entered a swear word or not. Give the small box the name “Status” and make it a dynamic text. Here is the picture of the two text field's.
 
Now create button and place it in the Button layer (obviously) and put this code inside it.
 
  1. on (release) {
  2. // If the Box has no text inside it, tell the user to enter a message
  3. if (Box eq "") {
  4. Status = "Enter Message";
  5. return;
  6. }
  7. // This goes through every element in the array.
  8. //It basically says do whatever follows to every element in the array.
  9. for (i in badWords) {
  10. // This says if the current element in the badWords array is
  11. //found in the "box" string then there is a bad word present.
  12. if (Box.indexOf(badWords[i])>-1) {
  13. Status = "No Swearing";
  14. return;
  15. }
  16. }
  17. Status = "Clean Message";
  18. }
 
Remember that the keywords are case sensitive and the word “cat” is not the same as “Cat” Now you're done. You can use any word you want by editing the array.
 
Here is the working version that you can try.
 

FlashVacuum Flash ActionScript Tutorial CyanBlue subQuark JT

You do not have the Flash plugin installed, or your browser does not support Javascript.

 

 

   |      |      |   Last Modified: July 17, 2009 @ 4:25 am