Game Development Reference
In-Depth Information
static public const STATUS_MESSAGE_ERROR:String = " An error
occurred when retrieving scores.\nPlease try again later. " ;
static private var _netConnection:NetConnection;
The static constants for the leaderboard are the URL of the AMF
gatewaytowhichthegamewillconnect,thegamename(ID),a
secret key value that will be used for security purposes, the number
of results to pull from the database, and the text to display in the
event of an error (like the lack of an Internet connection). A refer-
ence to a NetConnection object is also created, as this will be how
the AMF communication is handled.
static public function createConnection():void
{
if (!_netConnection)
{
_netConnection = new NetConnection();
_netConnection.connect(GATEWAY_URL);
}
}
static public function saveScore(score:int, initials:String)
{
createConnection();
var responder:Responder = new Responder(onScoreSaved,
onScoreSaveError);
var date:Date = new Date();
var hash:String = MD5.hash(MD5.hash(SECRET_KEY + score +
initials + date.toString()));
_netConnection.call( " games.HighScores.saveScore " ,
responder, GAME_ID, score, initials, date.toString(), hash);
}
static private function onScoreSaved(result:Object):void
{
trace(
"
Score Saved:
"
,result);
}
static private function onScoreSaveError(result:Object):void
{
//ERROR OCCURRED
}
Any time a call to the AMF service is made; createConnection is
called to make sure the NetConnection has been established. When
a score is saved to the database, which can be done from any other
Search Nedrilad ::




Custom Search