• Flash AS3 Leaderboard
    5 replies, posted
  • Avatar of WhiTAkeR
  • Hey I'm wondering if anyone knows a good tutorial or knows how to make a leader board for a game and would care to explain how to do it? I would like it to upload to a web server so there is a multi player aspect in the game. I have found some tutorials where the game is in the same location as the leader board php script but as i ultimately want to compile it as an iPhone app and see if it works this isn't an option. Thanks to anyone who has some information.
  • Avatar of Naelstrom
  • When sending data to the php script, i beleive you can put the direct url. instead of MySendVars.send("myphp.php","_self"); use MySendVars.send("http://myserver.com/myphp.php","_self"); I'm unsure however. Another way is to have your game .swf on a server with the php script. And compile a swf for the phone that downloads and loads the .swf from the server.
  • 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; } [/code] 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"); ?> [/code] 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++; } } ?> [/code] and config.php [code] <?php $db_host = "localhost"; $db_user = "root"; $db_pass = "yourmysqlpassword"; ?> [/code]
  • Avatar of Agent766
  • If this is going to be an iPhone app, doesn't Game Center provide a leaderboard?
  • Avatar of WhiTAkeR
  • I cant find a way to implement that or openfeint etc when making it through flash. its fine on a mac and in c# but cant find a way to do it this way.