Sign in

Forgot your
password?

Nonoba ActionScript 2 API

Class NonobaAPI

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.

Public Static Methods

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!

Public Constants

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.

Details

SubmitScore method

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.

Parameters
  • key:String - Key identifier which controls which high score list the API submits to. Use the values you have set up on the game management page.
  • score:Number - The score you want to submit.
  • callback:Function - As submitting the score is done asynchronously, a callback method is used to get the result state.
Callback

The callback method must have the following format:

function callback(state:String):Void
Callback parameters
  • state:String - Defines the state of the request using the values of the NonobaAPI's Public Constants
Example
//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;
		}
	}
})
		

AwardAchievement method

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.

Parameters
  • key:String - Key identifier which controls which achievement to award. Use the values you have set up on the game management page.
  • callback:Function - As awarding the achievement is done asynchronously, a callback method is used to get the result state.
Callback

The callback method must have the following format:

function callback(state:String, count:Number):Void
Callback parameters
  • state:String - Defines the state of the request using the values of the NonobaAPI's Public Constants
  • count:Number - Defines how many times the user has received this achievement. If this value is 1, it means that this was the first time the user received it, and you might want to do something special for the user. If the value is above 1, it means that the user has recieved the achievement before. If the value is 0, it means that something went wrong, and in ths case the state will not be SUCCESS.
Example
//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;
		}
	}
})			
		

SetUserData method

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.

Parameters
  • key:String - The key the data should be stored with. You must use the exact same key for getting the data again.
  • value:String - The value you want to store. The maximum size is 1000 characters.
  • callback:Function - Storing data is done asynchronously, so a callback method is used to get the result state.
Callback

The callback method must have the following format:

function callback(state:String):Void
Callback parameters
  • state:String - Defines the state of the request using the values of the NonobaAPI's Public Constants
Example
//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;
		}
	}
})	
		

GetUserData method

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.

Parameters
  • key:String - The key the data was stored with.
  • callback:Function - Loading data is done asynchronously, so a callback method is used to get the result state and stored data.
Callback

The callback method must have the following format:

function callback(state:String, data:String):Void
Callback parameters
  • state:String - Defines the state of the request using the values of the NonobaAPI's Public Constants
  • data:String - The data stored with the specified key identifier.
Example
//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;
		}
	}
})	
		

GetUsername method

public static function GetUsername(callback:Function):Void

Returns the users Nonoba username.

Parameters
  • callback:Function - Authenticating is done asynchronously, so a callback method is used to get the result state and username.
Callback

The callback method must have the following format:

function callback(state:String, username:String):Void
Callback parameters
  • state:String - Defines the state of the request using the values of the NonobaAPI's Public Constants
  • username:String - The Nonoba username.
Example
//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;
		}
	}
})	
		

Login method

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.

Parameters
  • callback:Function - Authenticating is done asynchronously, so a callback method is used to get the result state.
Callback

The callback method must have the following format:

function callback(state:String):void
Callback parameters
  • state:String - Defines the state of the request using the values of the NonobaAPI's Public Constants.
    SUCESS is returned if the user signed in successfully.
    NOT_LOGGED_IN is returned if the user cancels the process.
Example
//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;
			}
		}
	})
		

ShowShop method

public static function ShowShop(item:String, callback:Function):void

Opens the purchase process for the item defined in the request.

Parameters
  • item:String - The item's string identifier, you configure this in the shop admin, under edit game.
  • callback:Function - Authenticating is done asynchronously, so a callback method is used to get the result state.
Callback

The callback method must have the following format:

function callback(state:String, username:String):void
Callback parameters
  • state:String - Defines the state of the request using the values of the NonobaAPI's Public Constants
    Even though the user has the option to login or register in this process, NOT_LOGGED_IN can never be returned
  • success:Boolean - If true, the user bought the item.
Example
//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;
		}
	}				
})
		

GetShopItemKeys method

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.

Parameters
  • key:String - Shop key of the item you are testing for
  • callback:Function - Authenticating is done asynchronously, so a callback method is used to get the result state.
Callback

The callback method must have the following format:

function callback(state:String, keys:Object):void
Callback parameters
  • state:String - Defines the state of the request using the values of the NonobaAPI's Public Constants
    Even though the user has the option to login or register in this process, NOT_LOGGED_IN can never be returned
  • keys:Object - Object using the purchased items id's as keys.
Example
//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;
		}
	}
})
		

HasShopItem method

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.

Parameters
  • callback:Function - Authenticating is done asynchronously, so a callback method is used to get the result state.
Callback

The callback method must have the following format:

function callback(state:String, keys:Object):void
Callback parameters
  • state:String - Defines the state of the request using the values of the NonobaAPI's Public Constants
    Even though the user has the option to login or register in this process, NOT_LOGGED_IN can never be returned
  • hasItem:Boolean - Does the user have the requested item?
  • keys:Array - String array of unique ids for each instance the user has purchased this item (Yes, users can purchase an item multiple times)
Example
//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;
		}
	}
})
		

Init method

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
  • container:MovieClip - The container the API should be loaded into
 
NONOBA-WEB2