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 case is that I found very useful property of Textfield Restrict the time of isolating the letters you type in the game. This property may be useful also 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 type in all the characters from A to Z capitals.
myText.restrict = "az AZ"; Textfield lets you type in all the characters from A to Z no matter whether they are uppercase or lowercase.
myText.restrict = "AZ 0-9"; Textfield lets you type 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 the Textfield MyText, all characters and numbers with the exception of AZ 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.
Game of Hangman
Below follows the example of the code I used in the game of force. Each character that is typed, will be excluded either as tiny capital. At Stage 5 there are objects. Two captions "typed letters:" and "Type a letter:" the type that are Textfields Static, two Texfields Input type the first txtTypped and low txtLetter and button btnOK.O actionscript 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 () ( / / Transfer the value entered for the textbox txtTyped typed = txtTyped.text;
letter = txtLetter.text;
txtTyped.text = typed + txtLetter.text;
/ / 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









































