8 Replies Latest reply on Nov 16, 2007 9:49 AM by abeall

    How does one go about making a preloader for sound

    Boxing Boom Level 1
      Hi,

      Need a little help from my friends ;)

      How would one go about creating a preloader for sound? Any examples would be highly appreciated. I done a search here on the forums, but nothing meaningful showed up, this surprised me.

      So let all those interested in a bit of hard work, create a few preloaders for sound. Come on, who's up for it? Let us make the Worlds best designed preloaders for sound, ever. ;)

      Kind Regards,

      Boxing Boom ;)
        • 1. Re: How does one go about making a preloader for sound
          Boxing Boom Level 1
          Hi All,

          Still awaiting response.

          Kind Regards,

          Boxing Boom
          • 2. Re: How does one go about making a preloader for sound
            abeall Level 3
            I'm not going to make a preloader for you, but I will say that it is different than making a preloader for a movie.

            It also depends on what version of AS you are using, and how you are loading the sound.
            • 3. Re: How does one go about making a preloader for sound
              Boxing Boom Level 1
              Hi,

              ActionScript 2.0 would be used, within Flash cs3. Any help would really be appreciated.

              Kind Regards,

              Boxing Boom
              • 4. Re: How does one go about making a preloader for sound
                robdillon Most Valuable Participant
                Look in the built in help for the description of getBytesLoaded(). There is a pretty good example of loading an external sound and monitoring its download.
                • 5. Re: How does one go about making a preloader for sound
                  Boxing Boom Level 1
                  Hi Rob,

                  Thank you, your a star!

                  However, I did assume you might build me one ;)

                  Kind Regards,

                  Boxing Boom
                  • 6. Re: How does one go about making a preloader for sound
                    Boxing Boom Level 1
                    Hi All,

                    Yes Rob, very nice example ;)

                    getBytesLoaded (Sound.getBytesLoaded method)
                    public getBytesLoaded() : Number

                    Returns the number of bytes loaded (streamed) for the specified Sound object. You can compare the value of getBytesLoaded() with the value of getBytesTotal() to determine what percentage of a sound has loaded.

                    Availability: ActionScript 1.0; Flash Player 6

                    Returns
                    Number - An integer indicating the number of bytes loaded.

                    Example
                    The following example dynamically creates two text fields that display the bytes that are loaded and the total number of bytes for a sound file that loads into the SWF file. A text field also displays a message when the file finishes loading. Add the following ActionScript to your FLA or AS file:

                    this.createTextField("message_txt", this.getNextHighestDepth(), 10,10,300,22)
                    this.createTextField("status_txt", this.getNextHighestDepth(), 10, 50, 300, 40);
                    status_txt.autoSize = true;
                    status_txt.multiline = true;
                    status_txt.border = false;

                    var my_sound:Sound = new Sound();
                    my_sound.onLoad = function(success:Boolean) {
                    if (success) {
                    this.start();
                    message_txt.text = "Finished loading";
                    }
                    };
                    my_sound.onSoundComplete = function() {
                    message_txt.text = "Clearing interval";
                    clearInterval(my_interval);
                    };
                    my_sound.loadSound("song2.mp3", true);
                    var my_interval:Number;
                    my_interval = setInterval(checkProgress, 100, my_sound);
                    function checkProgress(the_sound:Sound):Void {
                    var pct:Number = Math.round(the_sound.getBytesLoaded()/the_sound.getBytesTotal()*100);
                    var pos:Number = Math.round(the_sound.position/the_sound.duration*100);
                    status_txt.text = the_sound.getBytesLoaded()+" of "+the_sound.getBytesTotal()+" bytes ("+pct+"%)"+newline;
                    status_txt.text += the_sound.position+" of "+the_sound.duration+" milliseconds ("+pos+"%)"+newline;
                    }


                    The MovieClip.getNextHighestDepth() method used in this example requires Flash Player 7 or later. If your SWF file includes a version 2 component, use the version 2 components' DepthManager class instead of the MovieClip.getNextHighestDepth() method.

                    Kind Regards,

                    Boxing Boom

                    • 7. Re: How does one go about making a preloader for sound
                      Boxing Boom Level 1
                      Hi All,

                      Can anyone tell me how to change the above script to produce seconds and not miliseconds?

                      I ideally would like the following to be displayed:

                      Bytes Loaded 100%
                      Playing 4 sec. of 25 sec. (88%)

                      At present it is producing:

                      228298 of 228298 bytes (100%)
                      14211 of 14263 milliseconds (100%)

                      Would someone please show me how the above is acheived, I am desperate to know this ASAP ;)

                      Kind Regards,

                      Boxing Boom - forever jumping in a the deep end ;()
                      • 8. How does one go about making a preloader for sound
                        abeall Level 3
                        Multiply Sound.duration and Sound.position by 1000, and you have seconds:

                        the_sound.position * 1000