- Package: com.newgrounds
- Class: API
Methods
These are the methods of API.addEventListener
public static function addEventListener(eventType:String, listener:Function, priority:int, useWeakReference:Boolean):voidRegisters an event listener object with the API so that the listeners receives notification of an event.
- Parameters
- eventType:String
The type of the event. Should match an event type in APIEvent.
- listener:Function
The listener function that processes the event. The function must accept an event object as its only parameter.
- priority:int
The priority level of the event listener. The higher the number, the higher the priority. All listeners with priorty n are processed before listeners of priority n-1.
- useWeakReference:Boolean
Determines whether the reference to the listener is strong or weak. A strong reference prevents your listener from being garbage-collected.
connect
public static function connect(root:DisplayObject, apiId:String, encryptionKey:String, movieVersion:String):void
- eventType:String
After calling connect, the API will fire an API_CONNECTED event. If version control is enabled for the game and a new version is available, event.data.newVersion will be true.
- Parameters
- root:DisplayObject
The root DisplayObject.
- apiId:String
The API ID for this movie, as shown on the API settings page.
- encryptionKey:String
The encryption key for this movie, as shown on the API settings page.
- movieVersion:String
createSaveFile
public static function createSaveFile(groupName:String):SaveFile
- root:DisplayObject
- Parameters
- groupName:String
The name of the save group to which this file will belong.
- groupName:String
- Returns
- Parameters
- Returns
- Parameters
- groupName:String
The name of the save group to query.
- filename:String
The name to search for.
- exactMatch:Boolean
If true, the query only list files that have the exact name. Otherwise, the query lists files that contain the name.
- sortDescending:Boolean
If false, files will be listed in alphabetical order.
- groupName:String
- Returns
- Parameters
- Returns
- Parameters
- groupName:String
The name of the save group to query.
- groupName:String
- Returns
getMedal
public static function getMedal(medalName:String):MedalReturns the medal with the specified name. Returns null if no medal with that name exists for this game, or the API is disconnected.
- Parameters
- medalName:String
- medalName:String
- Returns
- Parameters
- groupName:String
- groupName:String
- Returns
- SaveGroup
The SaveGroup object with the matching name, or null if the save group is not found.
getScoreBoard
public static function getScoreBoard(scoreBoardName:String):ScoreBoard
- SaveGroup
- Parameters
- scoreBoardName:String
- scoreBoardName:String
- Returns
- ScoreBoard
The ScoreBoard object with the matching name.
loadCustomLink
public static function loadCustomLink(linkName:String):void
- ScoreBoard
- Parameters
- Parameters
- saveId:String
The id of the data to load.
- saveId:String
- Returns
loadNewgrounds
public static function loadNewgrounds():voidLoads newgrounds.com in a new browser window.
loadOfficialVersion
public static function loadOfficialVersion():voidLoads the official version of this game in a new browser window. The URL for the official version can be set on your API Settings pages.
loadSaveFile
public static function loadSaveFile(saveId:uint, loadContents:Boolean):voidLoads a save file with the specified save ID.
- Parameters
- Parameters
- scoreBoardName:String
The name of the score board that will load scores.
- period:String
The timeframe for which to load scores. Defaults to listing the best scores of all-time, ScoreBoard.ALL_TIME.
- firstResult:uint
The rank of the first result to load. Scores start from rank 1.
- numResults:uint
The number of scores to load.
- tag:String
Filter scores based on their tag. If tag is null, all scores will be listed. Otherwise, only scores with the matching tag will be listed.
- scoreBoardName:String
- Returns
- ScoreBoard
The ScoreBoard object with the matching name.
logCustomEvent
public static function logCustomEvent(eventName:String):void
- ScoreBoard
- Parameters
- Parameters
- Parameters
- Parameters
- Returns
unlockMedal
public static function unlockMedal(medalName:String):voidUnlocks a medal. Medal names are case sensitive. The API will fire a MEDAL_UNLOCKED event on success or failure. If a user is logged-in and playing on Newgrounds, the medal will unlock on their account and be visible in their profile. If a user is not on Newgrounds or not logged-in, then the medal unlock will be stored locally on their computer.
- Parameters
apiId
public static var apiId:String;The API ID of the movie. The API ID is set when connect is called.
connected
public static var connected:Boolean;Returns true if the API has connected successfully.
debugMode
public static var debugMode:String;The debug mode of the movie. The debug mode allows you to easily test different use cases during development. If debugMode is set to RELEASE_MODE, then the API operates normally. If debugMode is set to DEBUG_MODE_LOGGED_IN, then the API operates as if a logged-in user was viewing the movie on Newgrounds. If a game is played on the web, debugMode will automatically turn off and revert to RELEASE_MODE. However, it is still a good practice to set debugMode to RELEASE_MODE before making your game publically available.
hasUserSession
public static var hasUserSession:Boolean;Specifies whether the user is logged in.
hostDomain
public static var hostDomain:String;The domain that is hosting the file.
hostURL
public static var hostURL:String;The full URL to this file.
isNetworkHost
public static var isNetworkHost:Boolean;isNetworkHost is true if the movie is hosted on the web, or false if the movie is running locally.
isNewgrounds
public static var isNewgrounds:Boolean;Specifies whether the game is hosted on Newgrounds.
medals
public static var medals:Array;Returns a list of the medals for this game. Returns an empty array if there are no medals, or the API has not connected.
publisherId
public static var publisherId:uint;The publisher ID of the site that is hosting this game. If the game is hosted by an unknown publisher or running locally, publisherId is 0. If the game is hosted by Newgrounds, publisherId is 1.
saveGroups
public static var saveGroups:Array;Returns a list of save groups for this game. Returns an empty array if this game has no save groups, or the API has not connected.
scoreBoards
public static var scoreBoards:Array;Returns a list of scoreboards for this game. Returns an empty array if this game has no scoreboards, or the API has not connected.
sessionId
public static var sessionId:String;The session ID of the user playing the game. If the user is not logged-in, session ID is 0.
userId
public static var userId:uint;The ID of the user.
username
public static var username:String;The username of the user.
Constants
These are the constants of API.DEBUG_MODE_HOST_BLOCKED
public static const DEBUG_MODE_HOST_BLOCKED:String = "debugModeHostBlocked";The DEBUG_MODE_NEW_VERSION debug setting will cause the API to operate as if sitelocking is enabled, and the file is hosted on a blocked domain. The API_CONNECTED event will fail with a HOST_BLOCKED error.
DEBUG_MODE_LOGGED_IN
public static const DEBUG_MODE_LOGGED_IN:String = "debugModeLoggedIn";The DEBUG_MODE_LOGGED_OUT debug setting will cause the API to operate as if the user was on Newgrounds while logged-in.
DEBUG_MODE_LOGGED_OUT
public static const DEBUG_MODE_LOGGED_OUT:String = "debugModeLoggedOut";The DEBUG_MODE_LOGGED_OUT debug setting will cause the API to operate as if the user was on Newgrounds, but not logged-in.
DEBUG_MODE_NEW_VERSION
public static const DEBUG_MODE_NEW_VERSION:String = "debugModeNewVersion";The DEBUG_MODE_NEW_VERSION debug setting will cause the API to operate as if there is a new version of the movie available. The API_CONNECTED will have the newVersion flag set.
RELEASE_MODE
public static const RELEASE_MODE:String = "releaseMode";The RELEASE_MODE debug setting will cause the API to operate normally, without any debug functionality.
VERSION
public static const VERSION:String = "3.0.4.3 beta AS3";Specifies the version of the Newgrounds API. 11