Save a custom level or other shared content
save(type, content, callback, thumbnail, label)

Saving content

You can use the save function on the sharedContent property of the Kongregate API object to submit shared content on the Kongregate back-end. It accepts a type, content string, callback, and optionally a thumbnail and a label:

Name

Type

Description

type

String

Type of content the user wishes to save, 12 characters max

content

String

Value of content to be saved. We strongly recommend keeping these values under 100K since the game will hang until the content is sent, which can lead to a poor user experience if the content is too large

callback

Function

Function to be called when the operation is completed

thumbnail

DisplayObject or Base64-encoded string

Optional, but highly recommended! Send us a DisplayObject or Base64-encoded image string that we will snapshotted and used as a thumbnail for the content. If this is not provided we will take a picture of the entire stage and use that as the thumbnail (for AS3 games)

label

String

Optional label for sub-classing the shared content.

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

Name

Type

Description

success

Boolean

Flag indicating whether or not the operation was successful

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

Example: Save some shared content to as a Contraption with the contents x1y3z10, calling back onContraptionSaved using myContraptionEditor for the thumbnail and with the label Level 3 Solution

kongregate.sharedContent.save('Contraption', 'x1y3z10', onSaved,                                                                     myContraptionEditor,'Level 3 Solution');

function onSaved(params:Object):void {
  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  
  }
}
kongregate.sharedContent.save('Contraption', 'x1y3z10', onSaved,                                                                     myContraptionEditor,'Level 3 Solution');

function onSaved(params) {
  if (params.success) {
    // The shared content was saved successfully.
    console.log("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  
  }
}

Related: