17 Replies Latest reply: Jun 15, 2012 4:15 PM by iFlashAppsToo RSS

    How can I stop timeline sounds in external swf files from playing during loading?

    mlouisem

      I am having a problem with timeline sounds in external swf files playing during loading in a main swf. Can anyone help me?

      Here is some of the code from the main swf. I hope I have included enough.

      Thanks.

       

       

      import flash.events.MouseEvent;

      import flash.display.MovieClip;

      import flash.display.Loader;

      import flash.events.ProgressEvent;

      import flash.events.Event;

      import flash.net.URLRequest;

      import fl.events.SliderEvent;

      import flash.media.SoundTransform;

       

      preloader_mc.fill_mc.scaleX = 0;

       

      var swfA:Array = ["part1.swf","part2.swf"];

      var frameA:Array = [];

      var currentLoader:Loader;

      var swfTotalFrames:int;

       

      var tl:MovieClip = this;

      var st:SoundTransform = new SoundTransform()

      var index:int = 0;

      loadNextF();

      play_slider.enabled = false;

       

      function loadNextF():void{

                      tl["loader_"+index] = new Loader();

                      tl["loader_"+index].name = index.toString();

                      tl["loader_"+index].contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,progressF);

                      tl["loader_"+index].contentLoaderInfo.addEventListener(Event.COMPLETE,completeF);

                      tl["loader_"+index].load(new URLRequest(swfA[index]));

      }

      function progressF(e:ProgressEvent):void{

                      var fractionLoaded:Number = index/swfA.length+e.bytesLoaded/(e.bytesTotal*swfA.length);

                      preloader_mc.fill_mc.scaleX = fractionLoaded;

                      preloader_mc.tf.text = (100*fractionLoaded)+"% Loaded";

      }

       

      function completeF(e:Event):void{

                      tl["loader_"+index].contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS,progress F);

                      tl["loader_"+index].contentLoaderInfo.removeEventListener(Event.COMPLETE,completeF);

                      SoundMixer.stopAll();

                      var mc:MovieClip = MovieClip(tl["loader_"+index].content);

                      mc.gotoAndStop(1);

                      frameA.push(mc.totalFrames);

                      index++;

                      if(index<swfA.length){

                                      loadNextF();

                      } else {

                                      // all loads complete.  start play.

                                      restart_mc.buttonMode = true;

                                      restart_mc.alpha = 1;

                                      tl.addEventListener(Event.ENTER_FRAME,playUpdateF);

                                      tl.removeChild(preloader_mc);

                                      preloader_mc = null;

                                      play_slider.enabled = true;

                                      playpause_mc.alpha = 1;

                                      currentLoader = tl["loader_0"];

                                      tl.addChild(currentLoader);

                                      MovieClip(currentLoader.content).play();

                                      sliderParamsF();

                      }

      }

        • 1. Re: How can I stop timeline sounds in external swf files from playing during loading?
          esdebon Community Member

          maybe

           

          for(var i:int=0; i<swfA.lenght; i++){

               tl["loader_"+i].contentLoaderInfo.SoundMixer.stopAll();

          }

          • 2. Re: How can I stop timeline sounds in external swf files from playing during loading?
            mlouisem Community Member

            Thanks for your reply. It didn't work. Any other suggestions?

            • 3. Re: How can I stop timeline sounds in external swf files from playing during loading?
              esdebon Community Member
              I do not know what the name of the sound object within the swf, but you have to specifically refer to it and stop it, SoundMixer.stopAll (); stops the sounds of your movie, but the sounds within the swf "are not in the movie ", are in a own

               

              • 4. Re: How can I stop timeline sounds in external swf files from playing during loading?
                mlouisem Community Member

                There is no sound in the main swf. I have about 70 sounds in my two external swfs. Do I have to stop each one? Can you tell me how?

                Thanks.

                • 5. Re: How can I stop timeline sounds in external swf files from playing during loading?
                  esdebon Community Member

                  Would be something like:

                   

                  tl["loader_"+i].contentLoaderInfo.channelName.stop();

                   

                  To each sound

                   

                   

                  Or maybe you'd need a function within the SWF each stop all sounds using SoundMixer.stopAll();

                  , and call that function from your main movie.

                   

                   

                  tl["loader_"+i].contentLoaderInfo.myFunctionMute();

                  • 6. Re: How can I stop timeline sounds in external swf files from playing during loading?
                    esdebon Community Member

                    I am in the work, i haven´t speakers

                     

                    try this

                     

                    Add in the first frame of part1.fla and part2.fla this code:

                     

                    function mute():void {

                        SoundMixer.stopAll();

                    }

                     

                    and in the file remind_main_mod.fla

                     

                    SoundMixer.stopAll();

                    MovieClip(currentLoader.content).mute();

                     

                    each time thatlook

                     

                    SoundMixer.stopAll();

                    • 7. Re: How can I stop timeline sounds in external swf files from playing during loading?
                      iFlashAppsToo Community Member

                      I have about 70 sounds in my two external swfs. Do I have to stop each one?

                       

                      //---

                       

                      more than likely, yes. i guess it would depend on how you have the 70 sounds set up in your external swf... i mean:

                       

                      do you have 70 named movieclips on the external swf stage with a separate sound in each one? and do they each have a stop() action in the first frame?

                       

                      or

                       

                      do you tell your external swf to go to a certain frame label which plays a sound on the timeline at that label?

                       

                      or

                       

                      are your 70 sounds created dynamically with code and told to .start()?

                       

                      //---

                       

                      also keep in mind, a loading swf will start to play even before it is completely loaded. so instead of when it's completely loaded, try stopping the loaded swf with a listener for "init", which is when the loaded swf enters its first frame:

                       

                      function loadNextF():void{

                                      tl["loader_"+index] = new Loader();

                                      tl["loader_"+index].name = index.toString();

                                      tl["loader_"+index].contentLoaderInfo.addEventListener(ProgressEvent. PROGRESS,progressF);

                                      tl["loader_"+index].contentLoaderInfo.addEventListener(Event.COMPLETE ,completeF);

                                     tl["loader_"+index].contentLoaderInfo.addEventListener(Event.INIT, initF);                                     

                                      tl["loader_"+index].load(new URLRequest(swfA[index]));

                      }

                       

                      function initF(e:Event):void{

                                      SoundMixer.stopAll();

                                      var mc:MovieClip = MovieClip(tl["loader_"+index].content);

                                      mc.gotoAndStop(1);

                      }

                      • 8. Re: How can I stop timeline sounds in external swf files from playing during loading?
                        mlouisem Community Member

                        esdebon,

                        i tried this but now i have no sound at all.

                         

                        i'm not sure if i put the code for

                        remind_main_mod.fla

                        in the right place.

                         

                        i put it after

                        play_slider.enabled = false;

                         

                        is that ok?

                         

                        thanks so much for your help

                        • 9. Re: How can I stop timeline sounds in external swf files from playing during loading?
                          esdebon Community Member

                          import flash.events.MouseEvent;

                          import flash.display.MovieClip;

                          import flash.display.Loader;

                          import flash.events.ProgressEvent;

                          import flash.events.Event;

                          import flash.net.URLRequest;

                          import fl.events.SliderEvent;

                          import flash.media.SoundTransform;

                           

                          preloader_mc.fill_mc.scaleX = 0;

                           

                          var swfA:Array = ["part1.swf","part2.swf"];

                          var frameA:Array = [];

                          var currentLoader:Loader;

                          var swfTotalFrames:int;

                           

                          var tl:MovieClip = this;

                          var st:SoundTransform = new SoundTransform()

                          var index:int = 0;

                          loadNextF();

                          play_slider.enabled = false;

                           

                          function loadNextF():void{

                              tl["loader_"+index] = new Loader();

                              tl["loader_"+index].name = index.toString();

                              tl["loader_"+index].contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,progressF);

                              tl["loader_"+index].contentLoaderInfo.addEventListener(Event.COMPLETE,completeF);

                              tl["loader_"+index].load(new URLRequest(swfA[index]));

                          }

                          function progressF(e:ProgressEvent):void{

                              var fractionLoaded:Number = index/swfA.length+e.bytesLoaded/(e.bytesTotal*swfA.length);

                              preloader_mc.fill_mc.scaleX = fractionLoaded;

                              preloader_mc.tf.text = (100*fractionLoaded)+"% Loaded";

                          }

                          function completeF(e:Event):void{

                              tl["loader_"+index].contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS,progress F);

                              tl["loader_"+index].contentLoaderInfo.removeEventListener(Event.COMPLETE,completeF);

                              SoundMixer.stopAll();

                             

                              var mc:MovieClip = MovieClip(tl["loader_"+index].content);

                              mc.gotoAndStop(1);

                              frameA.push(mc.totalFrames);

                              index++;

                              if(index<swfA.length){

                                  loadNextF();

                              } else {

                                  // all loads complete.  start play.

                                  restart_mc.buttonMode = true;

                                  restart_mc.alpha = 1;

                                  tl.addEventListener(Event.ENTER_FRAME,playUpdateF);

                                  tl.removeChild(preloader_mc);

                                  preloader_mc = null;

                                  play_slider.enabled = true;

                                  playpause_mc.alpha = 1;

                                  currentLoader = tl["loader_0"];

                                  tl.addChild(currentLoader);

                                  MovieClip(currentLoader.content).play();

                                  sliderParamsF();

                              }

                          }

                          ///////////////// start sliders /////////////////////////////////

                          sound_slider.addEventListener(SliderEvent.CHANGE,soundSliderF);

                          function soundSliderF(e:SliderEvent):void{

                              st.volume = e.value/100;

                              tl.soundTransform = st;

                          }

                          play_slider.addEventListener(SliderEvent.CHANGE,playSliderF);

                          play_slider.addEventListener(MouseEvent.MOUSE_DOWN,playSliderDownF);

                          //play_slider.addEventListener(MouseEvent.MOUSE_UP,playSliderUpF);

                           

                          function playSliderDownF(e:MouseEvent):void{

                              tl.removeEventListener(Event.ENTER_FRAME,playUpdateF);

                              stage.addEventListener(MouseEvent.MOUSE_UP,playSliderUpF);

                          }

                          function playSliderUpF(e:MouseEvent):void{

                              tl.addEventListener(Event.ENTER_FRAME,playUpdateF);

                          }

                          function playSliderF(e:SliderEvent):void{

                              SoundMixer.stopAll();

                              var frameNum:int = Math.ceil(swfTotalFrames*e.value/100);

                              var partialTotalFrames:int = 0;

                              for(var i:int=0;i<frameA.length;i++){

                                  partialTotalFrames += frameA[i];

                                  if(partialTotalFrames>=frameNum){

                                      break;

                                  }

                              }

                             

                              partialTotalFrames -= frameA[i];

                              //trace(i,frameNum,frameNum-partialTotalFrames);

                              if(currentLoader!=tl["loader_"+(i)]){

                                  tl.removeChild(currentLoader);

                                  MovieClip(currentLoader.content).stop();

                                  currentLoader = tl["loader_"+(i)];

                                  tl.addChild(currentLoader);

                                 

                              }

                              if(playpause_mc.currentFrame==1){

                                  MovieClip(currentLoader.content).gotoAndPlay(frameNum-partialTotalFrames);

                              } else {

                                  MovieClip(currentLoader.content).gotoAndStop(frameNum-partialTotalFrames);

                              }

                             

                          }

                          function sliderUpdateF(e:Event):void{

                              var playedFrames:int = 0;

                              for(var i:int=0;i<Number(currentLoader.name);i++){

                                  playedFrames += frameA[i];

                              }

                              playedFrames += MovieClip(currentLoader.content).currentFrame;

                              play_slider.value = Math.round(100*playedFrames/swfTotalFrames);

                          }

                          function sliderParamsF():void{

                              swfTotalFrames = 0;

                              for(var i:int=0;i<swfA.length;i++){

                                  swfTotalFrames += MovieClip(tl["loader_"+i].content).totalFrames;

                              }

                          }

                          ///////////////// end  sliders //////////////////////////////////

                          ///////////////// start playpause restart ///////////////////////

                          playpause_mc.addEventListener(MouseEvent.CLICK,playpauseF);

                          playpause_mc.alpha = .2;

                          restart_mc.addEventListener(MouseEvent.CLICK,restartF);

                          restart_mc.buttonMode = false;

                          restart_mc.alpha = .2;

                           

                          function playpauseF(e:MouseEvent):void{

                              if(!e.currentTarget.toggle){

                                  MovieClip(currentLoader.content).stop();

                                  tl.removeEventListener(Event.ENTER_FRAME,playUpdateF);

                                  e.currentTarget.gotoAndStop(2);

                              } else {

                                  MovieClip(currentLoader.content).play();

                                  tl.addEventListener(Event.ENTER_FRAME,playUpdateF);

                                  e.currentTarget.gotoAndStop(1);

                              }

                              e.currentTarget.toggle = !e.currentTarget.toggle;

                          }

                          ///////////////// end playpause //////////////////////////////

                           

                          function playUpdateF(e:Event):void{

                              sliderUpdateF(e);

                              var playingFrame:int = MovieClip(currentLoader.content).currentFrame;

                              if(playingFrame==frameA[Number(currentLoader.name)]){

                                  // next loader

                                  MovieClip(currentLoader.content).stop();

                                  SoundMixer.stopAll();

                                  MovieClip(currentLoader.content).mute();

                           

                                  var nextIndex:int = Number(currentLoader.name)+1;

                                  if(nextIndex<swfA.length){

                                      tl.removeChild(currentLoader);

                                      currentLoader = tl["loader_"+nextIndex];

                                      tl.addChild(currentLoader);

                                      MovieClip(currentLoader.content).gotoAndPlay(1);

                                  } else {

                                      tl.removeEventListener(Event.ENTER_FRAME,playUpdateF);

                                      playpause_mc.gotoAndStop(2);

                                      playpause_mc.toggle = !playpause_mc.toggle;

                                      //playpause_mc.alpha = .2;

                                      // all swfs have completed play

                                  }

                              }

                          }

                           

                          function restartF(e:MouseEvent):void{

                              MovieClip(currentLoader.content).stop();

                              tl.removeChild(currentLoader);

                              SoundMixer.stopAll();

                              MovieClip(currentLoader.content).mute();

                           

                              currentLoader = tl["loader_"+0];

                              tl.addChild(currentLoader);

                              if(playpause_mc.currentFrame==1){

                                  MovieClip(currentLoader.content).gotoAndPlay(1);

                              } else {

                                  MovieClip(currentLoader.content).gotoAndStop(1);

                              }

                          }

                          • 10. Re: How can I stop timeline sounds in external swf files from playing during loading?
                            mlouisem Community Member

                            i think i have all of that code already (see above)

                            my swfs completely load before playing but the sound starts during loading

                             

                            i have 70 separate sounds on the timeline

                            i do not currently have a stop() action in the first frame of them

                             

                            any help would be greatly appreciated

                            thanks very much

                            • 11. Re: How can I stop timeline sounds in external swf files from playing during loading?
                              iFlashAppsToo Community Member

                              explain the setup of the sounds on the timeline of the external swf.

                               

                              i gave 3 possible scenarios. could it be one of those? or something different?

                               

                              dont forget, while the swf is loading, it is playing... you dont tell it to gotoAndStop(1) until it completes loading... do you hear the sounds start from the beginning twice?

                              • 12. Re: How can I stop timeline sounds in external swf files from playing during loading?
                                mlouisem Community Member

                                i imported the sounds to the library and dragged each one to the stage where it is needed it in the timeline...they are all on the same layer...i created a keyframe for each one...i did not name them other than the file name they already had... i don't know if that makes them movie clips or not...please excuse my ignorance...i have not added any code to them.

                                 

                                each sound plays once while loading...part way through loading I start to hear the sounds from the second swf...when the swfs are both loaded i hear the sounds again with the animation.

                                • 13. Re: How can I stop timeline sounds in external swf files from playing during loading?
                                  iFlashAppsToo Community Member

                                  sounds like your loading swf is not stopped.

                                   

                                  please try adding this. basically, it's telling the loading swf to gotAndStop(1) as soon as it enters it's first frame, whether it's finished loading or not:

                                   

                                  function loadNextF():void{

                                                  tl["loader_"+index] = new Loader();

                                                  tl["loader_"+index].name = index.toString();

                                                  tl["loader_"+index].contentLoaderInfo.addEventListener(ProgressEvent. PROGRESS,progressF);

                                                  tl["loader_"+index].contentLoaderInfo.addEventListener(Event.COMPLETE ,completeF);

                                                 tl["loader_"+index].contentLoaderInfo.addEventListener(Event.INIT, initF);                                    

                                                  tl["loader_"+index].load(new URLRequest(swfA[index]));

                                  }

                                   

                                  function initF(e:Event):void{

                                                  SoundMixer.stopAll();

                                                  var mc:MovieClip = MovieClip(tl["loader_"+index].content);

                                                  mc.gotoAndStop(1);

                                  }

                                   

                                   

                                  //---

                                   

                                  another thing you can do simply is try putting a stop() in the first frame of the loading swf (on a separate layer, of course)

                                  • 14. Re: How can I stop timeline sounds in external swf files from playing during loading?
                                    Rothrock Community Member

                                    Didn't read the whole thread, but are your sounds set to streaming or are they event?

                                    • 16. Re: How can I stop timeline sounds in external swf files from playing during loading?
                                      mlouisem Community Member

                                      thank you SO much! the code you provided above worked perfectly!