删除Child,这样我就可以加载新的FLV_Player

发布于 2024-12-12 00:07:54 字数 408 浏览 0 评论 0原文

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

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

我需要完全删除 main_container.addChild (my_player);

这是应该完成所有操作的函数:

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

I am making a flv player with playlist that has and English and Spanish section. The English is the default section and that works very well but when I click "Spanish" button I am trying to remove all the children that were added at start time and run two new functions that load my Spanish data.

The only thing is that removeChild is not working. I can hear my Spanish video load but the English one is still playing in the background.

I need to completely remove main_container.addChild (my_player);

here is the function that should do it all:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

高速公鹿 2024-12-19 00:07:54

确保您已停止播放器:

my_player.stop();

如果您想从 main_container 中删除所有子级,您可以:

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

Ensure you have stopped your player:

my_player.stop();

If you want to remove all children from main_container, you could:

while(main_container.numChildren > 0)
{
    main_container.removeChildAt(0);
}
静待花开 2024-12-19 00:07:54

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

my_container.removeChild(my_flvplayer_instance);

my_flvplayer_instance.getVideoPlayer(0).close();

my_flvplayer_instance=null;

关键是 getVideoPlayer(0).close();,它关闭隐藏在 FLVPlayback 组件中的网络流。

Sorry this is a little late in getting to you, but it'll be useful to future readers. This problem has been the bane of many of my projects. Here is the solution:

my_container.removeChild(my_flvplayer_instance);

my_flvplayer_instance.getVideoPlayer(0).close();

my_flvplayer_instance=null;

the key is getVideoPlayer(0).close(); which closes the netstream hidden within the FLVPlayback component.

丑疤怪 2024-12-19 00:07:54

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

If you are using net stream you need to close the connection to the stream, how are you implementing this player?

如梦初醒的夏天 2024-12-19 00:07:54

从舞台上删除显示对象(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");
}

Removing a display object(my_player) from the stage does NOT stop its functions from working. You just will not see it
This is why garbage collection fails and creates memory leaks.
You need to to do the follow.

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");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文