Topic: Game Programming /
API Issue
Hi,
I’m trying to use the Kongregate API in my project but I’ve got some problems:
when I run my project locally everything works perfectly, but when I load my project in the preview mode I’ve got an error. After a lot of tests I discovered that the problem is my _api.services that is null.
Anyone knows why?
Thank You
This is the code i used:
// Pull the API path from the FlashVars
var paramObj : Object = LoaderInfo( _stage.root.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, KongAPIv2LoadComplete );
loader.load( request );
_stage.addChild( loader );
private function KongAPIv2LoadComplete( event : Event ) : void
{
//event.currentTarget.removeEventListener(Event.COMPLETE, KongAPIv2LoadComplete);
if( event != null && event.target != null && event.target.content != null )
{
_api = event.target.content;
if( _api )
{
_stage.addChild( _api );
//if( _api.services != null )
//{
_api.services.connect();
_initialized = true;
//}
if( _loadCompleteCallback != null )
_loadCompleteCallback( this );
}
}
else
{
if( _loadCompleteCallback != null )
_loadCompleteCallback( this );
}
}
|