Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

removeChild() but audio still plays

Explorer ,
Apr 26, 2013 Apr 26, 2013

Hy!

I have a flash website where different pages are movieclips which are added or removed from the main stage, depending on which buttons are clicked.

The problem is that I have a 'video' page where a YouTube player is embedded. The video plays as soon as the movieclip loads, but when I remove the child from the stage and I add another movieclip on top of it, the audio still plays.

I have tried using the SounMixer.stopAll() but it works only when I test swf in Flash. When I open the swf separately from the folder it is in, it doesn't work anymore.

Can somebody please help me?

Thanks a lot!

TOPICS
ActionScript
1.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Apr 26, 2013 Apr 26, 2013

Add another listener for REMOVED_FROM_STAGE use it to call either pauseVid or muteVid

Translate
Guide ,
Apr 26, 2013 Apr 26, 2013

Try calling stop() on the FLVPlayback component before you remove it. Probably the best way to handle this is to have the loaded MovieClip that contains the component watch for REMOVED_FROM_STAGE and call stop() on the child component when that event fires.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 26, 2013 Apr 26, 2013

Thank you for answering so fast!

I do not understand where I should call stop(). The code for my YouTube player is inside the movieclip, whereas the code for adding and removing different movieclips from the stage is on the main stage.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 26, 2013 Apr 26, 2013

I think I was pretty clear in my answer where the code should go. Do you own the code for the MovieClip that contains the FLVPlayback control or not? If you don't, you'll need to try to fish around in it somehow and find that control.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 26, 2013 Apr 26, 2013

It is not a FLVPlayback control, it is a YouTube ActionScript 3.0 Player API.

Here is the code :

// The player SWF file on www.youtube.com needs to communicate with your host

// SWF file. Your code must call Security.allowDomain() to allow this

// communication.

Security.allowDomain("www.youtube.com");

// This will hold the API player instance once it is initialized.

var player:Object;

var loader:Loader = new Loader();

loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);

loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3")); //load the embedded player

play_btn.addEventListener(MouseEvent.CLICK, playVid);

pause_btn.addEventListener(MouseEvent.CLICK, pauseVid);

video1_btn.addEventListener(MouseEvent.CLICK,playVid1);

video2_btn.addEventListener(MouseEvent.CLICK,playVid2);

video3_btn.addEventListener(MouseEvent.CLICK,playVid3);

mute_btn.addEventListener(MouseEvent.CLICK,muteVideo);

unmute_btn.addEventListener(MouseEvent.CLICK,unmuteVideo);

function onLoaderInit(event:Event):void {

    addChild(loader);

    loader.content.addEventListener("onReady", onPlayerReady);

    loader.content.addEventListener("onError", onPlayerError);

    loader.content.addEventListener("onStateChange", onPlayerStateChange);

    loader.content.addEventListener("onPlaybackQualityChange", onVideoPlaybackQualityChange);

}

function onPlayerReady(event:Event):void {

    // Event.data contains the event parameter, which is the Player API ID

  trace("player ready:", Object(event).data);

  player = loader.content;

          player.loadVideoByUrl("http://www.youtube.com/v/v6oJ5rw9mys",0);

    // Set appropriate player dimensions an its position

  player.setSize(480, 360);

          player.x=50;

          player.y=220;

          video_title.text="Multiplying Sevens-Times Table";

}

function onPlayerError(event:Event):void {

    // Event.data contains the event parameter, which is the error code

    trace("player error:", Object(event).data);

}

function onPlayerStateChange(event:Event):void {

    // Event.data contains the event parameter, which is the new player state

    trace("player state:", Object(event).data);

}

function onVideoPlaybackQualityChange(event:Event):void {

    // Event.data contains the event parameter, which is the new video quality

    trace("video quality:", Object(event).data);

}

I have taken this code from its YouTube ActionScript 3.0 Player API Reference

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 26, 2013 Apr 26, 2013

Add another listener for REMOVED_FROM_STAGE use it to call either pauseVid or muteVid

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 26, 2013 Apr 26, 2013

Yes it worked!

Thank you very very much for your help!

The code I used is this:

this.addEventListener(Event.REMOVED_FROM_STAGE, videoRemoved);

 

function videoRemoved(e:Event):void{

                    player.pauseVideo();

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 26, 2013 Apr 26, 2013
LATEST

You're welcome

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines