Topic: Game Programming / API Problem with MAnual Loading
/*
* Called when PlayerClient instantiates on Stage
* @param evt
*/
public function onAddedToStage(evt:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
/*
* Kongregate Stuff
*/
// Pull the API path from the FlashVars
var paramObj:Object = LoaderInfo(root.loaderInfo).parameters;
//ExternalInterface.call(“alert”, "ParamObj: “+paramObj);
// The API path. The debug version (”shadow" API) will load if testing locally.
var api_url:String = paramObj.api_path || “http://www.kongregate.com/flash/API_AS3_Local.swf”;
// Debug
trace ( "API path: " + api_url );
// Load the API
var request:URLRequest = new URLRequest ( api_url );
var loader:Loader = new Loader();
var context:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
loader.contentLoaderInfo.addEventListener ( Event.COMPLETE, onLoadComplete );
loader.load ( request, context );
stage.addChild ( loader );
}
private function onLoadComplete(evt:Event):void
{
trace(“GameKongregate: onLoadComplete”);
// Save Kongregate API reference
kongregate = evt.target.content;
// Connect
if (kongregate && kongregate.services) {
kongregate.services.connect();
}
//kongregate.addEventListener(KongregateEvent.COMPLETE, onServicesComplete);
}