ActionScript Achievements

Introduction

After making an Event that awards your player an Achievement using Cloud Code in the Portal, you can incorporate them into your game. This tutorial shows you how to award the player an Achievement and how to check the Achievements a Player has earned in-game.

Setting up the Account Details Request and Earning an Achievement

Testing the Achievement


Example ActionScript Achievements code can be downloaded here

Setting up the Account Details Request and Earning an Achievement

Before you award the authenticated Player an Achievement, you'll have to give them the ability to check the Achievements that they've earned. To do that, you must request account details using the createAccountDetailsRequest using the requestBuilder.

        private function requestDetails():void
                {
                    requestBuilder.createAccountDetailsRequest().send(PlayerDetails);
                }

The response received by the createAccountDetailsRequest can be broken down to access a large amount of useful data.

For our example, we'll retrieve Display name, currency, location, and Achievements. The Achievements can be retrieved as a vector type and can be looped and listed conveniently. In our function, we're setting our text labels text to the data we're retrieving and looping through the Achievements earned to display them in a list.

        private function PlayerDetails(response:AccountDetailsResponse):void
                {

                    var vec:Vector.;
                    PlayerInfo.visible = true;
                    AInv.removeAllElements();
                    vec = response.getAchievements();
                    DNameTxt.text = response.getDisplayName() ;
                    C1Txt.text = response.getCurrency1("CURRENCY_1").toString();
                    LocTxt.text = response.getLocation().getCountry();
                    ATxt.text = response.getAchievements().length.toString();
                    for (var i:int = 0;  i < vec.length; i++)
                    {
                        if (vec[i] != null)
                        {
                            addAchievements(vec[i]);
                        }
                    }

                }

Finally, to finish the Achievement set up, all you have to do is call the Event that awards the Player the 'Cloud Achievement' that has been created in the Portal.

In this tutorial, we're going to call the Event when the authenticated Player receives a highscore message:

        private function HighScoreMessageListener(message:NewHighScoreMessage):void
                {
                    Alert.show("You achieved the highscore in the leaderboard: " + message.getLeaderboardName(), "High Score Alert")
                    requestBuilder.createLogEventRequest().setEventKey("Award_Achievement").send(GeneralLogResponse);
                }

Testing the Achievement

1. Log in a player and request the details to see that everything is in order. You should receive the Player's Display name, currency, location, and zero Achievements:

2. Play the game and beat the highscore. Once you've received a message informing you that you've beaten the highscore, you should automatically receive the Achievement.

3. Request the account details again and check to see if the account has earned the Achievement:

Did this page help you? Please enter your feedback below. For questions about using this part of the platform, please contact support here