Flash 删除child以便我可以加载新的FLV_播放器

Flash 删除child以便我可以加载新的FLV_播放器,flash,actionscript-3,removechild,Flash,Actionscript 3,Removechild,我正在制作一个flv播放器,播放列表中有英语和西班牙语部分。英语是默认的部分,效果很好,但当我单击“西班牙语”按钮时,我试图删除在开始时添加的所有子项,并运行两个加载西班牙语数据的新函数 唯一的问题是removeChild不起作用。我能听到我的西班牙语视频,但英语视频仍在后台播放 我需要完全删除main_container.addChild(我的_播放器) 以下是应该完成这一切的函数: function playSpanish (evt:MouseEvent){ main_contain

我正在制作一个flv播放器,播放列表中有英语和西班牙语部分。英语是默认的部分,效果很好,但当我单击“西班牙语”按钮时,我试图删除在开始时添加的所有子项,并运行两个加载西班牙语数据的新函数

唯一的问题是removeChild不起作用。我能听到我的西班牙语视频,但英语视频仍在后台播放

我需要完全删除
main_container.addChild(我的_播放器)

以下是应该完成这一切的函数:

function playSpanish (evt:MouseEvent){
    main_container.removeChild(my_player);
    gotoAndStop(2);
    trace("IN SPANISH");
}

确保您已停止播放机:

my_player.stop();
如果要从主容器中删除所有子容器,可以:

while(main_container.numChildren > 0)
{
    main_container.removeChildAt(0);
}

如果您正在使用网络流,则需要关闭与流的连接,您如何实现此播放器?

从后台删除显示对象(my_player)不会停止其功能。你就是看不到它
这就是垃圾收集失败并导致内存泄漏的原因。
你需要做到以下几点

function playSpanish (evt:MouseEvent){
    // make sure you call stop on the video to you know it is not playing
    my_player.stop()

    // remove it from the container/stage
    main_container.removeChild(my_player);

    // remove all event listeners
    my_player.removeEventlistener( EVENT, funcName );

    // null the object out to help promote garbage collection
    my_player = null;


    // do your other code here
    gotoAndStop(2);
    trace("IN SPANISH");
}

很抱歉,这对你来说有点晚了,但它对未来的读者很有用。这个问题一直困扰着我的许多项目。以下是解决方案:

my_container.removeChild(my_flvplayer_instance);

my_flvplayer_instance.getVideoPlayer(0).close();

my_flvplayer_instance=null;

键为
getVideoPlayer(0.close()关闭隐藏在FLVPlayback组件中的netstream。

英语视频继续播放,但我也能听到西班牙语视频开始播放。不确定为什么不删除它。确保适当的生命周期:“my_player”实例必须首先:停止(),删除子项,添加子项并应用下一语言的设置。