1. Code
  2. ActionScript

Create a Flash Login System Using PHP and MySQL – Part 2


In Part 1 we created the front end login system for users to enter their details. In this tutorial we will create a registry form that will allow users to register. This will then add their details to the database, after which they will be able to login.

Step 1: Setup Document Class

Firstly, let's setup our document class and Flash file. Open a new Flash file, then call it register.fla. Next, create an actionscript file and call it

Then type register in the class text field in the Properties panel.

Step 2: Setup Code Structure

Now we have connected our document to our code, we need to create our class in the as file.

Step 3: Create The Registry Form Interface

Draw a 460x300px filled rectangle and choose what background color you like. Create the title - Register With Us - and a text field - Register.

Your interface should look like this:

Step 4: Setup The Form Fields

Create three input text fields with the instance names of username_text, password_text and userbio_text.

Step 5: Create The Register Button

Click the text field with "Register" that you created in Step 3 and convert it to a movie clip. Give it an instance name of register_button.

By now your interface should look like this:

Step 6: Create The Result Text

Create a new dynamic textfield next to the register and give it an instance name of result_text. We have completed all the objects we need. Our finished interface should look like this.

Step 7: Get Assets From Part 1

To save you time I will not cover the connection in this Part as you can learn that in Part 1. Get the connect.php from the php folder in Part 1. I have also included it in the Part 2 Source zip download.

That's all we need from Part 1. Now let's create the actionscript code.

Step 8: Create Object Settings - Register Button

First we need to give the register button a rollover cursor. We do this by using the buttonMode property.

That is all we need to do to format our register button.

Step 9: Setting up The Register Button

We now need our register button to run a function that validates the input of a user. We can do this by adding an event listener and triggering the function when the user presses the button.

Step 10: Validate the Form

Before the user can submit the form they have to fill in all the fields. Remember to import the* classes into your AS file. Follow the comments...

Step 10: Set up the URLVariables Class

Remember to import the* classes into your AS file. The URLVariables class is used to store data in that you would send off to a external source at a later date.

We need to create a variable to hold this data in:

var phpVars:URLVariables = new URLVariables();

We use instance variables to store data:

Step 11: Set up the URLRequest Class

Next we need to make a URL request to get the location of our php file. This URLRequest is also what we pass our php variables through. When we load this request the php variables are sent to the php file.

Step 12: Set up the URLLoader Class

The URLLoader Class allows you send & receive data from external sources. In this case we will be sending our URLVariables data to the php file via our URLRequest. Follow the comments...

Step 13: Create the showResult() Function

In the sendForm() function we added a listener to run the showResult() function when the php file had been executed. Now let's create it...

Step 14: Create the PHP File

Create a new php file, name it register.php and save it in a new folder called php.

Step 15: Flash to PHP Communication

In order to continue we need to be sure whether our php and Flash files are talking to each other. Open your text editor of choice and open the register.php you just created. Again, follow the comments...

Now upload the files to your server for testing and check it out. If the resultant text is now the same as the username you have successful communication between Flash and php. Now delete the contents of register.php.

Step 16: Include Connection File

Now we have successful connection we can connect to our database from Part 1. We do this by including our connect.php file we made in Part 1.

Step 17: Create POST Vars

We need to create POST vars to receive the php vars we sent and defined as POST variables.

Step 18: Create the SQL Statement

Let's now create the SQL statement that will add our values and store them in a new record in the database. Follow the comments..

Step 19: Back to Flash

Step 20: Completed PHP Script

Step 21: Completed ActionScript File


Now you can go to the demo, register, then go to the login page and try it out. Thanks for reading this two-part series!

Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.