10 Replies Latest reply: Oct 26, 2009 4:35 AM by Lujunq RSS

    I removeChild but audio still plays

    BrianatArena Community Member

      I have as3 script that loads an external swf which contains flv video:

       

      var eventInitialLoader:Loader = new Loader();

      var eventInitialURL:String = parent['eventPath'+ie];
      var eventInitialRequest:URLRequest = new URLRequest(eventInitialURL);
      eventInitialLoader.load(eventInitialRequest);
      eventOdd.addChild(eventInitialLoader);

       

      ...And some script later on that removes it:

       

      eventOdd.removeChild(eventInitialLoader);

       

      The movie clip is removed but the audio continues to play. Why is this? What can I do to make sure the audio is removed also?

       

      Thank You!

        • 1. Re: I removeChild but audio still plays
          Lujunq Community Member

          When you remove the movieclip using "removeChild" you're only taking if off the display list, so it is not seen. However it is still there and you'll hear any sound it produces... To avoid this you must unload it, delete it or do anything to completeley remove it (not only taking it off the display list). In this case, since you're using the Loader Class you may simply call the unload method:

          eventOdd.removeChild(eventInitialLoader);

          eventInitialLoader.unload();

          Check the docummentation for this unload method (Loader Class) since it may be necessary to clear event assignments or associated netstrems before calling it.

          • 2. Re: I removeChild but audio still plays
            BrianatArena Community Member

            Well I tried that and audio still plays. Checked several other forums and to the best of my searches this is one of those issues that never provides a solution. Someone recommended SoundMixer.stopAll(); which will do for now. Thanks.

            • 3. Re: I removeChild but audio still plays
              timlitos Community Member

              I am having a very similar issue but my set up is a bit different. I am loading the video this way:

               

              addChild(AL_mc);

              and was trying to remove it this way:
              removeChild(AL_mc);
              So the video goes away but the audio stays playing. Is there a way of fixing this with my current code intact? or do I need to set things up differently?
              Thanks!

              • 4. Re: I removeChild but audio still plays
                Lujunq Community Member

                You must always remember that just removing an object from display list won't "kill" it: it'll be still active and running. At your case I would first stop the video, then remove it from display list ( removeChild(AL_mc); ), then, if it is not to be used anymore, make it free for the garbage collector (something like AL_mc = null; ). But remember that you must remove all references to this object for it to be completely removed. Also, any event listeners registered to it must be removed.

                • 5. Re: I removeChild but audio still plays
                  timlitos Community Member

                  thanks!

                   

                  so the code should look like this:

                  removeChild(AL_mc);
                  Al_mc = null;
                  ???
                  and what snippet of code should I use to stop the video first?

                  • 6. Re: I removeChild but audio still plays
                    Mike6679 Community Member

                    Hey BrianatArean I have the same problem . Were you using the Video class? I user this code to kill everything but the audio still plays:

                     

                    public function stopIt()
                            {
                               
                                video.clear();
                                ns.close();
                             }
                            //-------------------------------------------
                            public function killIt()
                            {
                               
                                 trace("VideoHandler.killIt() called");
                               
                                 stopIt();
                                 _stage.removeChild(video);
                                
                                 nc.removeEventListener (NetStatusEvent.NET_STATUS,checkConnect);
                                 ns.removeEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
                                
                                 nc.close();
                                
                                 video = null;
                                 ns = null;
                                 nc = null;
                                
                                 flag_Running =false;
                               
                            }

                    • 7. Re: I removeChild but audio still plays
                      BrianatArena Community Member

                      I had to use stopAllSounds();. And it works. But I could see how this would suck if you wanted other sounds to continue playing.

                      • 8. Re: I removeChild but audio still plays
                        Mike6679 Community Member

                        thx for the reply....Ah, funny I use AS3 and I was JUST looking at the equivalent which is SoundMixer.stopAll();  hmmm yeah it will work for me but it no good if you only want to stop one audio clip from a movie.

                         

                        If you are trying to stop your vid from a parent video,  In CS4 there wil be a function called "imgLoader.unloadAndStop()" will will supposedly take care of this issue......

                         

                        thanks again

                         

                        -Mike

                        • 9. Re: I removeChild but audio still plays
                          Triynko Community Member

                          And how exactly are we supposed to know about and remove or stop every movieclip, registered event, or sound clip playing in an externally loaded swf file?  First, you'd have to be the one who built it, which is not necessarily the case, and even if we did... for something like an Adobe Captivate swf, there is no documented ActionScript API for those.... so we're basically screwed until Adobe releases the source code for Loader.unloadAndStop and makes it available in a form compatible with flash player 9.  UNLOAD means UNLOAD, as in the opposite of LOAD.  The current Loader.unload method doesn't unload anything, and doesn't seem to be much different than just calling removeChild.

                          • 10. Re: I removeChild but audio still plays
                            Lujunq Community Member

                            Well, considering external swf files with sound I had success using flash standard methodsto "remove" them. First, I always remove any listener associated with the loader (I guess remaining listeners may prevent the unload method to work). Then, I remove the child, call the unload method and, to make sure, I set the loader itself to null. This seems to work for me...