5 Replies Latest reply on Aug 20, 2007 2:32 PM by jl2000

    To loadSound or attachSound

    jl2000 Level 1
      Hi - Could someone please explain the difference/advantages for loadSound and attachSound. What's the "best practise" on when to use which?

      I've been trolling around and found 2 ways to get a sound to play onRelease. I don't see a difference.

      Thanks fr your expert input.

      JL
        • 1. Re: To loadSound or attachSound
          kglad Adobe Community Professional & MVP
          attachSound is used for sounds that are already in your swf's library. they add to the loading time of your swf. they can be played immediately.

          loadSound is used for sounds that are external to your swf. they do not add to the loading time of your swf, but they take time to load (after loadSound is executed) and are not usually used for sounds that need to play instantly. (though they can be preloaded and played immediately.)
          • 2. Re: To loadSound or attachSound
            Level 7
            jlucchesi,

            > Hi - Could someone please explain the difference/advantages
            > for loadSound and attachSound. What's the "best practise" on
            > when to use which?

            The main difference, really, is that Sound.loadSound() pulls external
            MP3 files from outside the SWF. That means you can keep the SWF's file size
            much lower than when you include audio files directly in your the Library.
            On the other hand, Sound.attachSound() requires that audio files (not just
            MP3s) appear in the Library, so they can be attached at runtime.

            When to use what depends on your needs. Small (short) sounds can be
            added to the Library without too much extra weight. Those will load
            instantly, because they're already in the SWF. You might use something like
            that for user interface sounds, like mouse clicks. If you have a slideshow
            or some other presentation that has optional background music or spoken
            narrative, it would be better to keep that audio external to the SWF,
            because if the user chooses not to listen to it, the user won't have to
            spend the time downloading it.


            David Stiller
            Co-author, Foundation Flash CS3 for Designers
            http://tinyurl.com/2k29mj
            "Luck is the residue of good design."


            • 3. Re: To loadSound or attachSound
              jl2000 Level 1
              kglad and David, Thank you both. Can I mark 2 as being the answer? Interesting side occurance/question. I set up 2 btns on the stage using the same sound - a very short whoosh (actually copies of the same sound). I know now that one btn is "attaching" the sound from the Library while the other is "loading" it from the relative folder in the FInder.

              Here's the thing - they sound different. The attached sound is the same as if I play it in the Finder. The loaded sound is a higher pitch (indicating the playback is faster, I assume). If anything I would think the loaded sound would be slower because of the extra work of bringing it in from the outside.

              Any thoughts?
              Thanks again for squaring me on these two phrases.

              JL
              • 4. Re: To loadSound or attachSound
                Level 7
                JL,

                > I set up 2 btns on the stage using the same sound - a very short
                > whoosh (actually copies of the same sound). I know now that
                > one btn is "attaching" the sound from the Library while the other
                > is "loading" it from the relative folder in the FInder.

                Okay.

                > Here's the thing - they sound different.

                Attached sounds will be regulated by your global sound settings (see
                File > Publish Settings > Flash tab, Audio stream and Audio event buttons)
                or individually on the sound assets themselves (right-click / Command-click
                each asset and choose Properties). Loaded sounds sound like whatever they
                sound.

                You'll need to pay attention to your sample rates to avoid
                speed-of-playback glitches (search "Importing sounds" in the Help panel).

                You're using ActionScript 2.0, so you may also want to check out these
                brief articles on the Sound class in general:

                http://www.quip.net/blog/2006/flash/actionscript-20/understanding-the-sound-constructor/
                http://www.quip.net/blog/2006/flash/how-to-toggle-sound-globally/
                http://www.quip.net/blog/2006/flash/how-to-pause-sound-and-resume/


                David Stiller
                Co-author, Foundation Flash CS3 for Designers
                http://tinyurl.com/2k29mj
                "Luck is the residue of good design."


                • 5. Re: To loadSound or attachSound
                  jl2000 Level 1
                  Thanks Dave - That'll keep me busy.
                  Best regards,
                  JL