PDA

View Full Version : php to flash



nexx
December 1st, 2005, 05:36 PM
I have an error doing one of the tutorials on the website

trying to pass an 'echoed' data from PHP to FLASH array, Im sure its fine on PHP side, but in flash I got an error:

Error opening URL
"images/pics/test/undefined (file:///C|/phpdev/www/vfourorg3/images/pics/testing/undefined)"

Could anyone help pls.



files = new Array();
lv = new LoadVars();
lv.onLoad = function() {
fl = this.flashVar;
files = fl.split(",");
c = files.length-1;
for (i=0; i<c; i++) {
this.pArray = files[i]; // fill array with variables
}
};
lV.load('http://localhost/test4.php');

this.pathToPics = "images/pics/test/"; //

el endemoniau
December 2nd, 2005, 05:54 AM
Did you tried with senAndLoad?.

lV.sendAndLoad("http://localhost/test4.php",lv,"POST");

or

lV.sendAndLoad("http://127.0.0.1/test4.php",lv,"POST");

nexx
December 3rd, 2005, 02:32 PM
Did you tried with senAndLoad?.

lV.sendAndLoad("http://localhost/test4.php",lv,"POST");

or

lV.sendAndLoad("http://127.0.0.1/test4.php",lv,"POST");

doesn't work same error, really puzzles me
reckon doesn't get that data from php at all

php code


echo "flashVar=";
while($row = mysql_fetch_array($sql))
{
echo $var= $row["var"].",";

}
echo "null";

bigmtnskier
December 3rd, 2005, 05:35 PM
Yeah, It is your php if I'm not mistaken.


echo "flashVar=";
while($row = mysql_fetch_row($sql)){
echo $var= $row[0].",";
}
echo "null";

Try that^^^ Mysql_fetch_array returns all the rows at once, therefore rendering a while loop pointless. Mysql_fetch_row however, returns the current row and moves on. If you still want to use mysql_fetch_array you could do this I believe:



echo "flashVar=";
$rows = mysql_fetch_array($sql);
foreach($rows as $row){
echo $var= $row["var"].",";
}
echo "null";


I hope this helps :)
-Bigmtnskier

nexx
December 3rd, 2005, 06:24 PM
'Mysql_fetch_array returns all the rows at once.'


I dont think it does, it returns one row at a time thats why you need while loop.
Otherwise you gonna get a first row and thats it.

Try it yourself and look at the output.

bigmtnskier
December 3rd, 2005, 06:28 PM
Oops, my bad.. I guess my mind was elsewhere...

I think one of the problems is you need an &symbol in front of the variable name

nexx
December 5th, 2005, 09:51 AM
Oops, my bad.. I guess my mind was elsewhere...

I think one of the problems is you need an &symbol in front of the variable name

thats only if I was doing it through GET with induvidual vars, I load all variables into flashVar then get rid of "," and make an array.

el endemoniau
December 5th, 2005, 10:26 AM
It work for me.......

$var="";
while($row = mysql_fetch_row($sql)){
$var .= $row[0].",";
}
echo "var_to_flash=$var&";

nexx
December 5th, 2005, 11:09 AM
same php output as with my code, except you get & before null

Dont see why you would need & in array?

I pass only one var to flash, it happenes to be a long string.
Then i get rid of commas and convert it into array with induvidual vars

unfortunatelly it still does not work

nexx
December 5th, 2005, 02:27 PM
definetely not PHP, I can trace the passed vars in flash.
Something to do with assigning one array to another.

I'm new to actionscript thats why cant figure it out. Can you assign one var/array to another just by using = operator or you need something else?

el endemoniau
December 9th, 2005, 04:49 PM
maybe something will be useful, maybe not......

1)Not exactly the same code.... check in $var .= $row[0].","; there's a "." before "=" to add every result. Otherwise php will return only the last result.

2)In your code: files = fl.split(","); you create an array, so there's no need to create a new array in this.pArray = files[i];. Just use the "files" array.

3)Try to add a slash in :
this.pathToPics = "/images/pics/test/";

4)An example of SendAndLoad (the best way i found to use with php):

MyFunction=function(){
lv = new LoadVars();
lv.myvar="";
lv.onLoad=function(sucess){
if (sucess){
files = lv.myvar.split(",");
}
else {
trace ("oops!");
}
}
lv.sendAndLoad ('http://localhost/test4.php',lv,"POST (http://127.0.0.1/tn/buscartipol.php)");
}

then in php:

$var="";
while($row = mysql_fetch_row($sql)){
$var .= $row[0].",";
}
echo "myvar=$var&";

:puzzle: are we in the right way?