PureMVC Architects Lounge

PureMVC Manifold => Standard Version => Topic started by: Nebulous on April 20, 2011, 05:18:13



Title: addChild Problem
Post by: Nebulous on April 20, 2011, 05:18:13
Hi There,

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.


Title: Re: addChild Problem
Post by: puremvc on April 25, 2011, 07:28:25
It currently says addChild is not defined.

Doesn't look like you've even gotten into PureMVC territory yet. The static clip property and this method that sets it aren't working. I don't immediately see anything wrong, but I suggest using the debugger to check inside the  load_service method and see what the clip and mainMovie properties look like just before trying the addChild.

-=Cliff>