PDA

View Full Version : Getting PHP variable contents into Flash MX


jeffcravener
10-24-2003, 11:31 PM
Here is the code in the PHP file:


<?
$handle=opendir("\images");
$counter = 0;
while ($file = readdir($handle)) {

$the_type = strrchr($file, ".");
$is_picture = eregi("jpg",$the_type);

if ($file != "." and $file != ".." and $is_picture) {
$pics[$counter] = $file;
$counter++;
}
}
closedir($handle);
for ($i = 0; $i < count($pics); $i++){
$PicsList .= $mypics[$i] . "|";
}
$PicsList = substr ($PicsList, 0, -1);

echo ("&PicsList=$PicsList&");
?>



Here is what I have on a frame in flash:
varPics = new Array();
varReceiver = new LoadVars();
varReceiver.load("\\findpics.php");
varReceiver.onLoad = function(){
tmp = this.PicsList;
varPics = tmp.split("|");
PicTitle.text = varPics[0];
};


This is whats happeneing:

In the variable 'PicTitle.text', the varaible name from PHP is showing up: $PicsList, instead of the value in it

what am i doing wrong?

freddycodes
10-25-2003, 03:09 PM
Well first off you are not accessing the php file correctly. You should be using a proper url format \\findpics.php is not correct.

Does your php file work standalone. Menaing can you view it in the browser and see the file names? I think there are some problems with it as well.

I went ahead and changed some thing around. Remember that this example expects the full http path to the php script, and that there is a folder in the the same folder as the php script named images with the images in it.



<?php
$handle=dir("images/");
while ($file = $handle->read())
{
if(strtolower(substr($file, -3)) == "jpg")
{
$pics[] = $file;
}
}
$handle->close();
print implode("\n", $pics);
?>




varReceiver = new LoadVars();
varReceiver.load("http://freddy/images.php");
varReceiver.onData = function(raw){
varPics = raw.split("\n");
PicTitle.text = varPics[0];
};

jeffcravener
11-01-2003, 12:35 PM
worked perfectly!