022Beginners Flash
Compatibility:
MX For Flash MX 2004click
here
Written
by: Phil
Length: 1500
words
The
aim of the tutorial is to learn how to create an input box which the user types
a password. If the password is correct the user goes to a new frame in the Flash
movie or a new web page.
Important
Note: Never use Flash Password protection for highly sensitive
material. It is ok for low security material only. Flash files can be hacked
into (for people who are into that sort of thing).
Bare in mind that the vast majority of people on the net will have no idea
of how to hack into a Flash file (or interest) and
so information stored behind the password is quite safe form most peoples
eyes.
Don't
write in and ask me how to hack into a Flash file as I will not tell you
and if I see any such postings on the forum I will delete them.
Cross
Ref: There is an Intermediate tutorial on how to make a Flash Movie that
has both a User Name and Password: User Names and Passwords
Try the following
passwords:
go private letmein
please
You can use
either the enter button above or Enter on your keyboard.
Step One: Setting up the Document
Go to Modify > Document and set up a small
movie. Mine is 323 x 45 pixels.
Select a background colour. Click OK
Use the Text tool
to type: Password >
Use the Arrow tool
to deselect the text you have just typed by clicking anywhere on the page
away from the word you have just typed.
Step Two: Create the input box
Select the Text tool
and drag a text box on stage.
If you have dragged the text tool you should get a paragraph text box which
has a square in the top right hand corner:
Open the Property panel (Ctrl F3).
With the text box still highlighted select: Input Text from
the drop down menu .
Select the font, font style, size and colour:
Select: Left Justify
If your Property panel is in collapsed view, click on the down
arrow
in the bottom right corner of the Property panel to expand the panel. If you
have an up arrow
your panel is already expanded.
For line type select: Password.
Select: Show Borders Around Text.
For Variable name type: password
NB: Lowercase.
Your Property panel should look like this.
Step three: Creating the Buttons
Create two buttons. One with the word Enter on it and another
with the word Retry (see the tutorial
on how to create buttons).
Place the button with the word Enter onto the stage in frame
1.
Step four: Private Frame
Right click (Mac Control click) on frame 10 and select: Insert
Keyframe
Delete the: Text Box
With the Text tool
type on stage: This is private, it is not for you!
With the Arrow tool
click on frame 10 so that it is highlighted (it goes black).
In the Property panel, where is says <frame
label> type: private
In the time line you will get a flag:
There is not enough space to see the frame label yet, but when you add frames
the label will appear.
Click on the Enter button and write down the x, y position
from the Property panel.
Delete the button: Enter
Open the Library (Window > Library) and
drag out retry button.
Position the button in the same place as the Enter button.
To do this use the x, y coordinates in the Property panel.
Step five: Wrong Frame
Right click (Mac Control click) on frame 20 and select: Insert
Keyframe
You will now be able to see the 'private' label
in the time line.
Delete the text: This is private, it is not for you!
With the Text tool
type on stage: Wrong!
With the Arrow tool
click on frame 20 so that it is highlighted.
In the Property panel, where is says <frame
label> type: wrong NB: Type in lowercase. We will refer to these frame labels
in the actionscript, and as action script is case sensitive, so the script
must match how it is typed here.
Right click on frame 30 and select: Insert frame. This allows
you to see the label: wrong
You have now finished laying out the visible objects and labels. The only
thing left to do is the actionscript.
Step six: Frame actions - frame 1
Right click on frame 1 in the Time Line and select actions.
Select Normal Mode from the View Options button .
Click on the Plus button .
Select: Actions > Movie Control > Stop
This stops the movie from playing when it first loads.
Click on the Plus button .
Select: Actions > Variables > set
variable
In the Variable Text field type:
password
Leave the Value option empty, this means that every time the frame loads it
will clear any password that may have been typed previously.
Your code should look like this:
stop();
password = "";
Step seven: Button actions - Enter frame 1
Right click on the button called 'Enter' and select Actions.
Click on the Plus button .
Select: Actions > Conditions/Loops > if
For the condition text field type: password
eq "webwasp"
Click on the Plus button .
Select: Actions > Browser > getURL
For the URL option type: http://www.webwasp.co.uk
If someone types the password webwasp they will go to the web page www.webwasp.co.uk
Click on the Plus button .
Select: Actions > Conditions/Loops > else if
For the condition text field type: password
eq "private"
Click on the Plus button .
Select: Actions > Movie Control > goto
Select the option: Go to and Stop
For the Type option use the drop down arrow to select: Frame
Label
For the Frame option use the drop down arrow to select: private
If someone types the password private they will go to the frame with the label
'private'. NB: You may have as many else if's as you want, each password
taking you to a different frame or web page.
Click on the Plus button .
Select: Actions > Conditions/Loops > else
Select: Actions > Movie Control > goto
Select the option: Go to and Stop
For the Type option use the drop down arrow to select: Frame
Label
For the Frame option use the drop down arrow to select: wrong
This means that if none of the first conditions are correct, the user will
be directed to the frame 'wrong'.
Click on the first line of the actionscript: on (release) {
Place a tick next to the option: Key press
Press Enter on the Keyboard and you should see <Enter>
appear in the box next to Key press tick.
This means that when the user may press enter on the keyboard rather than
using the mouse. NB: This will not work in Test Mode as Enter has a preset
meaning: Play the movie. But it will work when the movie is published to a
web page.
Your script should look like this:
on (release,
keyPress"<Enter>")
{ if (passwordeq"webwasp")
{ getURL(""); } else if (passwordeq"private")
{ gotoAndStop("private"); } else { gotoAndStop("wrong"); }
}
Step eight: Button actions - Retry frame 10
Go to frame: 10
Right click on the button called 'Retry' and select: Actions
Click on the Plus button .
Select: Actions > Movie Control > Go to
Click on the first line of the actionscript: on (release) {
Place a tick next to the option: Key press
Press Enter on the Keyboard and you should see <Enter>
appear in the box next to Key press tick.
Your script should look like this:
on (release, keyPress"<Enter>")
{ gotoAndStop(1);
}
Step nine: Button actions - Retry frame 20
The script for frame retry button on frame 20 is identical to
that of the retry button in frame 10.
Your movie should now be finished.
Security
Important: When you go to publish
your movie select the following settings: File > Publish Settings > Flash
> Compress Movie (Flash MX only). This makes it slightly harder for a hacker
to crack the password.
Note: If the password takes the user to a new web page, that
page is not necessarily secure but hidden. For high security material never
use Flash to protect your data or other material.