Handling local high-scoring
Hi folks, Vlad here.
We just tackled a code problem that is as complicated in nature as simple in resolution.
Problem
To have a high-scoring table that works not only on websites, but also localy, in our case, while ran from a DVD. The second issue is that we need a custom high score table, not the standard one size fits all ’showboard()’ solution that most APIs offer.
Original approach
Our first thought was to communicate directly with a web service using AMFPHP. This works indeed, but the user must allow the local Flash Player to access outside content. We didn’t like this… on one hand, security warnings and the software asking to confirm security stuff scares the common user, on the other hand many of the players of these games are kids, so this would be a pain!
Further investigation
But we know that there are a lot of APIs that allow a lot of off-site communication, even localy! There are security protocols that Flash Player enforces, so how are they dealt with? If someone else has done it, it is possible…
The answer is: the APIs communicate with a swf that lies in the same server where data communication is handled. The APIs connection methods are in most part the download of that specific swf and it is the swf that holds all the ‘inteligence’, does making the whole process more troublesome, but more secure…
Solution
We investigated this because of a thread I created at FGL’s forums. I explained what we needed and the answer was: try Mochi’s APIs. Which we did, easily. Mochi’s API does exactly that: it connects to the webserver where it downloads a swf that holds all the methods to communicate with their databases, so there’s no security issue here. As long as there is a internet connection, it will work.
Code
And here is the code to handle the custom table. I’m not including the standard stuff, like connecting or sending scores, that’s pretty straight forward. The only weird and somewhat confusing and somewhat oddly documented feature is the request for high scoring data from Mochi’s servers.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | private function getScores(e:MouseEvent) { MochiScores.requestList(this, "onScoresReceived"); } public function onScoresReceived (args:Object) { if (args.scores != null) { nameTable.text = ""; // Textfield for names scoreTable.text = ""; // Textfield for scores var newScores:Object = MochiScores.scoresArrayToObjects(args.scores); for (var index = 0; index < 10; index++) { nameTable.text += newScores.alltime[index].name + "\n"; scoreTable.text += newScores.alltime[index].score + "\n"; } } else { if (args.error) { trace("Error: " + args.errorCode); } } } |
Hope this helps! See you all soon!
Posted: January 16th, 2010
at 11:16am by Vlad
Tagged with FlashGameBlogs, Testing
Categories: The code of VGS
Comments: 3 comments
