duanhuihui2705 2011-09-20 19:57
浏览 32

使用Flash CS5上的PHP和XML将图像从Mysql加载到TileList

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条回答 默认 最新

  • doushizhou4477 2011-09-21 18:52
    关注

    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});
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效