D. Leaderboards - myflashlab/GameServices-ANE GitHub Wiki
Updating the player's score
When the player's score changes (for example, when the player finishes the game), your game can update their score on the leaderboard by calling submitScore(), and passing in the LEADERBOARD_ID and the raw score value and an optional metadata about the score.
Games.leaderboards.addEventListener(GamesEvents.LEADERBOARDS_SUBMIT_SCORE_RESULT, onLeaderboardSubmitScoreResult);
Games.leaderboards.submitScore("LEADERBOARD_ID", 23, "ScoreTag", true);
function onLeaderboardSubmitScoreResult(e:GamesEvents):void
{
if(e.status == Games.SUCCESS)
{
trace("onLeaderboardSubmitScoreResult(" + e.leaderboardId + ") Success, playerId: " + e.playerId);
trace("scoreToday: " + e.scoreToday.formattedScore + ", is newBest: " + e.scoreToday.newBest);
trace("scoreThisWeek: " + e.scoreThisWeek.formattedScore + ", is newBest: " + e.scoreThisWeek.newBest);
trace("scoreAllTime: " + e.scoreAllTime.formattedScore + ", is newBest: " + e.scoreAllTime.newBest);
}
else if(e.status == Games.FAILURE)
{
trace("onLeaderboardSubmitScoreResult(" + e.leaderboardId + ") Failure: " + e.msg);
}
}
When making calls to update and load player scores, make sure to also follow these best practices to avoid exceeding your API quota.
Displaying a leaderboard
To display a leaderboard you have two options, either load player scores using the methods in Leaderboard API. Or call showNativeWindow and passing in the LEADERBOARD_ID, timespan in which you wish to show the information.
Games.leaderboards.addEventListener(GamesEvents.LEADERBOARDS_WINDOW_FAILURE, onLeaderboardsWindowFailure);
Games.leaderboards.addEventListener(GamesEvents.LEADERBOARDS_WINDOW_DISMISSED, onLeaderboardsWindowDismissed);
Games.leaderboards.showNativeWindow("LEADERBOARD_ID", Leaderboards.TIME_SPAN_ALL_TIME);
function onLeaderboardsWindowFailure(e:GamesEvents):void
{
trace("onLeaderboardsWindowFailure: " + e.leaderboardId + " " + e.msg);
}
function onLeaderboardsWindowDismissed(e:GamesEvents):void
{
trace("onLeaderboardsWindowDismissed");
}
DISCRIMINATION: We have copied and when needed has modified the Google documents so it will fit the needs of Adobe Air community. If you wish to see the original documentations, visit here. But if you are interested to do things in Adobe Air, then you are in the right place.