Php > xml > flash

Hi. I´m new here. It looks good!

I have written a php script that outputs xml, in order to load that into flash. My problem is, when using the XML object, or loadVars object to call the php script, in only loads the contents of the script itself, and not its output into flash…

do i need to open an XML socket here, or is there some other way of passing the output of the script to flash?

thanks.

if you could give a url to the php script, and a piece of code how you load it up…

that would give us something to search at…

<?php



$directory = 'images';
$resc = opendir($directory);
if (!$resc) {
	echo "Problem opening directory $directory. Error: $php_errormsg";
	exit;
}
$images = array();
while ($filename = readdir($resc)) {
	if (is_file($directory . '/' . $filename)) {
		$images[] = $filename;	// Add to the array
	}
}

echo "
<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>";

echo "<books>";
echo "<club_del_misterio>";


$cnt = count($images);
for ($i = 0; $i < $cnt; $i++) {
	    echo "<book file=\"" . $images[$i]."\" />";	 // Display filename or do whatever

}

echo "</club_del_misterio>";
echo "</books>";


?>

there´s your php, i was asking theoretically, in terms of what is the best practice in this situation. This just thows up a well formed xml doc. As I said before, the loadVars object and xml object only load in the contents of the script, and not the output.

thanks

and a piece of code how you load it up…

please…

I ran into a problem sort of like this. I needed to put this code in:

header(“Content-type: text/xml”);
echo “
<?xml version=“1.0” encoding=“ISO-8859-1” ?>”;

shrug maybe that will work?

thanks. removed the /n from the xml declaration and now doesn’t throw up any error in firefox.

still doesn’t laod into flash tho :frowning:

will look at this later, working on four things at once!!

try this:


myXML = new XML();
myXML.ignoreWhite = true;
myXML.load("path_to_php_file.php");
myXML.onLoad = function(){
  readXML(this);
}
function readXML(xmlFile){
  trace(xmlFile)
}

that should work…

same as before mate.

a -6 status code, which means a non-formed xml doc, which points to the possibility of it loading the php contents rather then the xml…


myXML = new XML();
myXML.ignoreWhite = true;
myXML.load("http://work.longmate.net/dev/php/read_dir.php");
myXML.onLoad = function(){
  readXML(this);
}
function readXML(xmlFile){
  trace(xmlFile.firstChild.firstChild.childNodes[4])
} 

copy paste THAT !!! :stuck_out_tongue:

it should return:

edit:
conclusion: just ignore the error code and start using it ! :slight_smile:

edit2:


myXML = new XML();
myXML.ignoreWhite = true;
myXML.load("http://work.longmate.net/dev/php/read_dir.php");
myXML.onLoad = function(){
  readXML(this);
}
function readXML(xmlFile){
	SubFolders = xmlFile.firstChild.childNodes
	for(i=0;i<SubFolders.length;i++){
		SubName = SubFolders*.nodeName;
		trace("Scanning folder: "+SubName);
		Books = SubFolders*.childNodes;
		for(ii=0;ii<Books.length;ii++){
			BookImage = Books[ii].attributes.file;
			trace("	 - "+BookImage);
		}
	}
} 

see it works perfectly ! :slight_smile: