C. Achievements - myflashlab/GameServices-ANE GitHub Wiki
Unlocking achievements
To unlock an achievement, call the unlock()
method and pass in the achievement ID.
Games.achievements.addEventListener(GamesEvents.ACHIEVEMENT_UPDATE_RESULT, onAchievementsUpdate);
Games.achievements.unlock("ACHIEVEMENT_ID", true); // if false, listener won't be dispatched
function onAchievementsUpdate(e:GamesEvents):void
{
if(e.status == Games.SUCCESS)
{
/**
* IMPORTANT:
*
* e.isAchievementUnlocked is irrelevant when Games.achievements.reveal is called!
* if the achievement is unlocked, calling Games.achievements.reveal would do nothing because
* the achievement is already unlocked and revealed. You should use e.isAchievementUnlocked when
* increment, setSteps or unlock
*/
}
else if(e.status == Games.FAILURE)
{
trace("onAchievementsUpdate for " + e.achievementId + " failure: " + e.msg);
}
}
If the achievement is of the incremental type (that is, several steps are required to unlock it), call increment()
instead.
Games.achievements.addEventListener(GamesEvents.ACHIEVEMENT_UPDATE_RESULT, onAchievementsUpdate);
Games.achievements.increment("ACHIEVEMENT_ID", 1, true); // if false, listener won't be dispatched
You do not need to write additional code to unlock the achievement; Google Play games services automatically unlocks the achievement once it reaches its required number of steps.
Displaying achievements
To show a player's achievements you have two options, either use the load() method and listen for the GamesEvents.ACHIEVEMENT_LOAD_RESULT event. OR call showNativeWindow()
method as follow:
Games.achievements.addEventListener(GamesEvents.ACHIEVEMENTS_WINDOW_FAILURE, onAchievementsWindowFailure);
Games.achievements.addEventListener(GamesEvents.ACHIEVEMENTS_WINDOW_DISMISSED, onAchievementsWindowDismissed);
Games.achievements.showNativeWindow();
function onAchievementsWindowFailure(e:GamesEvents):void
{
trace("onAchievementsWindowFailure: " + e.msg);
}
function onAchievementsWindowDismissed(e:GamesEvents):void
{
trace("onAchievementsWindowDismissed");
}
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.