Kongregate Level Sharing API (AS3 only)Kongregate's Content Sharing API makes it easier than ever for developers to add features like custom level sharing to your games. The new API gives your players the ability to:
We urge you all to check out the first integration of level sharing in Hexiom: Connect and grab the complete documentation here Setup
The shared content API is available through the // Register the shared content load listener before connecting kongregate.sharedContent.addLoadListener('Level', onLoadLevel); // Connect kongregate.services.connect(); Each game may save up to 10 different types of shared content, so the possibilities of what you can do with this API are nearly endless. API FunctionsAdding load event listeners
You can use the addLoadListener(contentType:String, callback:Function):void
The callback function must accept a single
Example: Loading shared content with "Contraption" as the content type: kongregate.sharedContent.addLoadListener("Contraption", onContraptionLoad); function onContraptionLoad(params:Object) { 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); } Browsing shared content
By using the browse(contentType:String, sortOrder:String=null, label:String=null):void
Example: Display a Shared Content browser for Contraptions, only showing those by your friends with the "Level 3 Solution" label kongregate.sharedContent.browse("Contraption", kongregate.sharedContent.BY_FRIENDS, "Level 3 Solution"); Saving content
You can use the save(type:String,content:String,callback:Function,thumb:DisplayObject=null,label:String=null):void
The
Example: Save some shared content to as a "Contraption" with the contents "x1y3z10", calling back kongregate.sharedContent.save('Contraption', 'x1y3z10', onSaved, myContraptionEditor, 'Level 3 Solution'); function onSaved(params:Object) { if (params.success) { // The shared content was saved successfully. trace("Content saved, id:" + params.id + ", name:" + params.name); } else { // The shared content was not saved. // The most likely cause of this is that the User dismissed the save dialog } } Saving shared content on sites other than KongregateYou may submit shared content created in versions of your game hosted on sites other than Kongregate. The API simply consists of a set of URL parameters you pass along with a GET request to your game's URL on Kongregate. The relevent query parameters are type, content, and optionally, label. Note that this method is more limited in terms of the size of the content due to browser limitations with passing through a URL - they need to be limited to under 2,000 characters after encoding in order to ensure that it will work. Additionally, a trailing &z must be appended to the URL to indicate the content was not truncated. ExampleThis snippet is a simple function that accepts the relevant arguments and forwards them to Kongregate: var saveRemote:Function=function(kongregateGameUrl:String,type:String,content:String,label:String=null):void{ var toQueryString:Function = function(params:Object):String { var q:Array = []; for (var p:String in params) q.push(encodeURIComponent(p) + '=' + encodeURIComponent(params[p])); return q.join('&'); } var loc:String = kongregateGameUrl + "?" + toQueryString({ 'type': contentType, 'content': content, 'label': label }) + '&z'; // This &z sigil indicates that no content was truncated from the URL by a nasty browser // and is required for your level to be saved when a user visits the game // Make sure your URL isn't going to be too long to send through a browser if (loc.length < 2000) navigateToURL(new URLRequest(loc), '_blank'); // else... // You will need to provide some error handling in cases where the content is too large } |