Connecting Twice?

4 posts

Flag Post

I’m not sure if this is a bug or I’m doing something wrong, but when I connect to the API my output box shows:


Alert: Kongregate API shadow services loaded due to local testing. API will load when the game is uploaded.
Alert: Kongregate API shadow services loaded due to local testing. API will load when the game is uploaded.
Kongregate API: IKongregateServices.connect() 
Kongregate API: IKongregateServices.connect() 

Everythings peachy there except the fact it traces twice- is this a bug in Kongregates code or mine? Here is my KongAPI class:

package com.rtl.Utils
{
	import flash.display.Sprite; // Sprite class
	
	import flash.display.LoaderInfo; // Importing everything we need for the KongAPI
	import flash.display.Loader;
	import flash.net.URLRequest;
	import flash.events.Event;
	import flash.system.Security;
	
	/**
	 * ...
	 * @author Aftershock Studios
	 */
	public class KongAPI extends Sprite
	{
		private var _paramObj:Object; // API Variables
		private var _apiPath:String;
		private var _request:URLRequest;
		private var _loader:Loader;
		public var _kongregate:*; // API Reference
		
		public function KongAPI()
		{
			addEventListener( Event.ADDED_TO_STAGE, init );
		}
		
		public function init( e:Event ):void
		{
			
			// Pull the API location from FlashVars.
			_paramObj = LoaderInfo( root.loaderInfo ).parameters;
			
			// The API path. The "shadow" API will load if testing locally.
			_apiPath = _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
			_request = new URLRequest( _apiPath );
			_loader = new Loader();
			_loader.contentLoaderInfo.addEventListener( Event.COMPLETE, loadComplete );
			_loader.load( _request );
			addChild( _loader );
		}
		
		// This function is called when loading is complete
		public function loadComplete( event:Event ):void
		{
			_loader.contentLoaderInfo.removeEventListener( Event.COMPLETE, loadComplete )
			// 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..
		
		}
	}
}

And how I add it:

public var kAPI:KongAPI = new KongAPI();
addChild(kAPI)
 
Flag Post

Remove your event listener in your init function.

 
Flag Post

Umm. remove the listener or remove the code that adds it?

 
Flag Post

removeEventListener( Event.ADDED_TO_STAGE, init );