Load images to a TileList from Mysql using PHP and XML on Flash CS5

佐手、 提交于 2019-12-12 18:22:17

问题


I have a mysql database with a table containing PATH's to images.

I want to load al the images to a TileList. Now i have this in PHP:

<?PHP

mysql_connect("localhost", "root", "root");
mysql_select_db("prototipo");

$result = mysql_query("select entretenimiento_id, e_nombre, e_imagen from          entretenimiento");

echo "<?xml version=\"1.0\" ?><entretenimiento>";

while($row = mysql_fetch_assoc($result))
{
    echo "<e_nombre>" . $row["e_nombre"] . "</e_nombre>";
    echo "<e_imagen>" . $row["e_imagen"] . "</e_imagen>";   
}

echo "</entretenimiento>";

?>

This is supposed to fetch me the PATH of the image, the name so it goes on the label of the tile that displays the image, and brings me also the id so i can launch another query when that image is clicked on.

All this is set into a dynamically created XML.

Now my question.... How do i load this??? What to do o AS3?? I already have the AS3 for the tilelist, i only need to load this dynamically created XML from PHP to it.

Thanks in advance. And sorry if i messed up on english, its not my main language. Im South American.


I have a partial answer:

var path:String = "http://localhost/entretenimiento.php";
xmlLoader:URLLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, onLoadComplete);
xmlLoader.load(new URLRequest(path));       

function onLoadComplete(e:Event):void {
    var xmlData:XML = new XML(e.target.data);
    //trace(xmlData);

    for (var i:int=0; i<xmlData.*.length(); i++)
    {
        myTileList.addItem({label:xmlData.e_nombre[i], source:xmlData.e_imagen[i]});
        //trace(xmlData.e_nombre[i]);
    }

}

Althought this shows me the images and the titles on the tiles, i also get two more tiles that are empty, and in the trace they are shown as "undefined". Any thoughts to why is this?


回答1:


Here is a sample code that should works :

var xmlLoader:URLLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, showXML);
// change the path of your php file
xmlLoader.load(new URLRequest("your-file.php"));
function showXML(e:Event):void
{
    var entretenimiento:XML = new XML(e.target.data);
    // for each row :
    for (var x:XML in entretenimiento.loc)
    {
        // Change the name of your tilelist
        myTileList.addItem({label:x.e_nombre, source:x.e_imagen});
    }
}


来源:https://stackoverflow.com/questions/7491037/load-images-to-a-tilelist-from-mysql-using-php-and-xml-on-flash-cs5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!