External API Integration

Monkey Targets Forums/Flash/External API Integration

PoliteProgrammer(Posted 2013) [#1]
TLDR - I need up-to-date help with Kongregate or Mochi API integration; get in touch if you know how to do this. :)

Hello Monkey community! This is a more general follow-up to a previous post. I have recently started using Monkey to make Flash games, which, so far, has been a very enjoyable experience. However, I am thoroughly stumped by how to integrate external APIs into my game, particularly either the Kongregate API or the Mochi API; I would like to be able to store high scores and generate leaderboards.

I'm aware that there are tutorials that already deal with this topic:
http://www.monkeycoder.co.nz/Community/posts.php?topic=1825
http://www.monkeycoder.co.nz/Community/posts.php?topic=2264
however, these don't work 'out of the box' for me, which could possibly be the result of changes to Monkey since those tutorials were written (I'm using v67f, by the way). The first errors that I get by following the Kongregate tutorial are due to undefined references to a 'game' object, which I've managed to get around by replacing 'game' with 'this' in the appropriate places. However, I then get various TypeErrors, even though the actionscript appears fine.

My attempt at integrating the Kongregate API is as follows. The contents of "Kongregate.as":
var kongregate:*;

function kongregateInit():void
{
  var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
  var apiPath:String = paramObj.kongregate_api_path || "http://www.kongregate.com/flash/API_AS3_Local.swf";
  this.Security.allowDomain(apiPath);
  var request:URLRequest = new URLRequest(apiPath);
  var loader:Loader = new Loader();
  loader.contentLoaderInfo.addEventListener(Event.COMPLETE, kongregateLoadComplete);
  loader.load(request);
  this.addChild(loader);
}

function kongregateLoadComplete(event:Event):void
{
  kongregate = event.target.content;
  kongregate.services.connect();
}

The contents of "Kongregate.monkey":
Import "Kongregate.as"
Extern
Function kongregateInit:Void()

Then in my main file, "Main.monkey", I simply import Kongregate.monkey and call kongregateInit() from the OnCreate() method.

This all fails with the following error:
Monkey Runtime Error : TypeError: Error #1010
Main.monkey<46>

where this line of code is just the call of kongregateInit().

My attempt at integrating the Mochi API fails in much the same way. Does anyone here have recent experience of integrating either of these APIs that they'd be happy to share, or perhaps know more about actionscript than me that would allow them to spot the problem?