hide side navigation
    5 most recent
    Web Services
    Library's
    Component's
    Applications
    Articles
  Flash button as Flex icon  Flex form by email  Hello Remoting with AS3  AS3 Saving data from Flash  AS3 Loading data into Flash  Fire Effect  Contact form  Dragable buttons  Hello World with openamf  Loading helper classes  Upload with Flash 8  Transitions effects  Snapshot with Flash 8  Hello World Remoting AS2  Flash AS2 Remoting Connector  Saving data from Flash  Loading data into Flash  FlashCom & Remoting login  Cell Renderer API  Editing a table using remoting components  Flash MX2004 web service classes  Browsing a catalog  amfphp Documentation  Hello World Remoting  Online Store with AMFPHP  Flash clients for Web Services  Web Service Walk Though with NuSoap  Popup windows in flash with javascript  Installing Apache/PHP  MoreOver News Feeds  Load Edit Save Text Files via CGI  Save Movie Clip Postion via PHP and MySQL
Current Page (4) << Previous Page | Next Page >>  View Article Example >> 1 | 2 | 3 | 4 | 5

Loading the Variables

PHP used the Loading Variables Part (Load.php)

The load variables part is not important the first time a user enters the room.  It does become important when a user moves the objects then returns to the room at a later time.  This is what loads them all into the same place as when the user left.  It also Loads a comment that the user can optionally leave. Here's what the basic script looks like.  Again it is strongly recommended to follow along by also reading the php script. They are commented in much more detail. 

$result = mysql_query("SELECT * FROM $table WHERE Name = '$Name'");
     ##This sets the variables from the Database
     $Comment = mysql_result($result,0,"Comment");
     $Object1 = mysql_result($result,0,"Object1");
     $Object2 = mysql_result($result,0,"Object2");
     $Object3 = mysql_result($result,0,"Object3");
 if ($Comment == "") {
$Comment = "Hello $Name";
}
#This next bit prints out the value's of the Comment and the positions 
#of the three objects whose properties you want to save. This is the line that Flash will read into the movie. 

print "Comment=$Comment&$Object1$Object2$Object3";

The first line of code just selects the record in the database where the Name that the person Logged in as matches the Name in the Database. After this each column in the result record set is set to a variable.  This basically just extracts the result you got from the query and puts it into variables that you can use.  The if statement is necessary to make sure that the Comment variable contains some value. This will be explained later.  The last line of Code prints the results back to Flash.  Notice how Object1, Object2, and Object3 are not separated by the & symbol. This is because the & symbols already exist in the database - when you update the database these are included. Not necessary but just makes it easier.

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 3 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 buy 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 set's 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.

The Actionscript used for updating the variables

on (release) {
	loadVariablesNum ("Update.php?Name="+Name+"&Comment="+Comment+"&O1x="+O1x+"
	&O1y="+O1y+"&O2x="+O2x+"&O2y="+O2y+"&O3x="+O3x+"&O3y="+O3y, "0");
	_root.UpdateStatus = "Updating..";
}

This part is probably easier accomplished by just using the "Post" option of the loadVariablesNum function -which will load all the variables in the movie to the script. But I just attached them all onto the end of the url to the php script.  Mostly because it's easier to test and you know exactly what is being passed. 

Current Page (4) << Previous Page | Next Page >> 1 | 2 | 3 | 4 | 5