Youtube AS3 API内存泄漏



我在使用AS3 youtube播放器时出现内存泄漏。所有侦听器都已删除。请帮助找到解决方案。

public class YoutubeStreamTest extends Sprite
{
    private var _loader : Loader;
    private var _player : Object;
    private var _spr : Sprite;
    // constructor -----------------------------------------
    public function YoutubeStreamTest()
    {
        addEventListener(Event.ADDED_TO_STAGE, hAddedToStage);
    }
    // methods ---------------------------------------------

开始加载视频

    private function startVideo() : void {
        _loader = new Loader();
        _loader.contentLoaderInfo.addEventListener(Event.INIT, hLoaderInit, false, 0, true);
        _loader.load(new URLRequest("http://www.youtube.com/v/FooZ5x-OX0E?version=3&controls=0&showinfo=0&end=3")); //yPrHf776eWA = the vid u want t play
    }
    // handlers --------------------------------------------

正在等待视频就绪

    private function hLoaderInit(event : Event) : void {
        _loader.contentLoaderInfo.removeEventListener(Event.INIT, hLoaderInit);
        _player = _loader.content;
        _player.addEventListener("onReady", hPlayerReady, false, 0, true);
        addChild(_player as DisplayObject);
        _player.x = 0;
        _player.y = 20;
        _spr = new Sprite();
        _spr.graphics.beginFill(0x0, .1);
        _spr.graphics.drawRect(0, 0, 500, 500);
        _spr.graphics.endFill();
        addChild(_spr);
    }

准备就绪-开始播放

    private function hPlayerReady(event : Event) : void 
    {
        _player.removeEventListener("onReady", hPlayerReady);
        _player.setSize(440, 260);
        _player.playVideo();
    }
    private function hAddedToStage(event : Event) : void {
        Security.allowInsecureDomain("*");
        Security.allowDomain("*");
        startVideo();
        addEventListener(MouseEvent.CLICK, hClick);
    }

点击加载新视频实例

    private function hClick(event : Event) : void {
        removeEventListener(Event.ADDED_TO_STAGE, hAddedToStage);
        if(_player) {
            removeChild(_player as DisplayObject);
            _player.destroy();
            removeChild(_spr);
            _loader.unloadAndStop(true);
        }
        startVideo();
    }
    // getsetters ------------------------------------------

}

点击监听器怎么样,并添加到stage监听器中?后者在点击处理程序中未注册-错误?

此外,您可能希望在注册事件(弱侦听器)时使用以下内容

addEventListener(事件类型、处理程序、useCapture、优先级、true);

例如

addEventListener(MouseEvent.CLICK, onClicked, false, 0, true);

向致以最良好的问候

相关内容

  • 没有找到相关文章

最新更新