echo不在php actionscript连接上返回变量值

时间:2013-07-25 01:28:09

标签: php mysql flash actionscript echo

我正在尝试将一些变量从php传递给flash,我使用这个动作脚本代码:

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

这是我想要获得的实际变量值,任何帮助都将非常感激。

1 个答案:

答案 0 :(得分:0)

我想你可能只是将php文件作为flash文本文件加载。你能改变以下一行:

new URLRequest("checkScores.php");

类似于:

new URLRequest("http://localhost/checkScores.php");

或者当您按照问题中的说法“运行”它时,您在浏览器地址栏中看到的任何内容。