Unload embedded video in flash AS3 (skip intro style)

actionscript-3embedded-resourceflashvideo

Here's the scenario:

  1. i've created an external.swf that contains an embedded video (FLV) in the timeline.
  2. i've created another swf file (player.swf) that loads the external.swf using this:

    var request:URLRequest = new URLRequest("external.swf");
    var loader:Loader = new Loader();
    loader.load(request);
    videoContainer_mc.addChild(loader); 
    
  3. i inserted a skipIntro_btn in player.swf using:

    skipIntro_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownSkip);
    function mouseDownSkip(event:MouseEvent):void {
      videoContainer_mc.removeChild(loader);
      gotoAndPlay("ending");
    } 
    

it seems that the skipIntro_btn unloads the external.swf, but i can still hear the audio of the embedded video. what am i doing wrong? are there any other ways to implement the skip intro effect on embedded videos?

Best Solution

Well, if you can just remove the swf after the click, like this:

var request:URLRequest = new URLRequest("external.swf");
var loader:Loader = new Loader(); 
loader.load(request); videoContainer_mc.addChild(loader);

skipIntro_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownSkip);
function mouseDownSkip(event:MouseEvent):void { 
    videoContainer_mc.removeChild(loader);
    loader.unloadAndStop(true);
    gotoAndPlay("ending");
}

If you can't just remove the swf, then you'll need to stop the movieclip that contains the video inside the loaded swf.

Related Question