6 Replies Latest reply on Aug 23, 2006 8:10 AM by abeall

    Play sound once with shared object

    windsor
      I need a little help. I have a sound loop that plays once when my home page is loaded but when you leave the home page and then return it plays again. I only want it to play once even if the page is refreshed. Can you do this using SharedObjects?
      Is there a way of controlling it so that it wont play for a set amount of time. How can I make the code below do this?

      b = new Sound();
      b.attachSound("back dub");
      b.start(0,1);

      Any help on this would be greatly appreciated


      cheers

        • 1. Re: Play sound once with shared object
          abeall Level 3
          SharedObject is used to create data that will persist for a user even if they close the session and come back. In other words, that would be useful if you wanted the Sound to play on the first time the user *ever* visited your website, but never again even if they leave your site and come back a week later. Sounds like you just want it to play once 'per session', correct?

          Try checking to see if the Sound has not been created yet, only if that's true then play the Sound. Like this:
          if(!b){
          b = new Sound();
          b.attachSound("back dub");
          b.start(0,1);
          }
          • 2. Re: Play sound once with shared object
            WebXperience Level 1
            you could place the code in a function that runs when the page is loaded.
            Then within an movieClip.onLoadComplete fuction you could stop the Sound.. Or stop the sound while loading the next page.
            • 3. Re: Play sound once with shared object
              windsor Level 1
              Actually thats what i had in mind to only play once and never again. Your idea of playing once per session is a close second but the code didnt work . The whole home page isnt flash its just apart of the top banner does that make a difference?
              • 4. Re: Play sound once with shared object
                WebXperience Level 1
                Are you calling the sound from the html page or are you loading it in the flash banner ad?
                • 5. Re: Play sound once with shared object
                  abeall Level 3
                  > The whole home page isnt flash its just apart of the top banner does that make a
                  > difference?
                  Ah, that's a big difference. This means the Flash session is closed when you change pages, so it's not any help. Yes, SharedObject would be a perfect solution for this.

                  > Are you calling the sound from the html page or are you loading it in the flash
                  > banner ad?
                  Refer to the first post, he's using the Sound object in Flash.

                  windsor, try this:
                  var so = SharedObject.getLocal("myIntro");
                  if(!so.data.hasPlayed){
                  b = new Sound();
                  b.attachSound("back dub");
                  b.start(0,1);
                  so.data.hasPlayed = true; //this data will be written when the user closes the Flash session
                  }
                  • 6. Re: Play sound once with shared object
                    abeall Level 3
                    This doesn't seem to affect you in this case, but one thing to note about the SharedObject is that even if you explicitly flush() the data( so.data.flush() ), which writes the data immediantly to the user's machine, it won't be re-readable by any other Flash on the page untill it reloads.

                    In other words, it's not possible to communicate between SWFs on a page with a SO, you must use LocalConnection to do that, or force the page to refresh.