Ask the user to change their avatar
submitAvatar(display_object, callback)

Exporting a custom avatar

Kongregate's Avatar Export API gives you the ability to export in-game avatars and let users use them as their Kongregate profile avatar. When you call the submitAvatar function, the user will receive a notification that the game is requesting to change their avatar. At that point, they'll be able to crop the suggested image if they wish, and can choose to accept or decline the avatar modification. This functionality can be used to provide bonuses for players, as well as more directly with avatar creator/editor apps, and probably other uses we haven't even thought of yet.

You can use the submitAvatar function on the images property of the Kongregate API object to export a DisplayObject or a Base64-encoded string containing the image data to be converted to a user avatar. It is highly recommended that avatars be at least 40x40px:

Name

Type

Description

display_object

DisplayObject or Base64-encoded string

The DisplayObject or Base64-encoded string containing the avatar image

callback

Function

The callback function to be called when the operation is complete.

The callback function is passed a single boolean parameter which will be true if the user has accepted the avatar and false if they decide not to use it.

Example: Exporting a rectangle

var rect:Shape = new Shape();
rect.graphics.lineStyle(1);
rect.graphics.beginFill(0x0000FF, 1);
rect.graphics.drawRect(0, 0, 75, 50);

kongregate.images.submitAvatar(rect, onAvatarComplete);

function onAvatarComplete(success:Boolean) {
  if(success) {
    trace("That user must love rectangles!")
  } else {
    trace("Next time I'll try a triangle :(")
  }
}
var base64PNG = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVQYV2NgYAAAAAMAAWgmWQ0AAAAASUVORK5CYII=';

kongregate.images.submitAvatar(base64PNG, function(success) {
    if (success) {
    console.log('That is a small avatar');
  }
});