PDA

View Full Version : PHP Generates populates Flash text?


spmccain
08-04-2004, 08:36 AM
I can't find an answer to my problem: I have created a SWF with a three dynamic text fields, Title, Link and Content. I would like to be able to create and instance of this Flash for every row in the database table I am querying.

For instance:
in the PHP file that hosts the FLash instances.

<?
//query returns rows of topics
/* For each (row in result) do
SWF goes here, with its dynamic text boxes correctly
populated by data from the current row
end forloop */

?>

So far in my research I have come to the conclusion that since Flash is client side and PHP is server side I lack a key to their crucial connectivity. Maybe through XML? I don't know, but I don't want to be more complicated than it is actually worth. Ideas please?!

Shawn

snapple
08-04-2004, 09:23 AM
spmccain,

There is no need to complicate things with XML. Just use Flash > PHP (they are more then capable of talking to each other).

Lets say you want to duplicate a movieclip in Flash for every entry in a database - so your php might look something like this (in this case there is a field called "draw_name") don't worry about how it got there just yet:


$myNames = $_POST['myNames'];
$res = mysql_db_query ( "images","SELECT draw_name FROM draw" );
$tmpStr = "";

while ($entry = mysql_fetch_array ( $res ))
{
$tmpStr = $tmpStr . $entry["draw_name"] . ",";
}

mysql_free_result($res);
$myNames = $tmpStr;
print "myNames=$tmpStr";


This would output a string of commer seperated names like "Andy, James, Charlotte, Amy...etc" to flash (Flash and php are not, i found out the other day, capable of sharing data structures, such as arrays) - so once you have that string into Flash, you can split it into an array using actionscript like this:


getNames_lv = new LoadVars();
getNames_lv.load("myphpFile.php");
getNames_lv.onLoad = function (worked)
{
if(worked)
{
outPut();
}
};
function outPut ()
{
storeNames = getNames_lv.myNames.split(",");
}

//You could then duplicate an mc depending on the length of your array
function createMenu()
{
myHeight =0;
for(var g=0; g<storeNames.length-1; g++)
{

_root.holder.dupClip.duplicateMovieClip("userCoord||"+g, g);
_root.holder["userCoord||"+g]._visible = true;
_root.holder["userCoord||"+g]._y = myHeight;
myHeight += 20;
}
}


Here an array called "storeNames" now holds "Andy, James, Charlotte, Amy...etc" - if you get the length of the array and perform an action depending on the result - your nearly there!!!

Generally thats how the whole thing would work. If you do a search for "loadVars()" on this site - you'll have more than enough to help you.

Hope this has been helpful.

Regards, snapple :)

spmccain
08-04-2004, 05:53 PM
thanks snapple,That does help in my understanding of their communication however it's not exaclty what I need. I think, It might be I could just be an idiot. I want to be able to duplicate the movie outside of the "root" layer. For each record in the database I want to pump out another instance of the movie clip that is independent of the others. For instance, another Flash file placed in the HTML of a page. Not another movie clip duplicated within the same Flash Player. does that make sense? If I am just mistaken than please clarify.

I see this practice in PHP especially with buttons, for every element in a array, print out another button. or in PHPNuke sites, for every block or Story print out another layer or table. hope this helps my case.!

Shawn