Be a Supporter!

Browse Sections

Newgrounds Wiki: Connecting to the API

Adobe Flash

Flash users should follow the instructions on Using the API with Flash. The API Connector component will connect to the API if your API info has been entered into the connector parameters.

Code-based workflows

Code-based workflows should connect to the API using API.connect(). This call should be made before any other features of the API are used.
import com.newgrounds.*;
API.connect(root, "Your API ID", "Your Encryption Key");
Note that API.connect requires root, so it's best to avoid calling it in a constructor where root can be null. Instead, listen for the ADDED_TO_STAGE event before calling connect.

When the API has connected, it will fire the API_CONNECTED event.
import com.newgrounds.*;
API.addEventListener(APIEvent.API_CONNECTED, onAPIConnected);

function onAPIConnected(event:APIEvent):void { if(event.success) { trace("The API is connected and ready to use!"); } else { trace("Error connecting to the API: " + event.error); } }
You are ready to go! You can now use the various API features in your movie. Try out some of the following features: