我正在創建一個使用sharedObject來保存每個玩家本地進度的遊戲。它還連接到中央數據庫以創建在線記分牌。當用戶首次插入分數時,唯一ID將從數據庫發送到swf並作爲sharedObject數據的一部分進行保存。Flash AS2 - 幫助將使用PHP從mySQL導入的變量保存到sharedObject中?
絕對一切正常,並且ID保存到sharedObject,但是當swf重新啓動時,ID不會加載(即使保存在sharedObject中的其他變量也會加載)。
我認爲這可能與它被格式化的方式有關,也許與XML有關,但我不確定。
閃存代碼
function saveGame(currID:Number) {
gameInfo.data["playername"+currID] = playername;
gameInfo.data["playerscore"+currID] = playerscore;
gameInfo.data["playerID"+currID] = playerID;
gameInfo.data["playerLevel"+currID] = playerLevel;
for(i=1; i<6; i++){
gameInfo.data["level"+i+"Score"+currID] = ["level"+i+"Score"];
}
gameInfo.flush();
}
function loadGame(currID:Number) {
playername = gameInfo.data["playername"+currID];
playerscore = gameInfo.data["playerscore"+currID];
playerID = gameInfo.data["playerID"+currID];
playerLevel = gameInfo.data["playerLevel"+currID];
}
function scoreboardSubmit() {
var insertReceive:XML = new XML();
insertReceive.ignoreWhite = true;
insertReceive.onLoad = function() {
playerID = this.firstChild.childNodes[0];
saveGame(currID);
};
insertSend = new LoadVars();
insertSend.playername = playername;
insertSend.playerscore = playerscore;
insertSend.playerID = playerID;
insertSend.sendAndLoad("scoreboardSend.php", insertReceive, "POST");
}
PHP代碼
<?php
$name = strip_tags($_POST['playername']);
$score = $_POST['playerscore'];
$id = $_POST['playerID'];
$con = mysql_connect("localhost","******","******");
mysql_select_db("******", $con);
if ($id == 0)
{
$insert="INSERT INTO scoreboard (Name, Score)
VALUES
('$name','$score')";
mysql_query($insert,$con);
$returnID = mysql_query("SELECT LAST_INSERT_ID()");
$playerID = mysql_result($returnID,0);
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
echo "<returnID>" . $playerID . "</returnID>\n";
}
else
{
$update = mysql_query("UPDATE scoreboard SET Name = '$name', Score = '$score'
WHERE id = '$id'",$con);
}
mysql_close($con);
?>