00:00
00:00
Newgrounds Background Image Theme

Jmurr12 just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Newgrounds Wiki: Flixel

Flixel is a code-based ActionScript 3 framework, so first follow the directions on getting started with the API for your specific development tool: Once you've added the Newgrounds API library to your project, the API is ready to use.

Connecting to the API

If you'd like to replace the default Flixel preloader with the Newgrounds Ad Preloader, you can use the API Connector component. If you are already using the default Flixel preloader, then you can replace your preloader code with the following code to use the API Connector.
package  
{
    import com.newgrounds.*;
    import com.newgrounds.components.*;
    import flash.display.MovieClip;

    public class Preloader extends MovieClip     {         public function Preloader()         {             var apiConnector:APIConnector = new APIConnector();             apiConnector.className = "MyGame";             apiConnector.apiId = "Your API ID";             apiConnector.encryptionKey = "Your Encryption Key";             addChild(apiConnector);

            // center connector on screen             if(stage)             {              apiConnector.x = (stage.stageWidth - apiConnector.width) / 2;              apiConnector.y = (stage.stageHeight - apiConnector.height) / 2;             }         }         } }
Alternatively, if you have your own custom preloader or don't want to use an ad, you can instead use the API.connect method. A good place to do this is in the create method of your FlxGame.
package
{
    import com.newgrounds.components.*;
    import org.flixel.FlxGame;

public class MyGame extends FlxGame {

override protected function create(FlashEvent:Event):void { super.create(FlashEvent);

API.connect(root, "Your API ID", "Your Encryption Key"); } }

Using API components

To use the API components such as the Medal Popup, you must instantiate them and add them to the display list. A good place to do this is in the create method of your FlxGame. For example, this code will create the Medal Popup component:
package
{
    import com.newgrounds.components.*;
    import org.flixel.FlxGame;

public class MyGame extends FlxGame {

override protected function create(FlashEvent:Event):void { super.create(FlashEvent);

var medalPopup:MedalPopup = new MedalPopup(); medalPopup.x = medalPopup.y = 5; root.addChild(medalPopup); } }
For more information on using the components with a code-based workflow, look at Using the API Components.