Easy GameJolt Flash Api integration for Games (As3)

Gamejolt is an awesome platform for indie developers to showcase their games. And they provide API for implementation of trophies, highscores and user data storage etc. This is a tutorial for implementing the GameJolt Flash API for a flash games & i hope it may help you in implementing it in your next game. And I’m using Flash Develop as the IDE here (although i guess its pretty much same for Adobe Flash as well. If in doubt do a Google search).

(I’m not going deep into the http requests, Server calls, Api Calls and the inside working of the AS3 API done by them (which i don’t have much knowledge about). If you find any descriptive mistake here, please notify me through comments.

Step 1 : Download the API

Download the api package with MD5 encryption Download From here. (Which worked for me so far).

In FlashDevelop add the extracted com folder to the src folder.

Step 2 : GameJoltConnect Class

To keep the Gamejolt activities outside of the game stuffs, i created a Singleton class(check this one for reference) and added functions and data related to gamejolt to it.

For Example, to authenticate user, i can call GameJoltConnect.instance.authUser(username,token);

Step 3 : Set Private Key & Game ID

In GameJoltConnect class replace the private key and Game Id with your Game Key & ID (Which can be found on the right side of Achievements tab).

Step 4 : User Authentication

In GameJolt , every user has a username and usertoken (click on show to see your token next to the displayed username on top). So (as far as i know) the username and token are passed to the Flash game when it loads. (How to retrive it [Ref:http://metah.ch/blog/2007/07/passing-variable-from-javascript-to-as3-flash-cs3/]). In your preloader (When the loading is complete) or Main.as file, add this line to retrieve the username and token & pass it to authenticate the data.

When it calls the auth() function, if the user exists and token is correct, the callback function will be called with either true or false, ie returning success (i’ve set a userVerified boolean to keep track of whether user exists or not).

Step 5 : Adding Highscores

In gamejolt for every game a primary highscore table is created (i believe). So to post a score i just call

GameJoltConnect.instance.addHighScore(scoreValue);

Step 6 : Adding Trophies (Achievements)

Click on the Achievements menu, Click on trophies tab and click on Add Trophy to add a new trophy for the game. Fill in the details, upload a 75×75 pixel awesome pic for it, choose from bronze, silver, Keep it secret etc. that kind of stuff.

After trophy is created it appears with a Trophy ID associated with it. I created 3 trophies for this demo game as shown below.

I have actually implemented the callback function (after reading the data) inside GameJoltConnect. You can implement a callBack function for unlocking levels after reading the saved data inside that function. Feel free to check inside the functions & use it, modify it according to your needs.

1 Response

got error :-
C:\Users\Desktop\AS3_API\com\gamejolt\crypt\MD5.as, Line 78 Warning: 1112: Array(x) behaves the same as new Array(x). To cast a value to type Array use the expression x as Array instead of Array(x).