Posts Tagged ‘api’

  • Using Flixel 2.5 and the Kongregate API

    Versions of Flixel before 2.5 had a handy little class called FlxKong, which neatly wrapped-up the Kongregate API and made it simple to use in your games. It was dropped in the 2.5 release however, and with the introduction of the new camera system and modified display list it made it a bit harder than before to get working. I wrote my own class to get around it, but after some posts on the flixel forums asking for help I figured it made sense to package my class into the Flixel Power Tools and release it.

    At the time of writing the class is only in the dev branch on github, but is pretty much feature complete and ready for use. Using it is simple, just import the class:

    import org.flixel.plugin.photonstorm.API.FlxKongregate;

    .. and then init the API. This downloads the Kongregate API SWF from their server and stores it locally for use:

    FlxKongregate.init(apiHasLoaded);
    
    private function apiHasLoaded():void
    {
    	FlxKongregate.connect();
    }
    

    The “apiHasLoaded” function is your own, it will be fired once the API SWF is downloaded. When this happens you can connect to it as above. The connection is pretty much instant, and you then have access to all of the API functions which I’ve exposed via the class, such as:

    FlxKongregate.isLocal
    FlxKongregate.isGuest
    FlxKongregate.getUserId
    FlxKongregate.getUserName
    FlxKongregate.showSignInBox
    FlxKongregate.showShoutBox
    FlxKongregate.submitStats
    
    etc etc 
    

    Also the api object itself is available via FlxKongregate.api, so you can call any service they have that I’ve not yet exposed in this class.

    There is a Test in the Demo Suite which shows how to use it. Here’s a direct link to the as file.

    Lots of the Kongregate API only works when your game is actually run on Kongregate itself. And equally lots of it such as micro-transactions don’t work at all unless your game is part of their private beta test. So don’t go calling functions randomly! Do check their documentation first.

    Using FlxKongregate without the Flixel Power Tools

    I fully understand if you don’t want to include the whole of my Power Tools library just to use this one class. So here’s how to make it run stand-alone:

    Download the FlxKongregate.as file from github and copy it into your src folder.

    Open it into FlashDevelop (or whatever editor you use) and edit the package. FlashDevelop will even prompt you that the package is wrong and automatically correct it! The default is:

    package org.flixel.plugin.photonstorm.API

    But if you have copied it into your src folder, you should remove everything after “package”. Equally if you have placed it into your own folder, you should make the package line reflect this.

    Once you’ve done that you can use the API as normal.

    Have fun 🙂