package APIs { import flash.display.Loader; import flash.display.Stage; import flash.events.Event; import flash.net.URLRequest; import flash.system.Security; /** * ... * @author Chris */ public class KONGREGATE { public var stage:Stage; // Kongregate API reference public static var kongregate:*; public function KONGREGATE(stage1:Stage) { stage = stage1; // Pull the API path from the FlashVars var paramObj:Object = stage.loaderInfo.parameters; // The API path. The "shadow" API will load if testing locally. var apiPath:String = paramObj.kongregate_api_path || "http://www.kongregate.com/flash/API_AS3_Local.swf"; // Allow the API access to this SWF Security.allowDomain(apiPath); // Load the API var request:URLRequest = new URLRequest(apiPath); var loader:Loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete); loader.load(request); stage.addChild(loader); } // This function is called when loading is complete private function loadComplete(event:Event):void { // Save Kongregate API reference kongregate = event.target.content; // Connect to the back-end kongregate.services.connect(); // You can now access the API via: // kongregate.services // kongregate.user // kongregate.scores // kongregate.stats // etc... } public static function SubmitScore(score:int):void { kongregate.stats.submit("HighScore",score); } } }