| Main Menu |
|---|
| Games |
|---|
| Current Projects |
|---|
| Articles & Tutorials |
|---|
| Other works |
|---|
| AS3 - Setting up a password input field |
|
|
|
| Sunday, 16 October 2011 13:51 |
|
In this tutorial, I'll explain how to set up a password input text field, including password check. So, first of all, we need to create a new TextField variable.
Then, do this in the Document Class constructor. Along with adding the text field to the stage I adjust its position and dimension, add border and a bunch of other things already covered in past tutorials.
Next, I specify it's an Input text field, and also restrict the number of character user can input, adding those lines:
Of course you can change the maximum number of characters, just write whatever you want instead of 10. And, finally, we specify that it's actually a Password Input text field, setting this property to true:
In this way, the text will be hidden. Also, Cut, Copy & Paste will be disabled. Here's what we have in this moment:
Now, we want to check if the password inserted is correct or not. Simple as that, we only need to compare the text property of the password field with the correct password. To do this, we will add a button on the stage, and, on click, we will make this check. You can do it through code or directly from Flash IDE, i'm using the second one. So, add a button to the stage and give "checkPassButton" as its instance name. Also add another dynamic text field and give "checkPass_txt" as instance name. Now, add a MouseEvent.CLICK event listener to the button, in this way:
And then write the actual checkPassword method. In this case the password is SGTPEPPER, just change it to your need :
So, if you followed the tutorial correctly, your Document Class will look like this:
And, as a result, here's our password field fully working!
|


