将AS3得分变量发送到PHP文件

时间:2012-08-24 22:47:20

标签: php actionscript-3 variables

我的flash游戏中有一个名为score的变量,我想将我的flash游戏中的分数发布到名为test.php的php文件中;游戏结束时AS3代码的最后一部分是:

function gameFinished(){
gameOver.play();
stage.removeEventListener(MouseEvent.CLICK, kick);
stage.removeEventListener(MouseEvent.MOUSE_MOVE, dragCursor);
Mouse.show();
again_btn.addEventListener(MouseEvent.MOUSE_DOWN, playAgain);
}

这是我想将我的得分var发布到php文件的地方,所以我可以在排行榜中使用它;我已经阅读了很多教程,但真的很难。你能指导我一点吗?

1 个答案:

答案 0 :(得分:4)

AS3:

function gameFinished(){
   ...
   again_btn.addEventListener(MouseEvent.MOUSE_DOWN, playAgain);

   var urlLoader:URLLoader = new URLLoader();
   var req:URLrequest = new URLRequest("test.php");
   var requestVars:URLVariables = new URLVariables();
   requestVars.score = 150; //your scroe here
   req.data = requestVars;
   req.method = URLRequestMethod.POST;
   urlLoader.load(req);
   urlLoader.addEventListener(Event.COMPLETE, scoreSent);
}

function scoreSent(e:Event){
  trace("score sent to php");
}

PHP:

if(isset($_POST["score"])){
  //submit the score;
}