Featured Tutorials

glass effect,glass text,logo on glass,logo on texture,text on glass,beer glass,beer photoshop,photoshop tutorial,blendning options,budweiser beer Adding Logos or Text to a Glass or Textured Surface

Adding Logos or Text to a Glass or Textured Surface

This one is a useful technique to learn in order to add logos or text to a textured surfac..

flash,exe,fullscreen,fscommand,fs command,auto run,autorun,autorun.inf,autorun.bat,autorun cd,cd,fullscreen flash,flash for cd,flash presentation Flash EXE Presentation for an Auto-Run CD

Flash EXE Presentation for an Auto-Run CD

This article will teach you how to create an Auto run CD for a fullscreen Flash presentati..

flash,game design,platform shooter,side scrolling,platform games,duplicate movie clips,keyboard input,key input,key press,movement in flash,user controlled,flash game design,how to design games Flash Game Design, Jet Fighter Shooter

Flash Game Design, Jet Fighter Shooter

Learn some of the basics scripts used to create this side scrolling jet fighter game. Lear..

firework photos,how to photo fireworks,photograph fireworks,photography,fireworks,shoot fireworks,take pictures of fireworks,fireworks with camera Firework Photography how to setup your camera

Firework Photography how to setup your camera

This digital photography tutorial will teach you how to setup your cameras shutter speed a..

photoshop,tips,tricks,tutorials,designs Fashion designs in Photoshop

Fashion designs in Photoshop

This tutorial will show you how to create affliction and modern fashion designs in Adobe ..

Featured Videos

Learn basic web design and seo skills, also explains what meta ta..

This video shows off the power of 3D software with realistic faci..

This video will teach you some basic techniques for creating and ..

This tutorial will show you how to import fully layers Photoshop ..

Heres a great spoof video for the technically challenged develope..

Simple Bad Word Filter in Flash

While searching for a bad word filter script for one of my flash projects I couldn't really find a simple answer, there were loads of big looping scripts and over the top ways of doing this, but hopefully you will find this the simplest and most effective.

 

Convert Text field to Lower Case

First convert your input field to lowercase characters, this will save you confusion and also save you from writing out multiple bad words to filter i.e Badword, badword, BadWord etc

 

text_field = text_field.toLowerCase();

 

Replace Bad Words in a 'New Variable'

Create a new variable name for this example this will be called "field_check". We now need to set "field_check" to the same value as our original "text_field" but also remove any bad words we don't want from the string and replace them with "" (or nothing).

 

field_check = text_field.replace("badword1", "").replace("badword2", "").replace("badword3", "");

 

Compare 'New Variable' to 'Text Field'

We now use an If Statement to compare the two variables to see if any changes have taken place, remember if the above script found any bad words listed it would of replaced them with "" (or nothing) so the new variable will now be different from the "text_field".

 

if (field_check != _level0.text_field) {
error_message = "Word not permitted!";
} else {
play();
}
};

 

The Final Code

Heres the final bit of code within a button event handler. You may also notice that ive made it write a message in another text field telling the user that the words entered were not permitted (but only if the two variables don't match after the replacing).

 


on (release) {
text_field = text_field.toLowerCase();

field_check = text_field.replace("badword1", "").replace("badword2", "").replace("badword3", "");

if (field_check != text_field) {
error_message = "Word not permitted!";
} else {
play();
}
};


The good thing about this technique is you don't need to enter a massive list of words because once it picks up the word "flash" for example the word "flashing" and "flasher" also become part of the bad word and the error is still shown.


More Flash...

Other Content...

 Subscribe to our feed

Send to a friend