PASSWORD PROTECTION as3 |
Very easy and simple tutorial to show you how to create basic password protection for your flash projects. The result should
look like this:
All we need is button with instance name set to pw_btn and input text field with instance name pw_txt. We can set the input texfield behaviour
to password and everything typed in will be displayed as *. You can change texfield behaviours in their properties/ paragraph menu.
![]() Now select frame one and enter following actionscript. stop(); function Password(evt:MouseEvent):void { if(pw_txt.text == "admin"){ gotoAndStop(3); }else{ gotoAndStop(2); } } pw_btn.addEventListener(MouseEvent.CLICK, Password);
Line 3 is definition of Password function. Line 4 checks if entered password matches the required string. In this case it is admin.
If string in input text fiels matches password, function jumps to frame 3. If password does not match function jumps to frame 2. Ofcourse what happens in this two cases
is entirely up to you to decide. Last line adds event listener to the button, meaning if the button is clicked, execute Password function. This kind of password protection can be easily
changed to login option by just adding name input text field and changing line 4 to something like this:
if(pw_txt.text == "admin" && name_txt.text == "Bob"){ //function body.. } |