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:

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

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:

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:

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 :)

Posted on August 3rd 2011 at 2:03 pm by .
View more posts in Flixel. Follow responses via the RSS 2.0 feed.


5 Responses

Leave a comment
  • superdeformed
    August 3rd 2011 at 4:53 pm

    somebody buy this man a beer.

  • August 3rd 2011 at 7:26 pm

    Been meaning to learn flixel lately…

  • Victor Grunn
    December 17th 2011 at 7:00 am

    Not sure if this is due to FlxKongregate or Kong itself (or me, somehow), but FlxKongregate.showRegistrationBox(); crashes with

    [Fault] exception, information=ReferenceError: Error #1069: Property showRegistrationBox not found on com.kongregate.as3.client.services.KongregateServiceShadow and there is no default value.

  • December 17th 2011 at 11:10 am

    It’s entirely possible that method doesn’t exist in a newer version of their API. Look at their docs to see what it might have changed to.

  • Victor Grunn
    December 17th 2011 at 10:17 pm

    Thanks. They’re showing it in their docs, but maybe those are out of date or it doesn’t work in shadow. I’ll keep at it.

Make yourself heard