我正在努力在一个项目中从孩子到父母 SWF 进行通信,其中父母从影片剪辑中调用孩子。
父动画剪辑在动作层中有这个
var loader:Loader = new Loader();
var defaultSWF:URLRequest = new URLRequest("child.swf");
loader.load(defaultSWF);
//I'm using an if statement to check if the movieclip is loaded to stage
if (loader.parent != null) {
loader.dispatchEvent(new Event(Event.ADDED_TO_STAGE));
trace("loader added to stage"); // trace returns positive
loader.content.addEventListener("directions", childLoader_someSignalHandler);
}
//once a button in the child SWF is clicks the playhead will
//change position on the parent.
function childLoader_someSignalHandler(event:Event):void {
gotoAndStop("directions");
}
子 SWF 将此代码发送给父级:
centre_btn.addEventListener(MouseEvent.MOUSE_DOWN, childBtn_mouseDownHandler);
// thanks to "Florent" for this code.
function childBtn_mouseDownHandler(event:MouseEvent) {
dispatchEvent(new Event("directions"));
}
我返回的错误是:
TypeError:错误 #1009:无法访问空对象引用的属性或方法。