ActionScript.org Flash, Flex and ActionScript Resources - http://www.actionscript.org/resources
Password protected pages
http://www.actionscript.org/resources/articles/43/1/Password-protected-pages/Page1.html
Perlaki
This user is yet to take control of their account and provide a biography. If you are the author of this article, please contact us via support AT actionscript DOT org. 
By Perlaki
Published on September 9, 2005
 
Written by: PERLAKI , email [email:[email protected]]
Difficulty Level: Beginner
Requirements: Flash 5 or higher

Page 1 of 1
Written by: PERLAKI , email [email:[email protected]]
Difficulty Level: Beginner
Requirements: Flash 5 or higher
Download FLA

This is a simple password file, ideal for business clients' access, or just friends to view personal pages.
You can set any number of passwords to launch any number of pages, or go to another part of the flash movie.
I have set this movie to accept "jokes", "stories" and "pictures" to load a new page, and "private" to go to another part of the movie. TRY IT! You can either press the 'Enter' button on the screen or on your keyboard.



Create a movie clip (Ctrl+F8) called "passwordMC", and we'll have all the workings in it. This makes it easier to move around later on in your design.
Edit this MC and set up 2 layers, and in layer1, frame1 have:
1. input text box with the variable name "password",
2. an enter button
3. add the stop (); command on the keyframe.


On layer2, frame10, call frame label "error"
On layer1, frame10, have a retry button.

Now to add the code.
On the enter button:
[as]on (release, keyPress "<Enter>") {
if (password eq "pictures") {
getURL ("pictures.htm", "_blank");
} else if (password eq "jokes") {
getURL ("jokes.htm", "_blank");
} else if (password eq "stories") {
getURL ("stories.htm", "_blank");
} else if (password eq "private") {
tellTarget ("_level0") {
gotoAndStop ("private");
}
} else {
gotoAndStop ("error");
}
}
[/as] On the retry button, have the command [as]on (release) {
gotoAndPlay (1);
}
[/as]

The last step is to have the private section of the movie.
Go back to the base timeline of Scene 1, where the password MC is placed (this is level 0). Then add a new blank keyframe further along the timeline (say frame 10) Give this keyframe the label "private". This is where you place your top secret files for 007 to access. Also, because the enter button says 'gotoAndPlay', you will need a stop command here, or change the button command to 'gotoAndStop.

EXPLAIN!! Well, when the user presses the "enter" button, the code checks to see if it recognizes the password e.g."pictures". If it does then the next line is read, "getURL ("pictures.htm", "_blank");" otherwise it goes to the next line and so on, until it gets to the "else" and then if nothing is recognized, then it carries out the final command - gotoAndStop ("error");
For the "private" password, the code controls the timeline on level 0 by the tell target command:

[as]tellTarget ("_level0") {
gotoAndPlay ("private");
}
[/as] Obviously, you can set as many passwords as you like, to go to whatever pages you want, even to go to a different part of your flash movie.
It's simple, yet effective. Enjoy!!