我需要在 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()
谢谢你的回答。