我使用 as3、mysql 和 php,尝试发送用户名并接收(积分)并将积分发布在舞台上的文本对象中,我可以使用类似的脚本将积分发送到服务器,但可以取回数字!
// global variables
var loader:URLLoader;
var urlReq:URLRequest;
var urlVars:URLVariables;
var myVars:URLVariables;
addEventListener(Event.ENTER_FRAME, onit);
function onit(e:Event):void
{
urlReq = new URLRequest("http://www.mysite.com/GetPoints.php");
urlReq.method = URLRequestMethod.POST;
urlVars = new URLVariables();
urlReq.data = urlVars;
urlVars.username = nickname_txt.text;
loader = new URLLoader(urlReq);
loader.addEventListener(Event.COMPLETE, onUpdateComplete);
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.load(urlReq);
}
function onUpdateComplete(e:Event):void
{
myVars = e.target.data;
totalP.text = myVars.total;
}
php 在浏览器中执行时重新运行这些点,但未连接到 flash。
<?php
$username = $_POST["username"];
// defining main variables
$dbHost = "localhost";
$dbUser = "";
$dbPass = "";
$dbName = "";
$dbTable = "`".$username."_points`";
@mysql_connect($dbHost, $dbUser, $dbPass) or die(mysql_error());
@mysql_select_db($dbName) or die(mysql_error());
$data = "";
$res = mysql_query("SELECT * FROM ".$dbTable." ORDER BY id") or die(mysql_error());
while($row = mysql_fetch_object($res)) {
$data = "total=".$row->total;
print $data;
}
?>
任何帮助将不胜感激 !