0

I'm trying to pass some variables from php to flash, im using this actionscript code:

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";
}

And this php code:

<?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]";

?>

both runs without errors, the problem is that what i get on flash aren't the variables values but the name of the variables, in other words what i get on vars.nickname is

$topScores[nickname] 

and for vars.score

$topScores[score]

If i run the php alone i get this:

&nickname=jonny&score=100

which are the actual variable values i'm trying to get, any help would be greatly appreciated.

4

1 回答 1

0

我认为您可能只是将 php 文件作为文本文件从 flash 中加载。您可以更改以下行:

new URLRequest("checkScores.php");

类似于:

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

或您在问题中所说的“运行”它时在浏览器地址栏中看到的任何内容。

于 2013-07-25T05:39:48.463 回答