Receive notifications when shared content is loaded
addLoadListener(type, callback)
Adding load event listeners
You can use the addLoadListener
function on the sharedContent
propery of the Kongregate API object to register an event listener which will be triggered when shared content of the specified type is loaded by the user. It accepts the following arguments:
Name | Type | Description |
---|---|---|
type | String | Type of content to listen for |
callback | Function | Function to call when a shared content load request has been made |
The callback method will be passed a single object with the following attributes:
Name | Type | Description |
---|---|---|
id | Integer | Unique ID of the created shared content |
name | String | Name of the shared content |
permalink | String | Link to the shared content |
content | String | The content itself |
label | String | The label for the shared content |
Note
It is important to register the listener as soon as possible after the API is loaded. This will allow you to capture a load event that was generated by the initial page load via URL parameters.
Example: Loading shared content with Contraption
as the content type
kongregate.sharedContent.addLoadListener("Contraption", onContraptionLoad);
kongregate.services.connect();
function onContraptionLoad(params:Object):void {
var id:Number = params.id;
var name:String = params.name;
var permalink:String = params.permalink;
var content:String = params.content;
var label:String = params.label;
trace("Contraption " + id + " [" + label + "] loaded: " + content);
}
kongregate.sharedContent.addLoadListener("Contraption", onContraptionLoad);
function onContraptionLoad(params) {
var id = params.id;
var name = params.name;
var permalink = params.permalink;
var content = params.content;
var label = params.label;
console.log("Contraption " + id + " [" + label + "] loaded: " + content);
}
Related: