#native_company# #native_desc#
#native_cta#

Using PHP and MySQL with Flash Page 8

By Jeffrey F. Hill
on December 14, 2001

Actionscript used to Load the Variables into the Movie

In the 4th frame of the movie the following actionscript is attached to a frame:

// Loads the Variables
loadVariablesNum ("Load.php?Name="+Name, 0);
gotoAndPlay (6);

What this does is to load the variables from the database and stick them into the movie. The variables that get loaded are the x and y coordinates for each of the three objects in the movie. After it makes the call to the script it goes onto Play Frame 6 of the Movie. We let the script play for a couple frames then check to see if the variables have been loaded. If they have been loaded we continue on in the movie. If not we continue to wait until they are. We do not need to check if they’ve all been loaded so we just check to see if the variable Comment has been loaded from the Database. Here’s the script for the second check. Which brings us to the final stage of the tutorial.

if (Comment ne "") {
    setProperty ("Object1", _x, xO1);
    setProperty ("Object1", _y, yO1);
    setProperty ("Object2", _x, xO2);
    setProperty ("Object2", _y, yO2);
    setProperty ("Object3", _x, xO3);
    setProperty ("Object3", _y, yO3);
    gotoAndPlay (19);
}
else {
    gotoAndPlay (6);
}
Notice how that unless Comment has a value it will loop back to Frame Number 6. If Comment is equal to a value then it will set the x and y positions of the movie clips then continue and Play Frame number 19.
Updating the Variables in the Database
The last part of this tutorial involves updating the variables x and y position in the database as well as the user entered comment. First we need to use actionscript to get the x and y positions of the movie clips as they are moved around by the user.

O1x = math.floor(getProperty(_root.Object1, _x));
O1y = math.floor(getProperty(_root.Object1, _y));
O2x = math.floor(getProperty(_root.Object2, _x));
O2y = math.floor(getProperty(_root.Object2, _y));
O3x = math.floor(getProperty(_root.Object3, _x));
O3y = math.floor(getProperty(_root.Object3, _y));
This is done simply by using the getProperty function to return the x and y position of each movie clip. I also use the math.floor function so that the x and y positions are rounded to the nearest integer. This is not necessary but why have all those extra numbers in your database when no one will ever no the difference. This is repeated twice. Then on the last frame it continues to loop back to the first instance of this code so that they postitions are continually updated.

The PHP used in updating the x and y positions along with the Comment (Update.php)


$query = "UPDATE saveMovie SET Object1='xO1=$O1x&yO1=$O1y&',  Object2='xO2=$O2x&yO2=$O2y&', 
Object3='xO3=$O3x&yO3=$O3y' , Comment='$Comment'  WHERE Name='$Name'";
$result = mysql_query($query);

print "_root.UpdateStatus=Success Updated - It's saved $Name";

This part of the script updates and sets the variables from the movie to the database. Basically this takes the values that you obtained with the getProperty function and sticks them in the database. The print statement just lets you know that everything went successfully.

1
|
2
|
3
|
4
|
5
|
6
|
7
|
8
|
9