I have a variable called score in my flash game and I want to post the score from my flash game to a php file called test.php; the last part of the AS3 code when game is finished is:
function gameFinished(){
gameOver.play();
stage.removeEventListener(MouseEvent.CLICK, kick);
stage.removeEventListener(MouseEvent.MOUSE_MOVE, dragCursor);
Mouse.show();
again_btn.addEventListener(MouseEvent.MOUSE_DOWN, playAgain);
}
Here is where I want to publish my score var to the php file so I can use it in a leaderboard; I have read many tutorials but having a really hard time. Could you please guide me a little bit?
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;
}