I did this a little while ago in an assignment for University. The easiest way to do this is to have a PHP / MySQL backend which the flash sends the score to. This is by no means secure, and very easy to cheat for somebody with even a small amount of networking knowledge. I also modified this to remove a lot of dependencies, so it might not work without some modification.
Code:
var Website:String = "http://yourwebsite.com/scoreboard/savescore.php";
var Completed:Boolean = false;
function saveScore(score:Number)
{
var url:String = Website + "?username=" + Username + "&score=" + score + "&gameid=2";
var myLoader:URLLoader = new URLLoader();
try
{
myLoader.load(new URLRequest(url));
myLoader.addEventListener(Event.COMPLETE, onLoaded);
}
catch (error:Error)
{
Completed = false;
// Print error message here
}
}
function onLoaded(e:Event):void {
// Score saved.
Completed = true;
}
And here is some PHP (this is probably insecure, I didn't do a lot of input sanitation as it was just for an assignment and security wasn't an issue).
savescore.php
Code:
<?php
include("config.php");
$con = mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
@mysql_select_db($db_name, $con) or die(mysql_error());
$name = mysql_real_escape_string($_GET['username']);
$score = mysql_real_escape_string($_GET['score']);
$gameid = mysql_real_escape_string($_GET['gameid']);
$query = "INSERT INTO highscores (Username, GameID, Score) VALUES('$name', '$gameid', '$score')";
mysql_query($query) or die(mysql_error());
echo("success");
?>
scores.php (to view the high scores)
Code:
<?php
include("config.php");
$gameid = $_GET['gameid'];
$query = "SELECT * FROM highscores WHERE GameID = '$gameid' ORDER by score DESC";
$con = mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
@mysql_select_db($db_name, $con) or die(mysql_error());
$result = mysql_query($query) or die(mysql_error());
echo "<html><body>Click <a href=\"./index.php\">here</a> to go back.</br></br></body></html>";
$index = 1;
while ($row = mysql_fetch_assoc($result)) {
$id = $row['GameID'];
if($id == $gameid)
{
$username = $row['Username'];
$score = $row['Score'];
echo($index . " - " . $username . " with score " . $score . "<br/>");
$index++;
}
}
?>
and config.php
Code:
<?php
$db_host = "localhost";
$db_user = "root";
$db_pass = "yourmysqlpassword";
?>