Instructions
Create a new scoreboard on the website's API by filling out the form in the accounts tab.
Access the code for the scoreboard from the account.
In the following code, change "board_name" to the name of the scoreboard you created.
import com.newgrounds.API;
import com.newgrounds.ScoreBoard;
var board:ScoreBoard = API.getScoreBoard(board_name:String);
Input this code into the scoreboard script:
import com.newgrounds.API;
import com.newgrounds.APIEvent;
import com.newgrounds.ScoreBoard;
import com.newgrounds.Score;
// this function will run when the server returns our list of scores
function onScoresLoaded(event:APIEvent):void {
if (event.success) {
var board = event.data.board;
for(var i:uint=0; i<board.scores.length; i++) {
var score:Score = board.scores[i];
trace(score.position+": "+score.username+" -- "+score.value);
}
}
// Tell the api to listen for the SCORES_LOADED event
API.addEventListener(APIEvent.SCORES_LOADED, onScoresLoaded);
// get our board and tell it what time period to load up, and how many results
var high_scores:ScoreBoard = API.getScoreBoard("High Scores");
high_scores.period = "Today";
high_scores.num_results = 20;
// load the scores from the server
high_scores.loadScores();
Input the following code to load the high scores in a game:
import com.newgrounds.API;
API.loadScores(board_name:String, period:String, tag:String);
Replaced the "board_name" with the name of your scoreboard and the "period" to the time period.