{"__v":3,"_id":"570fb2dbd6c6f00e00b98854","category":{"project":"56abbf55f25f160d00e17f4e","version":"56abbf55f25f160d00e17f51","_id":"570a5676ade45d0e00c1ad33","__v":0,"sync":{"url":"","isSync":false},"reference":true,"createdAt":"2016-04-10T13:34:46.864Z","from_sync":false,"order":3,"slug":"client-side-api","title":"Client Side API"},"parentDoc":null,"project":"56abbf55f25f160d00e17f4e","user":"56abbec30b9e0b0d00616274","version":{"__v":12,"_id":"56abbf55f25f160d00e17f51","project":"56abbf55f25f160d00e17f4e","createdAt":"2016-01-29T19:36:53.665Z","releaseDate":"2016-01-29T19:36:53.665Z","categories":["56abbf56f25f160d00e17f52","56abca6bf9757e0d007c6650","56acddfa0ab3c00d00ce3332","56af65da9d32e30d0006d30f","56af66cab34d210d003d9ad0","56af6afcd21e9c0d00b628d1","56af6d6ecc4cbd0d00ce2c88","5705b12221cfed0e00e8c580","570a5676ade45d0e00c1ad33","570d7d25d1e4b82000d9e385","570eac3c3160d10e0041df0e","575709000fd6a3200010dded"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-04-14T15:10:19.594Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":true,"order":26,"body":"## Adding load event listeners\n\nYou 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](doc:shared-content) of the specified type is loaded by the user. It accepts the following arguments:\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Name\",\n    \"h-1\": \"Type\",\n    \"h-2\": \"Description\",\n    \"0-0\": \"`type`\",\n    \"0-1\": \"String\",\n    \"0-2\": \"Type of content to listen for\",\n    \"1-0\": \"`callback`\",\n    \"1-1\": \"Function\",\n    \"1-2\": \"Function to call when a shared content load request has been made\"\n  },\n  \"cols\": 3,\n  \"rows\": 2\n}\n[/block]\nThe callback method will be passed a single object with the following attributes:\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Name\",\n    \"h-1\": \"Type\",\n    \"h-2\": \"Description\",\n    \"0-0\": \"`id`\",\n    \"0-1\": \"Integer\",\n    \"0-2\": \"Unique ID of the created shared content\",\n    \"1-0\": \"`name`\",\n    \"1-1\": \"String\",\n    \"1-2\": \"Name of the shared content\",\n    \"2-0\": \"`permalink`\",\n    \"2-1\": \"String\",\n    \"2-2\": \"Link to the shared content\",\n    \"3-0\": \"`content`\",\n    \"3-1\": \"String\",\n    \"3-2\": \"The content itself\",\n    \"4-0\": \"`label`\",\n    \"4-1\": \"String\",\n    \"4-2\": \"The label for the shared content\"\n  },\n  \"cols\": 3,\n  \"rows\": 5\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Note\",\n  \"body\": \"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.\"\n}\n[/block]\n**Example:** Loading shared content with `Contraption` as the content type\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"kongregate.sharedContent.addLoadListener(\\\"Contraption\\\", onContraptionLoad);\\nkongregate.services.connect();\\n\\nfunction onContraptionLoad(params:Object):void {\\n  var id:Number        = params.id;\\n  var name:String      = params.name;\\n  var permalink:String = params.permalink;\\n  var content:String   = params.content;\\n  var label:String     = params.label;\\n\\n  trace(\\\"Contraption \\\" + id + \\\" [\\\" + label + \\\"] loaded: \\\" + content);\\n}\",\n      \"language\": \"javascript\",\n      \"name\": \"ActionScript 3\"\n    },\n    {\n      \"code\": \"kongregate.sharedContent.addLoadListener(\\\"Contraption\\\", onContraptionLoad);\\n\\nfunction onContraptionLoad(params) {\\n  var id = params.id;\\n  var name = params.name;\\n  var permalink = params.permalink;\\n  var content = params.content;\\n  var label = params.label;\\n\\n  console.log(\\\"Contraption \\\" + id + \\\" [\\\" + label + \\\"] loaded: \\\" + content);\\n}\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nRelated:\n\n* [SharedContent.Save](doc:client-api-sharedcontent-save) \n* [SharedContent.Browse](doc:sharedcontentbrowse)","excerpt":"Receive notifications when shared content is loaded\n`addLoadListener(type, callback)`","slug":"client-api-sharedcontent-addloadlistener","type":"fn","title":"SharedContent.AddLoadListener"}

SharedContent.AddLoadListener

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](doc:shared-content) of the specified type is loaded by the user. It accepts the following arguments: [block:parameters] { "data": { "h-0": "Name", "h-1": "Type", "h-2": "Description", "0-0": "`type`", "0-1": "String", "0-2": "Type of content to listen for", "1-0": "`callback`", "1-1": "Function", "1-2": "Function to call when a shared content load request has been made" }, "cols": 3, "rows": 2 } [/block] The callback method will be passed a single object with the following attributes: [block:parameters] { "data": { "h-0": "Name", "h-1": "Type", "h-2": "Description", "0-0": "`id`", "0-1": "Integer", "0-2": "Unique ID of the created shared content", "1-0": "`name`", "1-1": "String", "1-2": "Name of the shared content", "2-0": "`permalink`", "2-1": "String", "2-2": "Link to the shared content", "3-0": "`content`", "3-1": "String", "3-2": "The content itself", "4-0": "`label`", "4-1": "String", "4-2": "The label for the shared content" }, "cols": 3, "rows": 5 } [/block] [block:callout] { "type": "info", "title": "Note", "body": "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." } [/block] **Example:** Loading shared content with `Contraption` as the content type [block:code] { "codes": [ { "code": "kongregate.sharedContent.addLoadListener(\"Contraption\", onContraptionLoad);\nkongregate.services.connect();\n\nfunction onContraptionLoad(params:Object):void {\n var id:Number = params.id;\n var name:String = params.name;\n var permalink:String = params.permalink;\n var content:String = params.content;\n var label:String = params.label;\n\n trace(\"Contraption \" + id + \" [\" + label + \"] loaded: \" + content);\n}", "language": "javascript", "name": "ActionScript 3" }, { "code": "kongregate.sharedContent.addLoadListener(\"Contraption\", onContraptionLoad);\n\nfunction onContraptionLoad(params) {\n var id = params.id;\n var name = params.name;\n var permalink = params.permalink;\n var content = params.content;\n var label = params.label;\n\n console.log(\"Contraption \" + id + \" [\" + label + \"] loaded: \" + content);\n}", "language": "javascript" } ] } [/block] Related: * [SharedContent.Save](doc:client-api-sharedcontent-save) * [SharedContent.Browse](doc:sharedcontentbrowse)