Packagecom.kongregate
Classpublic class KartridgeBindings
InheritanceKartridgeBindings Inheritance flash.events.EventDispatcher



Public Methods
 MethodDefined By
  
KongregateAPI_Initialize(settingsJson:String):Boolean
[static] Initialize the Kongregate API.
KartridgeBindings
  
[static]
KartridgeBindings
  
[static]
KartridgeBindings
  
[static] Checks to see if the game was launched from Kartridge, and requests Kartridge launch the game if not.
KartridgeBindings
  
KongregateAPI_SetEventCallback(listener:Function):void
[static] Sets the event listener callback to listen for API events.
KartridgeBindings
  
KongregateAPI_SetEventListener(listener:Function):void
[static]
KartridgeBindings
  
[static] Shuts down the Kongregate API after it has been initialized.
KartridgeBindings
  
[static] Updates the internal state of the Kongregate API.
KartridgeBindings
  
KongregateIAP_ConsumeItemInstance(instanceId:Number, callback:Function):Boolean
[static] Attempts to consume the item instance with the given ID and call the callback when the operation is complete.
KartridgeBindings
  
[static] Returns a list of ItemInstance objects representing items owned by the current user.
KartridgeBindings
  
[static] Returns a list of #Item objects representing items defined for the game.
KartridgeBindings
  
KongregateIAP_PurchaseDynamicItem(orderInfo:String, callback:Function):Boolean
[static] Initiates the dynamic purchase flow with the given order info string.
KartridgeBindings
  
KongregateIAP_PurchaseItem(identifier:String, consume:Boolean, callback:Function):Boolean
[static] Initiates the purchase flow for the predefined item with the given identifier.
KartridgeBindings
  
[static] Requests a fresh list of item instances from the server.
KartridgeBindings
  
[static] Checks if the given game ID or additional DLC with additional files is installed on the system.
KartridgeBindings
  
KongregateLibrary_IsGameOwned(gameId:uint):Boolean
[static] Checks if the current user owns the game/DLC with the given game ID.
KartridgeBindings
  
[static]
KartridgeBindings
  
[static]
KartridgeBindings
  
[static]
KartridgeBindings
  
KongregateStats_Submit(statisticName:String, value:Number):void
[static] Submit a statistic with the given name and value
KartridgeBindings
Method Detail
KongregateAPI_Initialize()method
public static function KongregateAPI_Initialize(settingsJson:String):Boolean

Initialize the Kongregate API. You must call this before most other API methods. If this method returns false, it can be because the game was not launched via Kartridge or because Kartridge is not installed, and all further API calls will be stubbed out. This method will use the game ID passed in from Kartridge, or the one present in the kong_gameid.txt file in the working directory the game was launched from if present. The kong_gameid.txt file should only be used for testing, and you should not ship it with your game.

Parameters

settingsJson:String — An optional string representation of a JSON object containing API settings. Can be null or an empty string to use all defaults.

Returns
Boolean — true if the API was successfully initialized, which means your game ID was successfully detected. If this method returns false, it means the game was not launched from Kartridge or the kong_gameid.txt file is not present.

See also

KongregateAPI_IsConnected()method 
public static function KongregateAPI_IsConnected():Boolean

Returns
Boolean — true if the API is connected to the Kongregate application. You can use this method to determine if the Kartridge application is running or not.
KongregateAPI_IsReady()method 
public static function KongregateAPI_IsReady():Boolean

Returns
Boolean — true if the API has been fully initialized and has successfully communicated with the Kartridge application for the first time. Will always return true after KONGREGATE_EVENT_READY has been fired.

See also

KongregateAPI_RestartWithKartridgeIfNeeded()method 
public static function KongregateAPI_RestartWithKartridgeIfNeeded(gameId:int):Boolean

Checks to see if the game was launched from Kartridge, and requests Kartridge launch the game if not. If you have a kong_gameid.txt file present with your game ID in it, this will always return false. The kong_gameid.txt should not be packaged with your release build. If this method returns true, you should exit your game as soon as possible, and not initialize the API, as that means that the Kartridge application will attempt to launch a duplicate copy of your game. This method is optional but suggested if your game depends on Kartridge API functionality. You should call it immediately before KongregateAPI_Initialize.

Parameters

gameId:int — The Kongregate game ID for your game

Returns
Boolean — true if the game will be re-launched via Kartridge, or false if not.

See also

KongregateAPI_SetEventCallback()method 
public static function KongregateAPI_SetEventCallback(listener:Function):void

Sets the event listener callback to listen for API events.

Parameters

listener:Function — A function that accepts two strings (eventName, eventPayload). Can be set to null to remove the listener.

KongregateAPI_SetEventListener()method 
public static function KongregateAPI_SetEventListener(listener:Function):void

Parameters

listener:Function

KongregateAPI_Shutdown()method 
public static function KongregateAPI_Shutdown():void

Shuts down the Kongregate API after it has been initialized. After this method is called, you must call KongregateAPI_Initialize again for the API to function.

KongregateAPI_Update()method 
public static function KongregateAPI_Update():void

Updates the internal state of the Kongregate API. Must be called periodically to maintain a connection to the Kongregate application and process events. Typically you would call this every frame or once every few frames.

KongregateIAP_ConsumeItemInstance()method 
public static function KongregateIAP_ConsumeItemInstance(instanceId:Number, callback:Function):Boolean

Attempts to consume the item instance with the given ID and call the callback when the operation is complete. If the operation is successful the item will be removed from the user's inventory and a KONGREGATE_EVENT_ITEM_INSTANCES event will be generated.

Parameters

instanceId:Number — The ID of the item instance that you wish to use
 
callback:Function — The callback method which will be called when the operation is completed or has failed. The callback will be called with an Object that has success:Boolean, and instance:ItemInstance properties

Returns
Boolean — True if the parameters are valid, or false if not. If false, your callback will NOT be called.

See also

KongregateIAP_GetItemInstances()method 
public static function KongregateIAP_GetItemInstances():Vector.<ItemInstance>

Returns a list of ItemInstance objects representing items owned by the current user. This should be used after KONGREGATE_EVENT_ITEM_INSTANCES is fired. The KONGREGATE_EVENT_ITEM_INSTANCES event will be fired when the user is changed or their inventory changes.

Returns
Vector.<ItemInstance> — The list of items in the current user's inventory

See also

KongregateIAP_GetItems()method 
public static function KongregateIAP_GetItems():Vector.<Item>

Returns a list of #Item objects representing items defined for the game. This should be used after KONGREGATE_EVENT_ITEMS is fired.

Returns
Vector.<Item> — The list of items defined for the game

See also

KongregateIAP_PurchaseDynamicItem()method 
public static function KongregateIAP_PurchaseDynamicItem(orderInfo:String, callback:Function):Boolean

Initiates the dynamic purchase flow with the given order info string. The order_info string will be passed to the back-end server you specify in the API callback URL field. For more information, see the documentation for the dynamic purchase API: https://docs.kongregate.com/docs/api-dynamic-purchasing This will attempt to switch focus to the Kartridge app, which may not work properly if your game is not in the foreground. In general, if the user has to click or otherwise interact with your game in order to trigger this function then the focus switch should work fine.

Parameters

orderInfo:String — The identifier that you set up for the item that you wish to be purchased (case sensitive)
 
callback:Function — If this flag is set and the item is consumable, it will be automatically consumed. This should be used if you are not planning on using/consuming the item instance manually via your game server (or if your game does not have a server). This flag has no effect for non-consumable items

Returns
Boolean — True if the parameters are valid, or false if not. If false, your callback will NOT be called.

See also

KongregateIAP_PurchaseItem()method 
public static function KongregateIAP_PurchaseItem(identifier:String, consume:Boolean, callback:Function):Boolean

Initiates the purchase flow for the predefined item with the given identifier. This will attempt to switch focus to the Kartridge app, which may not work properly if your game is not in the foreground. In general, if the user has to click or otherwise interact with your game in order to trigger this function then the focus switch should work fine.

Parameters

identifier:String — The identifier that you set up for the item that you wish to be purchased (case sensitive)
 
consume:Boolean — If this flag is set and the item is consumable, it will be automatically consumed. This should be used if you are not planning on using/consuming the item instance manually via your game server (or if your game does not have a server). This flag has no effect for non-consumable items
 
callback:Function — The callback method which will be called when the operation is completed or has failed. The callback will be called with an Object that has success:Boolean, and instance:ItemInstance properties

Returns
Boolean — True if the parameters are valid, or false if not. If false, your callback will NOT be called.

See also

KongregateIAP_RequestItemInstances()method 
public static function KongregateIAP_RequestItemInstances():void

Requests a fresh list of item instances from the server. The KONGREGATE_EVENT_ITEM_INSTANCES event will be fired when the list is received. This method does not typically need to be used, but can be useful in hybrid client/server applications.

See also

KongregateLibrary_IsGameInstalled()method 
public static function KongregateLibrary_IsGameInstalled(gameId:uint):Boolean

Checks if the given game ID or additional DLC with additional files is installed on the system. This can return true even if the current user does not own the given game, as it could belong to a different user. This means that typically for DLC with additional files you will want to use this combined with #KongregateLibrary_IsGameOwned for a full ownership/installation check. The KONGREGATE_EVENT_LIBRARY event will be fired when the list of installed games changes. This will always return false for DLC that does not have additioanl files since there is nothing to install in that case.

Parameters

gameId:uint — The game ID to check

Returns
Boolean — true if the given game ID is installed on the system, false if not. Always returns false for DLC that does not have additional files.

See also

KongregateLibrary_IsGameOwned()method 
public static function KongregateLibrary_IsGameOwned(gameId:uint):Boolean

Checks if the current user owns the game/DLC with the given game ID. If the game ID given is not published by the developer of the current game ID, this will return false. The KONGREGATE_EVENT_LIBRARY event will be fired when the list of owned games changes.

Parameters

gameId:uint — The game ID to check

Returns
Boolean — true if the current user owns the given game

See also

KongregateServices_GetGameAuthToken()method 
public static function KongregateServices_GetGameAuthToken():String

Returns
String — the game authorization token for the active user for your game. Use the Kongregate REST API from your server to validate the user. Will return an empty string if the user is a guest or the key has not been fetched yet.

See also

KongregateServices_GetUserId()method 
public static function KongregateServices_GetUserId():uint

Returns
uint — the user ID for the active user. Result is not valid until KONGREGATE_EVENT_USER has been fired. Will return 0 for guest users.

See also

KongregateServices_GetUsername()method 
public static function KongregateServices_GetUsername():String

Returns
String — the username for the active user within Kartridge. Result is not valid until KONGREGATE_EVENT_USER has been fired. Will return an empty string if the user information has not yet been fetched, and "Guest" for guest users.

See also

KongregateStats_Submit()method 
public static function KongregateStats_Submit(statisticName:String, value:Number):void

Submit a statistic with the given name and value

Parameters

statisticName:String — The name (not ID) that you chose for the statistic (must match exactly)
 
value:Number — The value to submit