Flash Tutorial: Using the Property Textfield.restrict

One of these days was studying Flash and decided to make a simple game of old. Post after the final result here for you. The point is that I found very useful property of TextField Restrict the time to isolate the letters you type in the game. This property may also be useful in forms, you may want to delete offensive words or things of tipo.Segue below a list of most common commands using this property. Assuming that we have in a Stage TextField instantiated as MyText:

  myText.restrict = "AZ"; 

TextField lets you enter in all the characters from A to Z capitals.

  myText.restrict = "AZ az"; 

TextField lets you enter in all the characters from A to Z no matter whether they are upper or lower.

  myText.restrict = "AZ 0-9"; 

TextField lets you enter in all the characters from A to Z capitals and numbers.

  myText.restrict = "^ az"; 

In some cases, the circumflex, can be used to delete a few characters. In the above example, are allowed in TextField MyText, all characters and numbers with the exception of AAZ lowercase letters.

  myText.restrict = "\ \ - \ \ ^"; 

To delete one of the characters that are used by actionscript, as the signs and ^ - for example, you must precede them with two backslashes as shown in the example above.

  myText.restrict = "AZ ^ Q"; 

You can use the character of exclusion ^ anywhere in the string to include a group of characters and exclude others. In the example above are allowed all the characters from A to Z capitals, except the letter Q.

Hangman's Game

Below follows the example of the code I used in the Game of force. Each character that is typed, is to exclude both capital as tiny. On Stage for 5 objects. Two captions "typed letters," and "Type a letter," which are the type Textfields Static, two Texfields Input type the first txtTypped and low txtLetter and btnOK.O actionscript button should be added in the first frame:

  / / Declaration of variables 
  var typed: String = ""; 
  var letter: String = ""; 
  var char1: String = ""; 
  var char2: String = ""; 
  / / This command prevents the user to enter values in Textbox txtTyped 
  txtTyped.selectable = false; 
  / / Function when you click the OK button 
  btnOK.onRelease = function () ( 
  / / Transfers the value entered for the Textbox txtTyped 
	  typed = txtTyped.text; 
	  letter = txtLetter.text; 
	  txtTyped.text = + txtLetter.text typed; 
	  / / Assembles the string that will be ignored by Textbox 
 	  / / Add the same letter in uppercase 
	  char1 = char1 + + letter letter.toUpperCase (); 
	  char2 = "^" + char1; 
	  / / Prohibits the letters you type to be re 
	  txtLetter.restrict = [char2]; 
	
 	  / / Clear the Textbox txtLetter 
	  txtLetter.text = "";); 

I hope I have helped in some coisa.Dúvidas please contact by e-mailing blog@tiagopimentel.com. [] S