High Score Engine V2.0 For Flash ================================ Introduction ------------ This set of scripts allows you to add high-score functionality to your Flash games, as well as display those high scores in a webpage, styled to your own liking. Feel free to use this, but mention that you got it from flashgamecoders.com. Requirements ------------ PHP v.4.02 mySQL 3.23.58 or higher Features -------- * Easy setup and initialization * Two lines of PHP code to include a high score list in a webpage * Use CSS to make the included score list look any way. * Ability to return scores as Flash formatted Name / Value pairs * Several parameters affect appearance of returned score list: - gameID: The game that you want the scores for. - action: Either "getTop" or "getBottom" - returns highest or lowest - limit: Max number of scores to return - top 10, top 20, etc. - viewmode: "admin", "site", or "flash". - dupes: "true" or "false". Determines if list will contain multiple scores for one user, or just their best (or worst, depending on "action"). * Supports an unlimited number of different games, as long as you keep track of which gameID is used for which game. Author ------------------- Glen Rhodes - www.glenrhodes.com Available at www.flashgamecoders.com Setup ------------------ Step 1: The first thing you will have to do is set up the variables in hsconfig.php. Open the file in an editor, and look for these lines of code: $hostname_HSDB = ""; $database_HSDB = ""; $username_HSDB = ""; $password_HSDB = ""; Fill these in with your mySQL information, for example: $hostname_HSDB = "localhost"; $database_HSDB = "gamedatabase"; $username_HSDB = "johnny"; $password_HSDB = "l33tp4zzw0rd"; If you don't know your settings, you must find out from your web host. Step 2: Copy all included files into a folder called 'hiscore' on your server: CORE ENGINE - hiscore.php - setup.php - hsconfig.php SUPPORT FILES - hiscoreInterface.php Use this to manually add scores, as well as generate your query strings to embed in Flash and in browser. - embeddingexample.php This file shows an example of how a score table would be embedded in your main site php. Includes some CSS code. The main embed code looks like so:

The Bottom 10 Scores for Golf!

NOTE: This points to a DUMMY server. You should use the query string generator in hiscoreInterface.php to generate the actual string to embed in $filename. To adjust the look and feel of the outputted table use Cascading Stylesheets to modify the styles associated with tables. See embeddingexample.php for an example. - browser.php This is a simple file that allows you to browse through all of the scores in the database. - hiscoretest.swf, hiscoretest.html These files are to demonstrate the high score engine being used in Flash. If you run hiscoretest.html, then you'll be presented with a Flash movie that allows you to add scores, and view some scores. This is just a testing application, meant to be learned from. See below for more Flash information. Step 3 Run the file setup.php from your browser. If your site was called www.dummy.com, and your high score files were in a folder called hiscore, then you'd run: http://www.dummy.com/hiscore/setup.php This file will create your database table. Integrating with Flash ---------------------- * RETREIVE SCORES To retreive a score list in Flash, you simply need to call the script, with the viewmode set to "flash" (along with the other required variables). The returned values will be in a name/value pair set of strings that look like this as raw data: &n0=Leo&s0=61&n1=Roger&s1=125&n2=Glen&s2=612&n3=Pola&s3=733&n4=Roger&s4=1335& n5=Shar&s5=1522&n6=Sam&s6=1847&n7=Steve&s7=2373&n8=Pico&s8=2633&n9=Sam&s9=2882 &n10=Mary&s10=6612 You don't need to worry about this, because Flash will parse these results, and the Flash variables are simply n0, n1, n2, n3, n4 etc., for the names, and s0, s1, s2, s3, s4 etc., for the corresponding score. The Actionscript code to do this is like so: serverURL = "http://www.dummysite.com/hiscore/"; gameID = "SUPERGAME"; lv = new LoadVars(); lv.onLoad = function(state) { var i = 0; while (this["s" + i] != undefined) { trace ("Rank " + (i + 1) + " NAME: " + this["n" + i] + " SCORE: " + this["s" + i]); i++; } } lv.gameID = gameID; lv.limit = 10; lv.action = "getTop"; lv.viewmode = "flash"; lv.dupes = "false"; lv.sendAndLoad(serverURL + "hiscore.php", lv, "POST"); serverURL is the location of your scripts. The above code would load the top 10 scores of game associated with id SUPERGAME. Upon return, the scores would be traced to the screen as: Rank 1 NAME: John Doe SCORE: 94391 Rank 2 NAME: Peter SCORE: 71815 Rank 3 NAME: Hicks SCORE: 65361 Rank 4 NAME: Walter SCORE: 59993 See hiscoretest.fla (included in the zipfile) for more examples. It will be up to you to do something more interesting with the scores than just simply tracing them to the trace window. In the included example hiscoretest.fla, there are datagrids on the screen which are populated from the results of the call. * SUBMIT SCORES To submit a score in Flash, you simply pass in score, userid, gameid and action of "addNew". The following Actionscript does the job: serverURL = "http://www.dummysite.com/hiscore/"; gameID = "MYFLASHGAME"; submit_btn.onRelease = function() { lv = new LoadVars(); lv.onLoad = function(state) { if (this.result == "success") { result_txt.text = "Successfully Added Score"; } else if (this.result = "fail") { result_txt.text = this.reason; } } lv.gameID = gameID; lv.userID = username.text; lv.score = randomscore.text; lv.action = "addNew"; lv.sendAndLoad(serverURL + "hiscore.php", lv, "POST"); result_txt.text = "Submitting..."; } The script will return a variable called "result", which will either be "success" or "fail". If the result has failed, then there will be another variable called "reason" which will contain text explaining the reason for the failure.