祝大家万圣节前快乐 :)
我今天的问题是删除子对象时出现的 DisplayObject 错误。我有将启动(addChild)视频容器和视频控件以及添加关闭按钮的代码。现在关闭按钮工作正常,一切正常,删除视频和控件,我可以再次选择另一个视频,但是当您第二次单击关闭时,我收到此错误:
ArgumentError:错误 #2025:提供的 DisplayObject 必须是调用者的子对象。在 flash.display::DisplayObjectContainer/removeChild()
因此,我将问题缩小到删除 videoContainer (包含视频对象)的位置
我播放视频的代码:
public function videoSwitch(videoName):void
{
nv.closeOut();
nv.resetNav = false;
if (!videoPlaying)
{
vc = new VideoClass(videoName, videoHolder);
vc.addEventListener("KillMovie", removePlayer);
container.addChild(videoContainer);
container.addChild(vc);
//container.addChildAt(videoContainer, 1);
//container.addChildAt(vc, 2);
videoPlaying = true;
closeVideo();
}
else if (videoPlaying)
{
vc.clearSource();
container.removeChild(videoContainer);
container.removeChild(vc);
vc = new VideoClass(videoName, videoHolder);
vc.addEventListener("KillMovie", removePlayer);
container.addChild(videoContainer);
container.addChild(vc);
//container.addChildAt(videoContainer, 1);
//container.addChildAt(vc, 2);
closeVideo();
}
trace("videoPlaying = "+videoPlaying+"\r");
}
关闭视频播放器代码: 您可以在我的评论中看到我尝试过的其他代码,但仍然出现错误。
function closeVideo():void
{
closeBtn.visible = true;
closeBtn.x = 770;
closeBtn.y = 20;
closeBtn.buttonMode = true;
container.addChild(closeBtn);
closeBtn.addEventListener(MouseEvent.MOUSE_UP, closeButtonClicked);
function closeButtonClicked(event:MouseEvent):void
{
vc.clearSource();
container.removeChild(videoContainer);
//container.removeChildAt(videoContainer, 1);
container.removeChild(vc);
videoPlaying = false;
closeBtn.visible = false;
}
}
现在我的电影效果很好,但我担心这个错误发生在后台(并显示在我的输出窗口中)最终会导致其他地方出现问题:(
在此先感谢您对这个的任何关注!:)
更新: 已修复!问题是我删除了 kill VC 侦听器,但忘记删除愚蠢的 Close Button Mouse_Event 侦听器:(
function addCloseButton():void
{
container.addChild(closeBtn);
closeBtn.addEventListener(MouseEvent.MOUSE_UP, closeButtonClicked);
function closeButtonClicked(event:MouseEvent):void
{
videoPlaying=false;
vc.clearSource();
removeContainerChildren(); // <- thx Joel!
closeBtn.removeEventListener(MouseEvent.MOUSE_UP, closeButtonClicked);
//^ Forgot this line - thx Jotham!
container.removeChild(closeBtn);
}
}
不知道这张图是否有帮助,但是: