Latest News and Developments
In this tutorial you will learn how to password protect your Flash Movie or Application by loading in a password that is located in an external text file. This will be presented in a step-by-step format.
1. First create an actions layer and a text layer in your Flash document.

2. Now draw your elements on the stage in the first frame on the ‘text’ layer. ‘Please enter password’ is just static text. For the input box goto to the properties panel and make it input text with the name ‘thePassword’. Also select border around text and make the text selectable. Draw the ‘ok’ button, press F8 to turn the graphic into a symbol, select ‘Button’ and hit .

3. The next thing we are going to do is create two more frames in the text layer. We will need one frame that reflects the user entering in the wrong password and one frame that reflects the user entering in the correct password (this is where your password protected movie or application would be located).
i. On the text layer, insert a keyframe in frame 2 and one in frame 3 of the timeline.
ii. On the frame 2 keyframe put a text message that indicates that the user entered in the wrong password. Also make a button (draw a square and press F8 and select button, then ‘enter’) and name it ‘back_btn’.

iii. Insert a keyframe on the actions layer at frame 2. Press F9 or open the actions tab and insert the following code:
// go back to frame 1 to re-enter the password
back_btn.onPress = function() {gotoAndStop(1)
}
iv. Insert a keyframe frame 3 of the actions layer and the text layer. Insert the stop(); command on the actions layer. On the text layer create a confirmation message letting the user know that they successfully entered in the password. This is also where you would put the movie or application that you want to protect with a password.
4. All thats left now is to create the actionscript that puts all this together along with the text file that contains the password. First we will create the actionscript. All of the following actionscript should be put into the first frame of the actions layer.
i. First we’ll create the script to retrieve the password from the text file.
// define an external variablevar externalVars = new LoadVars();
// when the file is loaded the password will be assigned to the
// variable name of the variable in the text file ’secretcode’.
//’content’ is the name of the variable contained in the text
//file.
externalVars.onLoad = function() {secretcode = this.content;
}
// load the text file.
externalVars.load(’code.txt’);
ii. Now we’ll create the script for the button named �ok_btn�
// When button is pressed�.
ok_btn.onPress = function() {// if ‘thePassword’ input text box = ’secretcode’
// then goto frame 3.
if (_root.thePassword.text == _root.secretcode) {_root.gotoAndStop(3);
} else {
// else ‘thePassword’ is incorrect then goto frame 2.
_root.gotoAndStop(2);}
}
iii. In order to make the password appear as asterisks while be typed in we need the following actionscript.
thePassword.password=true;
iv. Now make a text file with the following content (where 123456789 is my chosen password) and name it �code.txt�. Put this file in the same directory as your swf file.

Thats it! Your done test it out and let us know how you made out with it. Thank-you for participating in this My Flash Resource tutorial.
My Flash Resource - A continually growing collection of tutorials, thoughts and interests of a Flash Animator and/or Developer.