flash data integration:
Hi,
I have a php script that generates an xml file from a mysql database with a
list of media. I want to get flash to read the generated xml and store the data
in objects to be used later.
How do I read the xml data with flash?
Ive attach my code in 3 stage, the PHP, the Flash and the XML file which the
PHP generates.
Cheers
(CRS)
<?php
if(!$dbconnect = mysql_connect('localhost', 'root', 'admin')) {
echo "Connection failed to the host 'localhost'.";
exit;
}
if (!mysql_select_db('products')) {
echo "Cannot connect to database 'test'";
exit;
}
$table_id = 'images_xml_test';
$query = "SELECT * FROM $table_id";
$dbresult = mysql_query($query, $dbconnect);
// create a new XML document
$doc = new DomDocument('1.0');
// create root node
$root = $doc->createElement('media');
$root = $doc->appendChild($root);
$count=0;
while($row = mysql_fetch_assoc($dbresult)) {
$count++;
// add node for each row
$element=image;
$occ = $doc->createElement($element);
$occ = $root->appendChild($occ);
// add a child node for each field
foreach ($row as $fieldname => $fieldvalue) {
$child = $doc->createAttribute($fieldname);
$child = $occ->appendChild($child);
$value = $doc->createTextNode($fieldvalue);
$value = $child->appendChild($value);
} // foreach
} // while
// get completed xml document
$xml_string = $doc->saveXML();
print $xml_string;
?>
//////////////////////////////////////////////////////
My failed flash attempt
**************************************************
var myXML:XML = new XML();
myXML.ignoreWhite = true;
myXML.onLoad = function(success:Boolean):Void {
if (success) {
var mediaNode:XMLNode = this.firstChild;
if (mediaNode.hasChildNodes()) {
var imageArray:Array = new Array();
for (var i:Number = 0; i != mediaNode.childNodes.length; i++) {
var node:XMLNode = mediaNode.childNodes[i];
var obj:Object = new Object();
obj.id=node.attributes.label;
obj.label = node.attributes.label;
obj.data = node.attributes.data;
imageArray.push(obj);
}
}
list.dataProvider = imageArray;
}
};
theXML.load("http://localhost/products/fetch_assoc1.php");
//**********************************************************************
//the structure of my xml that the php has generated
//*********************************************
<?xml version="1.0"?>
<media>
<image id="1" url="images/aStudyInTexture.jpg" label="StudyInTexture"/>
<image id="2" url="images/buntzenWinter.jpg" label="buntzenWinter"/>
<image id="3" url="images/flowerInDetail.jpg" label="flowerInDetail"/>
<image id="4" url="images/flowerInDetail.jpg" label="flowerInDetail"/>
</media>