Load images to a TileList from Mysql using PHP and

2019-07-17 21:56发布

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条回答
一纸荒年 Trace。
2楼-- · 2019-07-17 22:03

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});
    }
}
查看更多
登录 后发表回答