9 Replies Latest reply on May 28, 2011 9:35 PM by kglad

    How to fade out preloader music as loading completes

    kayjs

      I have an external preloader that plays music while the main swf is loading. Everything works fine but it sounds a little abrupt when the music just stops as soon as the swf is loaded. Is there a way to start fading out the music when the progress bar gets to, say, 80%, so that by the time the main swf opens, the music is completely faded out?

        • 1. Re: How to fade out preloader music as loading completes
          kglad Adobe Community Professional & MVP

          yes.  show your preloader code.

          • 2. Re: How to fade out preloader music as loading completes
            kayjs Level 1

            Thanks, kglad. Here's the code:

             

             

            ACTIONS LAYER, FRAME 1:

             

            this.createEmptyMovieClip("container_mc", "100");

             

            my_mc = new MovieClipLoader();

             

            preload = new Object();

            my_mc.addListener(preload);

            preload.onLoadStart = function(targetMC) {

                            container_mc._visible = false;

                            loadingBar._visible = true;

                            loadingBorder._visible = true;

                            loadingText._visible = false;

                            loadingTitleScreen._visible = true;

                            loadingLessonName._visible = true;

            };

             

            preload.onLoadComplete = function(targetMC) {

                            container_mc._visible = true;

                            loadingBorder._visible = false;

                            loadingBar._visible = false;

                            loadingText._visible = false;

                            loadingTitleScreen._visible = false;

                            loadingLessonName._visible = false;

                            gotoAndStop(4);

            };

             

            my_mc.loadClip("lesson.swf", "container_mc");

             

            ACTIONS LAYER, FRAME 2:

             

            loadingBar._width = (container_mc.getBytesLoaded()/container_mc.getBytesTotal()) * 576.0;

            loadingText.text = "Loading " + Math.round(container_mc.getBytesLoaded() / 1024) + " K of "+ Math.round(container_mc.getBytesTotal() / 1024) + " K";

             

            ACTIONS LAYER, FRAME 3:

             

            gotoAndPlay(2);

             

            NOTE:

            You’ll notice that the sound file isn’t called in this code. Here’s how the sound plays: “TitleScreen” is a movie clip that contains another movie clip, “Notes_mc”, which is the animation that plays as the main swf loads. The sound file that I want to fade out (identifier is “BachPrelude”) is on the Sound layer of Notes_mc so the animation could be synched to the audio. If the sound file has to be called from the code on frame 1 in order to fade it out, that’s fine. I can remove the sound from Notes_mc and call it in the frame 1 code.

            • 3. Re: How to fade out preloader music as loading completes
              kglad Adobe Community Professional & MVP

              is TitleScreen on frames  1,2 and 3?

              • 4. Re: How to fade out preloader music as loading completes
                kayjs Level 1

                Yes. It's on all four frames of the preloader.

                • 5. Re: How to fade out preloader music as loading completes
                  kglad Adobe Community Professional & MVP
                  var alreadyExecuted:Boolean

                  if(!alreadyExecuted){
                  alreadyExecuted=true;
                  var s:Sound=new Sound(TitleScreen.Notes_mc);
                  }

                   

                  this.createEmptyMovieClip("container_mc", "100");

                   

                  my_mc = new MovieClipLoader();

                   

                  preload = new Object();

                  my_mc.addListener(preload);

                  preload.onLoadStart = function(targetMC) {

                                  container_mc._visible = false;

                                  loadingBar._visible = true;

                                  loadingBorder._visible = true;

                                  loadingText._visible = false;

                                  loadingTitleScreen._visible = true;

                                  loadingLessonName._visible = true;

                  };

                   

                  preload.onLoadComplete = function(targetMC) {

                                  container_mc._visible = true;

                                  loadingBorder._visible = false;

                                  loadingBar._visible = false;

                                  loadingText._visible = false;

                                  loadingTitleScreen._visible = false;

                                  loadingLessonName._visible = false;

                                  gotoAndStop(4);

                  };

                   

                  my_mc.loadClip("lesson.swf", "container_mc");

                   

                  ACTIONS LAYER, FRAME 2:

                   

                  loadingBar._width = (container_mc.getBytesLoaded()/container_mc.getBytesTotal()) * 576.0;

                  loadingText.text = "Loading " + Math.round(container_mc.getBytesLoaded() / 1024) + " K of "+ Math.round(container_mc.getBytesTotal() / 1024) + " K";

                   

                  s.setVolume(Math.round(100*container_mc.getBytesLoaded()/container_mc.getBytesTotal()));

                   

                  ACTIONS LAYER, FRAME 3:

                   

                  gotoAndPlay(2);

                   


                  1 person found this helpful
                  • 6. Re: How to fade out preloader music as loading completes
                    kayjs Level 1

                    Thanks, kglad. This is definitely the right approach. The new code is working as written (the music fades in) but it's not quite doing what I need it to do. The music should fade out, not fade in, and it should fade out only after a certain point.

                     

                    The new code you wrote for frame 2 sets the volume to 'bytes loaded' divided by 'total bytes'. The music starts at zero volume and increases in volume until the main swf is completely loaded, at which point the music stops playing.

                     

                    Instead, I would like the music to start out at full volume and play at full volume until the main swf is 80% loaded, then fade out. This gives the user an audio cue that the swf is almost loaded, in addition to the visual cue of the load bar reaching the end.

                     

                    I need to change the volume at the point when ('bytes loaded' divided by 'total bytes') = 80%, so that the music plays at full volume until the main swf is almost loaded.

                     

                    At that point I need to set the volume to ('total bytes' minus 'bytes loaded') divided by ('total bytes') - so that it fades out.

                     

                    If you're willing to provide the code for this, I would certainly appreciate the help.

                    • 7. Re: How to fade out preloader music as loading completes
                      kglad Adobe Community Professional & MVP

                      kglad wrote:

                       

                      var alreadyExecuted:Boolean

                      if(!alreadyExecuted){
                      alreadyExecuted=true;
                      var s:Sound=new Sound(TitleScreen.Notes_mc);
                      }

                       

                      this.createEmptyMovieClip("container_mc", "100");

                       

                      my_mc = new MovieClipLoader();

                       

                      preload = new Object();

                      my_mc.addListener(preload);

                      preload.onLoadStart = function(targetMC) {

                                      container_mc._visible = false;

                                      loadingBar._visible = true;

                                      loadingBorder._visible = true;

                                      loadingText._visible = false;

                                      loadingTitleScreen._visible = true;

                                      loadingLessonName._visible = true;

                      };

                       

                      preload.onLoadComplete = function(targetMC) {

                                      container_mc._visible = true;

                                      loadingBorder._visible = false;

                                      loadingBar._visible = false;

                                      loadingText._visible = false;

                                      loadingTitleScreen._visible = false;

                                      loadingLessonName._visible = false;

                                      gotoAndStop(4);

                      };

                       

                      my_mc.loadClip("lesson.swf", "container_mc");

                       

                      ACTIONS LAYER, FRAME 2:

                       

                      loadingBar._width = (container_mc.getBytesLoaded()/container_mc.getBytesTotal()) * 576.0;

                      loadingText.text = "Loading " + Math.round(container_mc.getBytesLoaded() / 1024) + " K of "+ Math.round(container_mc.getBytesTotal() / 1024) + " K";

                       

                      var vol:Number=Math.round(100*container_mc.getBytesLoaded()/container_mc. getBytesTotal())

                      if(vol>80){

                      s.setVolume(5*(100-vol));

                      }

                       

                       

                      ACTIONS LAYER, FRAME 3:

                       

                      gotoAndPlay(2);

                       


                      • 8. Re: How to fade out preloader music as loading completes
                        kayjs Level 1

                        Perfect! Thank you for the elegant solution.