|
||||||
|
||||||
Flash Tutorial - User Name and Password

Free Flash Tutorial
Step Three: The ActionScript
Note: If you wish you can miss out the comments (//text in gray). It makes no difference to the code if you include it or not, it's just there to explain how the code works. Comments used here start with // and are all typed on a single line.
You also do not need the blank lines, they are there to make the script easier to read.
//
This is a global function that checks the input boxes are not
just all spaces
String.prototype.isWhiteSpace = function()
{
return ((this != undefined && this.length>0)
? (this.split(" ").join("").length ==
0 ? b=true : b=false)
: (b=false));
};
//
This clears the
input
boxes so that if
the user logs in a second time the old information is deleted.
var UserName = "";
var Password = "";
//
This
sets
the
default
starting
message
when the
movie
first
loads
var Guide = "Please
Enter Your User Name And Password";
// Declares a global function which can be called any time from any where
in the flash movie
_global.nextcheck = function()
{
// Checks the
password to see if anything has been typed in or if it is empty
if ( _root.Password.length ==
0 | _root.Password.length == "" | _root.Password eq "")
{
// Alerts the user that their password is incorrect
_root.Guide = "No
Password Entered Please Try Again";
// Stops the movie from going to the next frame
stop();
// Checks to see if the password is only full of spaces
} else if (_root.Password.isWhiteSpace()){
// Alerts the user that their password is incorrect
_root.Guide = "Sorry
Incorrect Password Entered Please Try Again";
// Stops the movie from going to the next frame
stop();
// Checks to see if the password is right or not
} else if (_root.Password
== "wasp")
{
//
If the password is correct movie on to the next frame of the
movie
nextFrame();
} else {
// If the password is wrong then alert the user that it's wrong
_root.Guide = "Sorry
Incorrect Password Entered Please Try Again";
// Stops the movie from going to the next frame
stop();
}
};
// Stops the movie from going to the next frame
stop();
Note: If you wanted the Movie to direct the user to a new web page, replace the line nextFrame(); with the web address for example:
getURL("http://www.webwasp.co.uk");
Cross Ref: To learn how to create buttons see the tutorial: Buttons
Note: To make it easier to test the Movie, you may want to add a temporary Back Button. Drag a Button on Stage (you can use the same one you used in frame 1) and place the following ActionScript:
on (press) {
prevFrame();
}
|
Why not try out webwasp's new community. Meet new people, find friends in your area: Webwasp Mates & Dates
|
|
|
All material on this site is protected under international copyright © law. DO NOT reproduce any material from this site without written permission. Please ask as permission is often granted.
|