Package: Nonoba.api
Language version ActionScript 2.0
The NonobaAPI class allows you as a game developer to submit scores, award achievements and store userdata on our servers. All methods are static and you cannot create an instance of the NonobaAPI class.
SubmitScore(key:String, score:Number, callback:Function):Void
Submits a score to the Nonoba score system.
AwardAchievement(key:String, callback:Function):Void
Awards an achievement to the user.
SetUserData(key:String, value:String, callback:Function):Void
Store a string value on the server
GetUserData(key:String, callback:Function):Void
Loads a string value from the server.
GetUsername(callback:Function):Void
Gets the users Nonoba username.
(New) Login(callback:Function):void
Shows a login dialogue to the user.
(New) ShowShop(item:String, callback:Function):void
Shows the purchase process for item.
(New) GetShopItemKeys(callback:Function):void
Retrieves a list of items the user have purchased for this game.
(New) HasShopItem(key:String, callback:Function):void
Checks if a user has purchased a specific item. Also returns a list of ids, if the user should have purchased the same item more than once.
Init(container:MovieClip):Void
Forces the NonobaAPI class to initialize using another container than the _root node. This method can only be called once, and must be executed before any other API request. If it is called twice, or after any other API request, it will throw an error.
Before using this method please make sure that it is actually necessary for you!
SUCCESS:String="success"
Result message for when a request was successful.
NOT_LOGGED_IN:String="user not logged in"
Result message for when a request failed due to the user not being logged in to Nonoba.
ERROR:String="error"
Result message for when an error occurred when loading or requesting the API.
public static function SubmitScore(key:String, score:Number, callback:Function):Void
Submits a score to the Nonoba score system.
Before you can submit scores to your game, you must have set up one or more high score lists on the game management page.
Note that there are two types of score lists, high-score and ranking lists. When submitting to a high-score list, a unique entry will be created for each submission. When submitting to a ranking list, the score will be added to the user's current score and thereby possibly change the rank. If you submit a negative value, you will lower the user's current score.
The callback method must have the following format:
//Submits 100 to the score list with the key identifier "kills"
NonobaAPI.SubmitScore("kills", 100, function(response:String){
switch(response){
case NonobaAPI.SUCCESS:{
trace("The score was submitted successfully")
break;
}
case NonobaAPI.NOT_LOGGED_IN:{
trace("The user is not logged in")
break;
}
case NonobaAPI.ERROR:{
trace("An error occurred.")
break;
}
}
})
public static function AwardAchievement(key:String, callback:Function):Void
Award an achievement to the user.
Before you can award an achievement in your game, you must have set up one or more achievements on the game management page.
The callback method must have the following format:
//Awards the achievement with the key "monsterkill"
NonobaAPI.AwardAchievement("monsterkill", function(response:String, count:Number){
switch(response){
case NonobaAPI.SUCCESS:{
trace("The achievement was successfully awarded.")
trace("It has been awarded " + count + " times.")
break;
}
case NonobaAPI.NOT_LOGGED_IN:{
trace("The user is not logged in.")
break;
}
case NonobaAPI.ERROR:{
trace("An error occurred.")
break;
}
}
})
public static function SetUserData(key:String, value:String, callback:Function):Void
Store a string value on the server.
For each user and game you can store several different key/value pairs on the server.
If you call this method with a key that already exists, the existing value will be overwritten.
The callback method must have the following format:
//Saves the string "Some data we want to store" using the key "somedata"
NonobaAPI.SetUserData("somedata", "Some data we want to store", function(response:String){
switch(response){
case NonobaAPI.SUCCESS:{
trace("Data successfully stored on the server.")
break;
}
case NonobaAPI.NOT_LOGGED_IN:{
trace("The user is not logged in.")
break;
}
case NonobaAPI.ERROR:{
trace("An error occurred.")
break;
}
}
})
public static function GetUserData(key:String, callback:Function):Void
Loads a string value from the server.
This method gets the value that was previously stored with the given key parameter.
If you use a key that has not been stored, the callback method will receive ERROR as the state.
The callback method must have the following format:
//Loads data from the server using the key "somedata"
NonobaAPI.GetUserData("somedata", function(response:String, data:String){
switch(response){
case NonobaAPI.SUCCESS:{
trace("Data sucessfully loaded from the server")
trace("Value: " + data)
break;
}
case NonobaAPI.NOT_LOGGED_IN:{
trace("The user is not logged in")
break;
}
case NonobaAPI.ERROR:{
trace("An error occurred.")
break;
}
}
})
public static function GetUsername(callback:Function):Void
Returns the users Nonoba username.
The callback method must have the following format:
//Gets the Nonoba username.
NonobaAPI.GetUsername(function(response:String, username:String){
switch(response){
case NonobaAPI.SUCCESS:{
trace("username: " + username)
break;
}
case NonobaAPI.NOT_LOGGED_IN:{
trace("The user is not logged in")
break;
}
case NonobaAPI.ERROR:{
trace("An error occurred.")
break;
}
}
})
public static function Login(callback:Function):void
Shows the shop login window to the user
This method is usefull for users returning to the game on a 3rd party site, beaing able to auth to the system without going to the nonoba.com portal.
The callback method must have the following format:
//Shows the shop login dialog.
NonobaAPI.Login(function(response:String){
switch(response){
case NonobaAPI.SUCCESS:{
trace("Logged in!")
break;
}
case NonobaAPI.NOT_LOGGED_IN:{
trace("The user is not logged in")
break;
}
case NonobaAPI.ERROR:{
trace("An error occurred.")
break;
}
}
})
public static function ShowShop(item:String, callback:Function):void
Opens the purchase process for the item defined in the request.
The callback method must have the following format:
//Shows the shop for the item noba
NonobaAPI.ShowShop("noba", function(response:String, success:Boolean){
switch(response){
case NonobaAPI.SUCCESS:{
trace("Shop was shown, did we buy the item?", success)
break;
}
case NonobaAPI.ERROR:{
trace("An error occurred.")
break;
}
}
})
public static function GetShopItemKeys(key:String, callback:Function):void
Retrieves a list of items the user have purchased for this game.
The list is represented as an object using the purchased items id's as keys.
The callback method must have the following format:
//retrieve list of keys
NonobaAPI.GetShopItemKeys(function(response:String, keys:Object){
switch(response){
case NonobaAPI.SUCCESS:{
for( var key:String in keys){
trace("The user has at least one instance of " + key)
}
//Check if the user has a noba.
if(keys["noba"] == true){
trace("The user has a noba")
}else{
trace("The user does not have a noba")
}
break;
}
case NonobaAPI.NOT_LOGGED_IN:{
trace("The user is not logged in")
break;
}
case NonobaAPI.ERROR:{
trace("An error occurred.")
break;
}
}
})
public static function HasShopItem(callback:Function):void
Checks if a user has purchased a specific item.
Returns a list of ids, if the user should have purchased the same item more than once.
The callback method must have the following format:
//Does user have a noba?
NonobaAPI.HasShopItem("noba",function(response:String,hasItem:Boolean, ids:Array){
switch(response){
case NonobaAPI.SUCCESS:{
if(hasItem){
trace("the user have " + ids.length + " noba(s)")
trace("The item ids for the noba(s) are ", ids)
}else{
trace("The user does not have a noba!")
}
break;
}
case NonobaAPI.NOT_LOGGED_IN:{
trace("The user is not logged in")
break;
}
case NonobaAPI.ERROR:{
trace("An error occurred.")
break;
}
}
})
public static function Init(container:MovieClip):Void
Before you consider using this method, please make sure you really have to!
To make sure the API will work with future versions, much of the Nonoba API is downloaded from our servers encased in a SWF file.
In ActionScript 2.0, this code must be attached to some element, and the default value for this is _root. If this causes a problem for you in your game, you can use this method to define another element that the API should be attached to.
If you wish to use this method, you must execute it before any other API calls, or it will throw an error.
Parameters