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:

NameTypeDescription
typeStringType of content to listen for
callbackFunctionFunction to call when a shared content load request has been made

The callback method will be passed a single object with the following attributes:

NameTypeDescription
idIntegerUnique ID of the created shared content
nameStringName of the shared content
permalinkStringLink to the shared content
contentStringThe content itself
labelStringThe 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: