We have just changed the way our API works, and now it downloads a remote SWF so we only have to maintain one set of code. However, this has broken the integration in PureMVC and I can't work out how it should be done.
Currently, I register the old API in a Proxy, which has a Command that sends all of the requests to it.
The API Loader Class is as follows:
package {
import fl.controls.TextArea;
import flash.display.Loader
import flash.display.LoaderInfo
import flash.net.URLRequest
import flash.events.Event
import flash.display.MovieClip
import flash.system.Security
import com.demonsters.debugger.*;
public class API {
public static var service:Object = { connect: load_service }
public static var clip:MovieClip
public static var GameKey:String
public static var callback:Function;
private static function load_service_complete(e:Event):void {
MonsterDebugger.initialize(clip);
if (e.currentTarget.content != null && e.currentTarget.content.service != null) {
service = e.currentTarget.content.service
service.connect(GameKey, clip);
trace ("[API] Service Successfully Loaded")
API.callback();
} else {
trace("[API] failed to load")
}
}
private static function load_service(mainMovie:MovieClip, GameKey:String, callbk:Function):void {
API.clip = mainMovie;
API.GameKey = GameKey;
hAPI.callback = callbk;
if (service.submitScore == null) {
Security.allowDomain("domain.com")
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, load_service_complete);
loader.load(new URLRequest("domain.com/api.swf"));
clip.addChild(loader); // THIS LINE BREAKS IT
}
}
}
}
The highlighted line above, is the one causing the problem as I can't work out what I need to pass from the Proxy into this class in order to add the SWF to the Movie. It currently says addChild is not defined.
Any help would be great.
Dave.