Be a Supporter!

Browse Sections


Newgrounds Wiki: Events

About Event Handling

Events in the Flash API are modeled after the Actionscript 3.0 EventDispatcher.

Event listeners can be added (using the addEventListener method in the API class) or removed (using the removeEventListener method in the API class), using events as defined in the APIEvent class.

Actionscript 3.0 Example

If you wanted to make a custom event handler for the HOST_BLOCKED event, you would use a script similar to:
import com.newgrounds.API;
import com.newgrounds.APIEvent;

// this is our event listener function onHostBlocked(event:APIEvent):void { trace("This host is not allowed to use this game!"); // tell the API we no longer need this listener API.removeEventListsner(APIEvent.HOST_BLOCKED); }

// tell the api to run the above function when // a HOST_BLOCKED event triggers API.addEventListener(APIEvent.HOST_BLOCKED, onHostBlocked);

Actionscript 2.0 Example

Because Actionscript 2.0 handles the "this" identifier differently in function calls, you need to include a 3rd parameter to addEventListener that identifies what object "this" will refer to in your listener function.
import com.newgrounds.API;
import com.newgrounds.APIEvent;

// this is our event listener function onHostBlocked(event:APIEvent) { trace("This host is not allowed to use this game!"); // tell the API we no longer need this listener API.removeEventListener(APIEvent.HOST_BLOCKED, this); }

// tell the api to run the above function when // a HOST_BLOCKED event triggers API.addEventListener(APIEvent.HOST_BLOCKED, onHostBlocked, this);

API Events

APIEvent instances are passed to every listener function. These events contain results specific to each event, but all share some common properties.
  • event.data - Any mixed data the event has is found in this property
  • event.error - If the event wasn't successful, this property will be an APIError instance.
  • event.success - This is true or false depending on wether or not the command that called the event was successful
Browse the 'Related Pages' below for details on specific events