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:
newgroundsAPIManager.addAd(20, 20);
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:
newgroundsAPIManager.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:
newgroundsAPIManager.logCustomEvent("myCustomEvent");
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:
newgroundsAPIManager.loadCustomLink("www.monoflauta.com");
If you configured your personal site you can use:
newgroundsAPIManager.loadMySite();
Or load an official URL if you configured one:
newgroundsAPIManager.loadOfficialURL();
Or just load Newgrounds:
newgroundsAPIManager.loadNewgrounds();
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:
newgroundsAPIManager.hideScores();
It will remove the last highscore table you showed.
Then, if you want to post a score, you can call the following function:
newgroundsAPIManager.postScore("scoreBoardName", 71);
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:
newgroundsAPIManager.unlockMedal("nameOfTheMedal");
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.
Public Functions
- addAd(posX:int = 0, posY:int = 0):void
- removeAd():void
- logCustomEvent(event:String):void
- loadCustomLink(link:String):void
- loadMySite():void
- loadOfficialURL():void
- loadNewgrounds():void
- showScores(scoreBoardName:String, period:String = “All-Time”, posX:int = 0, posY:int = 0):void
- hideScores():void
- postScore(scoreBoardName:String, score:Number):void
- unlockMedal(medalName:String):void
- isMedalUnlocked(medalName:String):Boolean
Private Vars
- _id:String;
- _encrypt:String;
- _root:DisplayObject;
- _flashAd:FlashAd;
- _scoreBrowser:ScoreBrowser;