This implements a data entry form and submits the entered data to another
web page.
Start Flash MX
Create a new file.
Set the canvas size to 400x200
Set the colour to some pale pastel shade.
Right click on frame 25 and select Insert Frame
Click on the Text Tool.
Set it to Input Text
Set the font name and size if you wish.
Set the font colour if you wish.
Click the "Show Border" button on.
Place four text input boxes onto the canvas.
Click the Arrow tool and select the top input box.
Set its X and Y properties to 20 and 20.
Set its width property to 200.
Repeat this procedure for the rest of the input boxes but set their
Y properties to 50, 80 and 110 to space them out properly.
Use the arrow tool to select the top Input Text.
Set the Var (variable name) to title.
Repeat the procedure for the other Input Text boxes and set their
names to firstName, lastName and dob (date of birth).
Right click on Layer 1 and select "Insert Layer".
Right click on Layer 2 Frame 2 and select "Convert to Keyframes".
Place a Static Text control onto Layer 2 Frame 2. Make sure the correct
frame is selected!
Place an error message into this text control. "Error : Title
is blank."
Select Layer 1 Frame 1
Click on a blank area of the canvas to ensure no control is selected.
Click on Actions Frame.
Click to select advanced mode.
Enter this code stop();
Place a Submit button onto Layer 1 Frame 1.
Change the Button label to "Submit.
Select the button and click on "Actions-Movie Clip".
Enter this code.
on (release)
{
if (_root.title == Null)
{
_root.gotoAndStop(2);
}
else
if (_root.firstName == Null)
{
_root.gotoAndStop(3);
}
else
if (_root.lastName == Null)
{
_root.gotoAndStop(4);
}
else
if (_root.dob == Null)
{
_root.gotoAndStop(5);
}
else
{
// ALL OK
url = "foo.php"; // web page url
url = url + "?"; // start "get" parameters
url = url + "title="; // field name equals
url = url + _root.title; // some value
url = url + "&"; // separator
url = url + "firstName="; // field name equals
url = url + _root.firstName; // some value
url = url + "&"; // separator
url = url + "lastName="; // field name equals
url = url + _root.lastName; // some value
url = url + "&"; // separator
url = url + "dob="; // field name equals
url = url + _root.dob; // another value
getUrl (url); // navigate to url
}
}
Add the rest of the error messages ...
Right click on Layer 2 Frame 3 and select "Convert to Blank Keyframes".
Select Layer 2 Frame 3 and place a Static Text control onto the canvas.
Set the text to "Error : First Name must not be Blank."
Right click on Layer 2 Frame 4 and select "Convert to Blank Keyframes".
Select Layer 2 Frame 4 and place a Static Text control onto the canvas.
Set the text to "Error : Last Name must not be Blank."
Right click on Layer 2 Frame 5 and select "Convert to Blank Keyframes".
Select Layer 2 Frame 5 and place a Static Text control onto the canvas.
Set the text to "Error : Date of Birth must not be Blank."
Right Click on Layer 1 Frame 2 and select "Convert to Blank Keyframe."
Click on Layer 1 Frame 2 and place a button onto the canvas.
Set the button label to "Reset".
Open up "Actions - Movie Clip" and attach this code to the
Reset Button.
on (release)
{
_root.gotoAndStop(1);
}
Add static text labels to make the UI more friendly.
Add graphics for the error messages to make the UI more friendly/interesting/ammusing.
You need a web page to recieve the data submitted by your Flash application.
This assumes you have a database called "foo" and a table named
"customer".
Here is an example ...
<?php
$title = $_GET['title'];
$firstName = $_GET['firstName'];
$lastName = $_GET['lastName'];
$dob = $_GET['dob'];
$link = mysql_connect("localhost", // Host name
"root", // User name (never use root in real life - Too insecure!)
"") // User password (never have a blank password in real life - Insecure!)
or die("<h5>Could not connect: </h5>" . mysql_error());
if (mysql_select_db ("foo")) // Use your own database and table name
{
$sql = "INSERT INTO customer
(title, last_name, first_name, date_of_birth)
VALUES
(\"$title\", \"$lastName\", \"$firstName\", \"$dob\")";
mysql_query($sql, $link);
mysql_close($link); }
?>
<html>
<head>
<title>Example Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<h4><strong>Execute :</strong> <?php echo $sql; ?></h4>
</body>
</html>