The NewgroundsAPIManager.as script will help you as a facade of the Newgrounds API. The goal of this facade is to make things easier when using the api. Though most of them are already simple, it will simplify a few more. Note: You will need a public static instance of mono in the Main.as
How to start the NewgroundsAPIManager.as
In order to start the manager you will need first to have a public static instance of mono in the Main.as.
Once you already have it, just create an instance of the NewgroundsAPIManager.as doing something like this:
newgroundsAPIManager = new NewgroundsAPIManager("theIdGoesHere", "theAPIEncryptGoesHere", Main.mono.mainStage);
The first parameter is the id of the project, the second is the api encrypt code and the third is a display object. The last one you can get it from Mono.as
Once you have this, you can use all the functions from it.
How to use ads
In order to add the newgrounds ad you will just need to do the following:
Simple call the addAd function and send by parameter the position where you want the add. Default is 0, 0.
Then, if you want to remove it, just call removeAd:
It will auto remove the ad you created before.
How to log a custom event
If you configured custom events and you want to log them, you will need to call the following function with the name of the event:
How to load a custom links
If you want to load a custom link through the api you can call the following function with the url:
If you configured your personal site you can use:
Or load an official URL if you configured one:
Or just load Newgrounds:
How to use highscores
If you want to show the highscore table, once you have it configured, you will just need to call the following function:
newgroundsAPIManager.showScores("ScoreBoardName", "All-Time", 20, 20);
First you will need the name of the score board. In the second parameter goes the default time period you want to show. The possible options are All-Time, This Month, This Week, This Year and Today. And finally, the last to options are the positions where you want to show it.
Then, if you want to remove it, just call:
It will remove the last highscore table you showed.
Then, if you want to post a score, you can call the following function:
The first parameter will be the name of the score board while the second parameter is the score you want to post to it.
How to use the medals
If you configured medals for your game. You can unlock them by doing the following:
By doing this you will be unlocking the medal (It will auto check you haven’t already locked the medal). Just send by parameter the name of the medal.
Also, if you need to know, you can check if a medal is already unlocked by doing the following:
var unlocked:Boolean = newgroundsAPIManager.isMedalUnlocked("nameOfTheMedal"); if(unlocked) trace("Is unlocked!");
In this case we are tracing “Is unlocked” if the medal is unlocked.
- addAd(posX:int = 0, posY:int = 0):void
- showScores(scoreBoardName:String, period:String = “All-Time”, posX:int = 0, posY:int = 0):void
- postScore(scoreBoardName:String, score:Number):void