PDA

View Full Version : Flash and php?


moe122
03-07-2008, 09:55 PM
hey
i want to use some flash for a certain bit but for it i also need to use php......can i use php in flash?

davidj
03-07-2008, 10:16 PM
you can pass variables from one to another

moe122
03-07-2008, 11:04 PM
what you mean by that?

davidj
03-08-2008, 06:01 AM
imagine having a flash form which can communicate to a db using PHP

your forms could be animated using the power of flash but have the connectivity of php

this is beyond the scope of this forum as teaching you how to do this would take all my time. Go to amazon and buy a book

moe122
03-08-2008, 11:59 AM
ok i've done the following, dont know if you be able to help but i would appreciate it if you can......

created a php file.....products....

<?php
// database connection
$database = "TIJ";
$username = "moe";
$password = "balance";
/////

$link = mysql_connect("localhost",$username,$password);
$db = mysql_select_db($database,$link);
$query = sprintf("SELECT * FROM clients");
$result = @mysql_query($query);
$rowAccount = @mysql_fetch_array($result);
echo "<?xml version=\"1.0\"?>\n";
echo "<products>\n";
while($line = mysql_fetch_assoc($result)){
echo "<item>" . $rowAccount["First_Name"] . "</item\n";
}
echo "</products>\n";
mysql_close($link);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
</body>
</html>


ive then opend flash and created 2 layers
1 list
2 action
in list ive put in a list component
in action ive written the following code

var theXML:XML = new XML();
theXML.ignoreWhite = true;
theXML.onLoad = function() {
var nodes = this.firstChild.childNodes;
for(i=0;i<nodes.length;i++) {
theList.addItem(nodes[i].firstChild.nodeValue,i);
}
}
theXML.load("products.php");

and i get get a blank flash preview with the list component but no data

davidj
03-08-2008, 02:26 PM
sorry

i dont use this

davidj
03-08-2008, 02:28 PM
http://www.kirupa.com/developer/actionscript/flash_php_mysql.htm

http://www.adobe.com/devnet/flash/articles/flashmx_php.html

moe122
03-09-2008, 04:33 PM
ok not much luck with them.....i found another tut tho but have a smallproblem with it....the tut seems quite simple though

ok in php we have

<?PHP
$dataForCombobox_1 = "This is our FIRST variable,get ready combobox here I come";
$dataForCombobox_2 = "This is our SECOND variable,get ready combobox here I come";
$dataForCombobox_3 = "This is our THIRD variable,get ready combobox here I come";
$dataForListbox_1 = "This is our FIRST variable,get ready listbox here I come";
$dataForListbox_2 = "This is our SECOND variable,get ready listbox here I come";
$dataForListbox_3 = "This is our THIRD variable,get ready listbox here I come";
$dataForTxtbox_1 = "This is our FIRST variable,get ready textbox here I come";
$dataForTxtbox_2 = "This is our SECOND variable,get ready textbox here I come";
$dataForTxtbox_3 = "This is our THIRD variable,get ready textbox here I come";
print("&comboData1=$dataForCombobox_1");
print("&comboData2=$dataForCombobox_2");
print("&comboData3=$dataForCombobox_3");
print("&listbData1=$dataForListbox_1");
print("&listbData2=$dataForListbox_2");
print("&listbData3=$dataForListbox_3");
print("&textbData1=$dataForTxtbox_1");
print("&textbData2=$dataForTxtbox_2");
print("&textbData3=$dataForTxtbox_3");
?>

then in flash we have

// first we make a new loadvars object to hold the variables that are being loaded from the php filr
myData = new LoadVars();
//this is the part where we execute the function that handles the loaded data
myData.onLoad = function(){
placeTheDataIntoTheRightPlace();//call the function
};
//here we load in the php file, make sure you set the right path to your file
myData.load("myData.php");
//this is the function that handles the data.
//the variables now sorta live in the loadVars object we set named myData
//So we can call em like myData.myVariableInthePhpPrintedString
//just look at the script and whatch carefullt how its being called and it should become clear to ya.
placeTheDataIntoTheRightPlace = function(){
myComboBox.addItemAt(0,myData.comboData1);
myComboBox.addItemAt(1,myData.comboData2);
myComboBox.addItemAt(2,myData.comboData3);
myListBox.addItemAt(0,myData.listbData1);
myListBox.addItemAt(1,myData.listbData2);
myListBox.addItemAt(2,myData.listbData3);
txtBox1.text = myData.textbData1;
txtBox2.text = myData.textbData2;
txtBox3.text = myData.textbData3;
};


the problem is that instead of recognising what the $variables are flash jus catches whatevers after the &variables so ....
instead of having.....This is our first variable...... it has .....$dataForCombo.....

davidj
03-09-2008, 04:52 PM
if your sorted with this then great

if your having problems with it then contact the author of the tutorial

moe122
03-09-2008, 04:57 PM
yh i have but i was hoping you might have some ideas?

davidj
03-09-2008, 04:58 PM
i dont use this so cant help further

moe122
03-09-2008, 05:00 PM
ok thnx newayz