addEventListener(event_type, callback)

Services events

This method can be used to listen for events related to the Kongregate user.

The addEventListener method takes two arguments, the event type, and a callback function:

Name

Type

Description

event_type

String

Type of event to listen for

callback

Function

Function to call when the event is triggered

User events

The following event types are currently supported:

Name

Description

login

The user has converted from a guest to a registered user. User info methods on the services object will return updated information after this event is triggered.

Example: Listen for user login event

kongregate.services.addEventListener("login", onKongregateInPageLogin);

function onKongregateInPageLogin(event:Event):void {
  var user_id:Number = kongregate.services.getUserId();
  var username:String = kongregate.services.getUsername();
  var token:String = kongregate.services.getGameAuthToken();
}
kongregate.services.addEventListener("login", onKongregateInPageLogin);

function onKongregateInPageLogin() {
  var user_id = kongregate.services.getUserId();
  var username = kongregate.services.getUsername();
  var token = kongregate.services.getGameAuthToken();
}

Related: