4 Replies Latest reply on Jul 15, 2012 9:33 PM by kglad

    Game pauses upon playing a sound

    ZXZ1661

      I have a class in my flash project called "Resource" which I have designated to contain all the external files outside the flash documnent. When I play a sonud from this class, it seems that my program pauses until the sound is fully loaded, and then every time it plays after that it doesn't lag at all. Would there be a way to load the sound at a different time, i.e. at the beginning of the program, rather than on the fly? Here is the code for Resource.as and how I play the sound.

       

      Class "Resource" (I cut out unimportant stuff)

      [code]

      package  {

         

          public final class Resource

          {

              [Embed (source="/Resources/Sound.mp3" )]

              public static const Sound:Class;

              public function Resource()

              {

              }

       

          }

         

      }

      [/code]

       

      And this is how I call the sound and play it:
      [code]


      private var soundCoin:Sound = new Sound();


      public function User() {



      soundCoin = new Resource.Sound;












      }

      [/code]

      And, obviously, I play the sound using soundCoin.play();

       

      I might just not have the right setup, because I sort of improvised what I was doing. If this method is inefficient, I would love for people to give suggestions.

       

      Thanks

        • 1. Re: Game pauses upon playing a sound
          kglad Adobe Community Professional & MVP

          use:

           

           


          private var soundCoin:Sound = new Resource.Sound();


          public function User() {















          }

           

          • 2. Re: Game pauses upon playing a sound
            Amy Blankenship Level 4

            How are you using this or even getting this to happen? My experience is that any Symbol that references a Sound where you don't check "Embed on Frame N" (where n is the default embedding frame in your Publish settings) will give the error "Not a valid sound."  Sorry, I don't have the specific error number, as I have that box checked whenever I need an embedded sound .

             

            The only way I can think that this could possibly happen is if your Symbol that references the Class is before the frame specified in your publish settings (or is the Main document Class). But my experience is that Classes that load before the N frame will embed everything they need on that frame regardless of settings.

             

            Can you provide more details on what you did? Honestly, I'd love to be able to do on purpose what you did by accident. Having sounds that don't play immediately would be a small price to pay to have more flexibility about where the definition is embedded for the project I'm working on.

             

            In case it wasn't clear from the above, I thought I'd restate: what you are seeing shouldn't be happening. The file should be compiled on whatever frame is the default compile frame in your swf, and should play immediately when you call play. That it doesn't says that somehow you've stumbled into an edge case.

             

            FWIW, I find that using the Embed metadata as you have with Flash Pro is extremely unreliable--often part of the sound will not get compiled into the swf, so the sound will cut off early. You will probably find yourself switching to making a swc from embedded library sounds in the end because of this problem (which is what I'm doing).

            -----------------------------------------------

            Update:

            I just recreated the error you should be seeing with that box unchecked:

            ArgumentError: Error #2068: Invalid sound.

            at flash.media::Sound/play()

             

            You can do a web search for more information on this issue.

            • 3. Re: Game pauses upon playing a sound
              ZXZ1661 Level 1

              Thank you, kglad. This seemed to cut down on the delay, but there is still a pause the first time the sound plays. As before, after the first time it plays fine.

              • 4. Re: Game pauses upon playing a sound
                kglad Adobe Community Professional & MVP

                then you should start playing your sound immediately (with zero volume) so it's preloaded.

                1 person found this helpful