I am creating a game which uses the sharedObject to save each players progress locally. It also connects to a central database to create an online scoreboard. When a user inserts a score for the first time a unique ID is sent out of the database to the swf and saved as part of the sharedObject data.
Absolutely everything works and the ID is saved to the sharedObject, however when the swf is restarted the ID does not load (even though the other variables saved in the sharedObject do load).
I think it may be to do with the way it is formatted, perhaps to do with the XML but I'm not sure.
FLASH CODE
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 CODE
<?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);
?>