我想将外部子 swf 加载到父 swf(在同一目录下)。我确实尝试过,加载了孩子,但其中的课程不起作用。
1) 如何加载子 swf 类?
2) 我怎样才能卸载子 swf 的类?(因为可能有许多不同类的分机。swf)
谢谢
主文件
function startLoad(){
var mLoader:Loader = new Loader();
var mRequest:URLRequest = new URLRequest("game1.swf");
var mLoaderContext:LoaderContext = new LoaderContext(false,ApplicationDomain.currentDomain);
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
mLoader.load(mRequest, mLoaderContext);
}
function onCompleteHandler(loadEvent:Event){
var keyManager:Class = ApplicationDomain.currentDomain.getDefinition("net.keithhair.KeyManager") as Class;
addChild(loadEvent.currentTarget.content);
}
游戏1.fla
import net.keithhair.KeyManager;
keyManager=new KeyManager(stage);
keyManager.addKey(["a"], doSomething);
function doSomething():void {
//do something
}
结果:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at net.keithhair::KeyManager/removeListeners()
at net.keithhair::KeyManager/addListeners()
at net.keithhair::KeyManager()
at game1_fla::MainTimeline/frame1()