我需要在数据库中存储变量得分,这是我的代码:
AS2代码:
on(press)
{ var score = scorer.score
var myDataResponse:LoadVars = new LoadVars();
var myData:LoadVars = new LoadVars();
score.sendAndLoad("score.php", myDataResponse, "POST");
myDataResponse.onLoad = function() {
if (this.result == "OK") {
result= "Score Sent.";
} else {
result= this.result;
}
}
}
PHP代码:
<?php
$score = $_POST['score'];
$con = mysql_connect("localhost","root","");
mysql_select_db("test",$con);
$q = ("INSERT INTO score(count) VALUES ('$score')");
mysql_query($q) or die ("error");
?>
我在localhost中运行.swf,但没有保存分数
答案 0 :(得分:0)
更改onPress方法的AS3代码:
var loader : URLLoader = new URLLoader();
var request : URLRequest = new URLRequest("/score.php");
request.method = URLRequestMethod.POST;
var variables : URLVariables = new URLVariables();
variables.score = score;
request.data = variables;
// Handlers
loader.addEventListener(Event.COMPLETE, on_complete);
loader.load(request);
private function on_complete(e : Event):void{
result= "Score Sent.";
}