Creation of a Flash highscores API
More and more game portals are developing their own Flash API to manage high scores.

Having high scores means giving players the opportunity to compete for a leaderboard, making them play your game more and more. And making you earn more and more.
I am showing you how to make one. I'll use LocalConnection, like, as example, MindJolt.
The LocalConnection class lets you develop SWF files that can send instructions to each other, and if all files are located in the same domain, you won't have security issues.
Nice!
So you need two files: the game itself and the leaderboard file. Once the game is over, I will send the score to the leaderboard file, that will generate the leaderboard itself
The game
In this very hard to develop game, you will have to press a button to generate a random number between 0 and 999
Let's see its actionscript:
-
var send_score:LocalConnection = new LocalConnection();
-
onMouseDown = function () {
-
points = Math.floor(Math.random()*1000);
-
_root.score.text = "Your last score: "+points;
-
send_score.send("hall_of_fame", "compare_scores", points);
-
};
Line 1: Creation of the LocalConnection variable called send_score
Lines 2-4: Your game script here... score is saved in a variable called points
Line 5: Sending the score. How?
send calls the compare_scores method (the second parameter) on a connection opened with the LocalConnection.connect command we will insert into our leaderboard file. The name of the connection is the first parameter (hall_of_fame) while the score is passed as 3rd parameter, where I pass the points variable
That's all. This means I only have to add 2 lines to my game: line 1 with for the connection, and line 5 to send the score
The leaderboard
This is a very very complex leaderboard that will save only the highest score. Come on, what's the meaning of being 42,455th...
-
var get_score:LocalConnection = new LocalConnection();
-
best_score = 0;
-
get_score.connect("hall_of_fame");
-
get_score.compare_scores = function(points):Void {
-
if (points>best_score) {
-
_root.score.text = "Highest score: "+points;
-
best_score = points;
-
}
-
};
Line 1: Same thing the first line of the game, but the variable here is named get_score
Line 2: Initializing the score to zero.
Line 3: Connecting to the hall_of_fame connection created at line 5 of the game
Line 4: Creation of the compare_scores method passed as the 2nd parameter at line 5 of the game. Look how I pass the score as points variable
Lines 5-8: Creation of the leaderboard
And try the example: this game...
...sends the scores to this leaderboard...
easy and clean.
In a few days, I'll show you how to save scores in a mySql database with a little php
Meanwhile, download the sources and tell me how would you make your mySql interface
Tell me what do you think about this post. I'll write better and better entries.
They can be easily customized to meet the unique requirements of your project.
16 Responses to “Creation of a Flash highscores API”
Leave a Reply
Trackbacks
-
Creation of a Flash highscores API - Step 2 : Emanuele Feronato - italian geek and PROgrammer on
May 15th, 2008 10:55 pm
[...] that you know how to communicate between two Flash movies thanks to the Creation of a Flash highscores API tutorial, it’s time to introduce the next step that will make you save your highest score on your [...]
-
Flash sending, manipulating and receiving data with sendAndLoad : Emanuele Feronato - italian geek and PROgrammer on
June 1st, 2008 12:35 pm
[...] is a standalone tutorial, but the basics explained will be useful in the Creation of a Flash highscores API [...]

(5 votes, average: 4 out of 5)
Wow. First comment! lol
I, personally, don’t need this. :)
Some of my fav. tutorials are prototypes, things you can make games out of, you know?
I disagree, I really enjoy tutorials based data transfer, I look forward to SQL databases, because once you know how to pass data between flash and SQL, you can start saving games, with usernames and passwords and the like.
Nice tut Emanuele, keep it up!
Thanks for this! I tried to make an API like this but failed…now it looks like I won’t!
thanks, this is great!
Got 999!
Great tutorial and very simple to understand.
I agree with FrozenHaddock. Even tho prototypes are good for getting an idea done, data transfer info gets you to do things as saving, and that’s a step towards a “real game”, a comercial one.
Bigger games means more people playing, more people playing means more revenue to developers.
I might be wrong, but it appears to me that flash games are growing a little bigger. Some NewGrounds games I saw recently seem like an attempt to get the flash to a higher level. That could be very interesting, don’t you think?
Thank you for beginning this tutorial series! I see that this approach has a lot of other applications other than high scores - for instance, this can be used to exchange data between the game and chat, ala Kongregate. See http://board.flashkit.com/board/showthread.php?t=756551 .
Having highscores increases a game´s replay value.
Apart from that, I´m interested too in the publishing side of games. I´m building a game site and this article is very interesting to me.
I´m eager to see the next part, and I´d like to see the continuation of this topic:
http://www.emanueleferonato.com/2008/04/25/play-flash-games-on-triquicom/
Good work!
This is a nice concise tutorial that shows how easy it is to put something like this together.
The main question that I have is about cheaters. Is there a good way to do something to prevent people from reverse engineering the submit that the hi-score SWF file is doing to your server to post high scores?
This seems like a difficult problem to resolve since your SWF files can be decompiled to reveal your encryption method.
Jon, if you use this method to save highscores, then you have to encrypt your swf.
Read this post
http://www.emanueleferonato.com/2008/02/11/protect-your-actionscript-with-amayetas-swf-encrypt/
Could this method be used to make a serverless multiplayer game?
Hi Emanuele,
firstly, i greatly appreciate your blog. Your main intent is very similar to mine :) however, how are you going to solve the cheating in the scoretable entries? I’m not referring to reverse engineering cheaters, i am talking about those cheaters using applications like TSearch (application that change value at the memory address, without decompiling needed). I have been working for nearly six months on solutions to this, i am greatly interested in reading your solution to this problem, if you are going to write about it :)
Looking forward!
Hey im making a game in Flash CS3 and i need a highscore chart. its a game of snake (yes i know boring) but i need to know how i could make it so when you die it saves the highscore on that page. only running 1 programme. Can someone help me out plz.
Hmm, I dont get it, why do you need to send variables to another swf, and then send your scores to DB again ?