0

我需要在 Flash 中制作 TOP 10 玩家表。当我单击“TOP 10”按钮时,它必须从数据库中获取数据并在游戏屏幕上打印列表。我想在这里做的是愿景:

我的应用

我已经从 PHP 动态创建了 XML,并且必须将数据发送到 Action Script 3。

这是 top.php 文件

<?php 
    $time = $_POST['time'];     
    session_start();
    $name = $_SESSION['vardas']; 
    $time = strtotime($time);
    $times = date('s:H:i', $time);
    $_SESSION['test'] = $times;
    $_SESSION['test1'] = $username;


    $mysqli = new mysqli("localhost","my_db","pass","my_db");

    $query = "SELECT userName,time FROM eurokos ORDER by time ASC LIMIT 10";
if (!$mysqli->set_charset("utf8")) {
    printf("Error loading character set utf8: %s\n", $mysqli->error);
} else {
//    printf(" ", $mysqli->character_set_name());
}
    echo '<?xml version="1.0" encoding="UTF-8"?>';
    echo '<results>';
    if ($result = $mysqli->query($query)) {
        while ($row = $result->fetch_assoc()) {
           echo '<user name="'.$row["userName"].'" time="'.$row["time"].'" />';
        }
        $result->free();
    }
    echo '</results>';
    $mysqli->close();
?>

XML 看起来像:

<?xml version="1.0" encoding="UTF-8"?>
  <results>
    <user name="someone" time="xxx" />
    <user name="someone" time="xxx" />
    [...]
</results>

这是我的动作脚本代码:

 var myXml:XML;

    function uploadTops():void
    {
        var myLoader:URLLoader = new URLLoader();
        myLoader.load(new URLRequest("top.php"));
        myLoader.addEventListener(Event.COMPLETE, processXML);
    }
    function processXML(e:Event):void {
    myXml = new XML(e.target.data);
    trace(myXml);
    }
    function myButton(e:MouseEvent):void
    {
        uploadTops();
    //  _message = myXml.user.*; //these lines are wrong, I donn't know how to print answer
    //  message_txt.text = _message;
    }

我收到错误:

Error #1090: XML parser failure: element is malformed. when trying to trace

at MemoryGame/processXML()[C:\Users\Petras\Downloads\geraseaa\geraseaa\gerase\MemoryGame.as:570]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()

谢谢你的回答。

4

1 回答 1

0

尝试用浏览器打开你的 XML 文件,然后查看它的源代码,这样你就会知道你的 XML 文件到底出了什么问题。
如果你将在你的 php 文件中添加这一行,这是可能的:

 header('Content-Type: text/xml');

在此行之前:

 echo '<?xml version="1.0" encoding="UTF-8"?>';

我会帮你的

于 2013-05-11T12:51:43.360 回答