【发布时间】:2013-07-24 17:23:47
【问题描述】:
我正在尝试将一些变量从 php 传递到 flash,我正在使用这个 actionscript 代码:
public function gameOver(score:Number)
{
totalScore.text = score.toString();
var scriptVars:URLVariables = new URLVariables();
scriptVars.score = score;
var scriptLoader:URLLoader = new URLLoader();
var scriptRequest:URLRequest = new URLRequest("checkScores.php");
scriptRequest.method = URLRequestMethod.POST;
scriptRequest.data = scriptVars;
scriptLoader.load(scriptRequest);
scriptLoader.addEventListener(Event.COMPLETE, handleLoadSuccessful);
scriptLoader.addEventListener(IOErrorEvent.IO_ERROR, handleLoadError);
}
function handleLoadSuccessful(e:Event):void
{
trace("Scores Loaded");
var vars:URLVariables = new URLVariables(e.target.data);
nickname1.text = vars.nickname;
score1.text = vars.score;
}
function handleLoadError($evt:IOErrorEvent):void
{
trace("Load failed.");
nickname1.text ="error";
}
还有这个 php 代码:
<?php
... some code for the mysql connection and select sentence ...
$topScores = mysqli_query($con, $topScores);
$topScores = mysqli_fetch_array($topScores);
echo "&nickname=$topScores[nickname]&score=$topScores[score]";
?>
两者都运行没有错误,问题是我在闪存上得到的不是变量值而是变量的名称,换句话说,我在 vars.nickname 上得到的是
$topScores[nickname]
对于 vars.score
$topScores[score]
如果我单独运行 php,我会得到这个:
&nickname=jonny&score=100
这是我试图获得的实际变量值,任何帮助将不胜感激。
【问题讨论】:
标签: php mysql flash actionscript echo