24 Replies Latest reply on Mar 15, 2007 10:35 AM by kglad

    Audio Cookie

    xxaimsxx
      Hello All-

      I am in dire need of help! I'm working on this flash design that has a total of 4 voice overs in it. So every single time you get to the homepage, the VO plays once but it gets very irritating after while especially if someone was to go onto that page multiple times. So I wanted to do something like what this person did: http://www.ursart.com/html/flashAudioCookies.php

      Basically, if you press mute/stop and if you ever go back to that page or refresh it, the state stays the same until you press play again.

      However, my dilemma is that this particular tutorial uses only 1 sound/music that is looping and my project has 4 sounds/voice overs that is only to be repeated once each time it loads.

      Can anyone help me with this?

      I have tried looking it up online for the past 3 days and have found no luck. And I'm not so great in action scripting.
        • 1. Re: Audio Cookie
          Level 7
          Shared Objects is what you want. I created a sample here that you could use
          similar logic to tell the audio to mute.
          http://www.smithmediafusion.com/blog/?p=212


          --

          Dan Mode
          --> Adobe Community Expert
          *Flash Helps* http://www.smithmediafusion.com/blog/?cat=11
          *THE online Radio* http://www.tornadostream.com <--check this

          *Must Read* http://www.smithmediafusion.com/blog


          "xxaimsxx" <webforumsuser@macromedia.com> wrote in message
          news:ess86k$jg8$1@forums.macromedia.com...
          > Hello All-
          >
          > How are you guys doing? I've been using Kirupa.com as a reference for some
          > of
          > my work and finally have joined the forum cause I've been lazy!
          >
          > I am in dire need of help! I'm working on this flash design that has a
          > total
          > of 4 voice overs in it. So every single time you get to the homepage, the
          > VO
          > plays once but it gets very irritating after while especially if someone
          > was to
          > go onto that page multiple times. So I wanted to do something like what
          > this
          > person did: http://www.ursart.com/html/flashAudioCookies.php
          >
          > Basically, if you press mute/stop and if you ever go back to that page or
          > refresh it, the state stays the same until you press play again.
          >
          > However, my dilemma is that this particular tutorial uses only 1
          > sound/music
          > that is looping and my project has 4 sounds/voice overs that is only to be
          > repeated once each time it loads.
          >
          > Can anyone help me with this?
          >
          > I have tried looking it up online for the past 3 days and have found no
          > luck.
          > And I'm not so great in action scripting.
          >


          • 2. Re: Audio Cookie
            xxaimsxx Level 1
            Hello-

            So does that mean for each audio file, I have to create a Shared Object?

            Like I got this to work but with only 1 audio file, however I have 4 voiceover total that plays on different frame after one another.

            Like if you go to http://www.mandalaybay.com they have voice overs.
            • 3. Re: Audio Cookie
              kglad Adobe Community Professional & MVP
              no, one sharedobject can store many variables/values.
              • 4. Re: Audio Cookie
                xxaimsxx Level 1
                can someone give me an example of how do this?

                quote:

                Originally posted by: kglad
                no, one sharedobject can store many variables/values.


                • 5. Re: Audio Cookie
                  kglad Adobe Community Professional & MVP
                  :

                  • 6. Re: Audio Cookie
                    xxaimsxx Level 1
                    Hello-

                    Please forgive me if I get annoying. I don't really know how to program in Flash at all.

                    But this is what I have below:

                    // attach the sound
                    voiceOver_1 = new Sound(this);
                    voiceOver_1.attachSound('voiceOver_1');

                    // define the audio cookie (or create it if it's not there)
                    audio_data = SharedObject.getLocal("user_data");

                    //check the audio cookie for previous settings
                    lastVisitDate = audio_data.data.visitDate;
                    storedAudioSetting = audio_data.data.audioChoice;
                    storedAudioPoint = audio_data.data.audioPoint;

                    if ( lastVisitDate == undefined) lastVisitDate = 0;
                    if ( storedAudioSetting == undefined) storedAudioSetting = true;
                    if ( storedAudioPoint == undefined) storedAudioPoint = 0;

                    //see how it's been since their last visit (172800000 msec = 2 days)
                    todaysDate = new Date();
                    timeLapsed = todaysDate.getTime() - lastVisitDate;
                    if (timeLapsed > 172800000){
                    storedAudioSetting = true;
                    storedAudioPoint = 0;
                    }

                    //determine sound and button state based on shared object vars
                    if ( storedAudioSetting != false){
                    voiceOver_1.start(storedAudioPoint, 999);
                    audioOnButton.gotoAndStop("bold");
                    audioOffButton.gotoAndStop("dim");
                    _root.audioOn = true;
                    } else {
                    audioOnButton.gotoAndStop("dim");
                    audioOffButton.gotoAndStop("bold");
                    _root.audioOn = false;
                    this.stop();
                    }

                    This functions like how I want it, however, I want to know how to attach 3 additional sounds that can play after one another.

                    quote:

                    Originally posted by: kglad
                    :




                    • 7. Re: Audio Cookie
                      kglad Adobe Community Professional & MVP
                      are you using the sound object or are your sounds attached to a timeline's frame?
                      • 8. Re: Audio Cookie
                        xxaimsxx Level 1
                        Well right now I'm using the sound object, however, the actual audio are embedded into the timeline. That's what's confusing me.
                        • 9. Re: Audio Cookie
                          xxaimsxx Level 1
                          Does it make a big difference if my audio is attached to the timeline versus just it being in the library?
                          • 10. Re: Audio Cookie
                            kglad Adobe Community Professional & MVP
                            you have very limited control over sounds that are attached to a frame. sounds that are instantiated using the sound class are much more controllable.

                            for sounds attached to a movieclip frame: you can't use the sound class to control those sounds. all you can do is use stopAllSounds() and the goto methods to control which frames of the movieclip play.
                            • 11. Re: Audio Cookie
                              xxaimsxx Level 1
                              so then there's no way to do a cookie where if they hit off and each time the page is reloaded, the flash sound stays off? this is so confusing.
                              • 12. Re: Audio Cookie
                                xxaimsxx Level 1
                                Okay, so this is what I'm doing now but it still won't work as far as getting it to be in the same state if I pressed "off" and reloaded the page.

                                // define the audio cookie (or create it if it's not there)
                                audio_data = SharedObject.getLocal("myuser_data");

                                //check the audio cookie for previous settings
                                storedAudioSetting = audio_data.data.isPlaying;

                                if ( storedAudioSetting == undefined) storedAudioSetting = true;

                                // If querystring passed in, turn sound button off.
                                if (music == "off") {
                                mySound = new Sound();
                                mySound.setVolume(0);
                                if (sound_btn.isPlaying == true) {
                                sound_btn.onPress();
                                }
                                }

                                init();
                                function init() {
                                if (this.inited == undefined) {
                                this.inited = true;
                                this.isPlaying = true;
                                }
                                }
                                //this.onRollOver = function() {
                                // if (this.isPlaying) {
                                // this.gotoAndStop("Over");
                                // } else {
                                // this.gotoAndStop("On");
                                // }
                                //};

                                this.onRollOut = function() {
                                if (this.isPlaying) {
                                this.gotoAndStop("On");
                                } else {
                                this.gotoAndStop("Off");
                                }
                                };
                                this.onPress = function() {
                                if (this.isPlaying) {
                                this.isPlaying = false;
                                this.gotoAndStop("Off");
                                this.isPlaying = false;
                                // set volume to 0
                                loop = new Sound();
                                volume = 0;
                                loop.setVolume(volume);

                                //cookie stuff
                                _parent.audio_data.data.isPlaying = false;
                                _parent.audio_data.flush();


                                } else {
                                this.isPlaying = true;
                                this.gotoAndStop("On");
                                // set volume to 100
                                loop = new Sound();
                                volume = 100;
                                loop.setVolume(volume);

                                //cookie stuff
                                _parent.audio_data.data.isPlaying = true;
                                _parent.audio_data.flush();
                                }
                                };

                                quote:

                                Originally posted by: kglad
                                you have very limited control over sounds that are attached to a frame. sounds that are instantiated using the sound class are much more controllable.

                                for sounds attached to a movieclip frame: you can't use the sound class to control those sounds. all you can do is use stopAllSounds() and the goto methods to control which frames of the movieclip play.


                                • 13. Re: Audio Cookie
                                  xxaimsxx Level 1
                                  Okay, so this is what I'm doing now but it still won't work as far as getting it to be in the same state if I pressed "off" and reloaded the page.

                                  // define the audio cookie (or create it if it's not there)
                                  audio_data = SharedObject.getLocal("myuser_data");

                                  //check the audio cookie for previous settings
                                  storedAudioSetting = audio_data.data.isPlaying;

                                  if ( storedAudioSetting == undefined) storedAudioSetting = true;

                                  // If querystring passed in, turn sound button off.
                                  if (music == "off") {
                                  mySound = new Sound();
                                  mySound.setVolume(0);
                                  if (sound_btn.isPlaying == true) {
                                  sound_btn.onPress();
                                  }
                                  }

                                  init();
                                  function init() {
                                  if (this.inited == undefined) {
                                  this.inited = true;
                                  this.isPlaying = true;
                                  }
                                  }
                                  //this.onRollOver = function() {
                                  // if (this.isPlaying) {
                                  // this.gotoAndStop("Over");
                                  // } else {
                                  // this.gotoAndStop("On");
                                  // }
                                  //};

                                  this.onRollOut = function() {
                                  if (this.isPlaying) {
                                  this.gotoAndStop("On");
                                  } else {
                                  this.gotoAndStop("Off");
                                  }
                                  };
                                  this.onPress = function() {
                                  if (this.isPlaying) {
                                  this.isPlaying = false;
                                  this.gotoAndStop("Off");
                                  this.isPlaying = false;
                                  // set volume to 0
                                  loop = new Sound();
                                  volume = 0;
                                  loop.setVolume(volume);

                                  //cookie stuff
                                  _parent.audio_data.data.isPlaying = false;
                                  _parent.audio_data.flush();


                                  } else {
                                  this.isPlaying = true;
                                  this.gotoAndStop("On");
                                  // set volume to 100
                                  loop = new Sound();
                                  volume = 100;
                                  loop.setVolume(volume);

                                  //cookie stuff
                                  _parent.audio_data.data.isPlaying = true;
                                  _parent.audio_data.flush();
                                  }
                                  };

                                  quote:

                                  Originally posted by: kglad
                                  you have very limited control over sounds that are attached to a frame. sounds that are instantiated using the sound class are much more controllable.

                                  for sounds attached to a movieclip frame: you can't use the sound class to control those sounds. all you can do is use stopAllSounds() and the goto methods to control which frames of the movieclip play.


                                  • 14. Re: Audio Cookie
                                    kglad Adobe Community Professional & MVP
                                    what starts your sound playing? is it attached to a frame?
                                    • 15. Re: Audio Cookie
                                      xxaimsxx Level 1
                                      yes it's attached to the timeline.

                                      someone said that "if u want to remember a user's choices w/regards to the embedded sounds u can store those choices in a shared object that you check each time that user revisits the app" so I'm trrying to do something like that but is not working.
                                      • 16. Re: Audio Cookie
                                        kglad Adobe Community Professional & MVP
                                        well, you can store any variable/value in the sharedobject to be retrieved when a user returns to your swf. but that may not be the main issue.

                                        how are you trying to control that sound? you can't use the sound class. as i mentioned above, you can use stopAllSounds() and you can control the movieclip's timeline using the goto methods.

                                        so, if a user wants to stop the voice overs how have you coded that? and does that work?
                                        • 17. Re: Audio Cookie
                                          xxaimsxx Level 1
                                          Well originally the way it is right now, it's just a stopAllSound Method. And it does work if I toggle it on and off.
                                          • 18. Re: Audio Cookie
                                            kglad Adobe Community Professional & MVP
                                            that stops any current sounds from playing but doesn't stop ones that are about to play. what do you do to stop those?
                                            • 19. Re: Audio Cookie
                                              xxaimsxx Level 1
                                              okies, currently right now it's attaching the sound "afewgoodmen.wav".

                                              what would i have to do in order to change that if my sound was embedded into the timeline itself?

                                              // attach the sound
                                              bgTune = new Sound(this);
                                              bgTune.attachSound("aFewGoodMen.wav");

                                              // define the audio cookie (or create it if it's not there)
                                              audio_data = SharedObject.getLocal("myuser_data");

                                              //check the audio cookie for previous settings
                                              lastVisitDate = audio_data.data.visitDate;
                                              storedAudioSetting = audio_data.data.audioChoice;
                                              storedAudioPoint = audio_data.data.audioPoint;

                                              if ( lastVisitDate == undefined) lastVisitDate = 0;
                                              if ( storedAudioSetting == undefined) storedAudioSetting = true;
                                              if ( storedAudioPoint == undefined) storedAudioPoint = 0;

                                              //see how it's been since their last visit (172800000 msec = 2 days)
                                              todaysDate = new Date();
                                              timeLapsed = todaysDate.getTime() - lastVisitDate;
                                              if (timeLapsed > 172800000){
                                              storedAudioSetting = true;
                                              storedAudioPoint = 0;
                                              }

                                              //determine sound and button state based on shared object vars
                                              if ( storedAudioSetting != false){
                                              bgTune.start(storedAudioPoint, 999);
                                              audioOnButton.gotoAndStop("bold");
                                              audioOffButton.gotoAndStop("normal");
                                              _root.audioOn = true;
                                              } else {
                                              audioOnButton.gotoAndStop("normal");
                                              audioOffButton.gotoAndStop("bold");
                                              _root.audioOn = false;
                                              this.stop();
                                              }
                                              • 20. Re: Audio Cookie
                                                kglad Adobe Community Professional & MVP
                                                if the sound is currently attached using actionscript (as you showed above), leave it alone. that's preferrable to attaching it to a frame.

                                                i thought the sound was attached to a frame in the authoring environment. is the sound attached using the code you showed?
                                                • 21. Re: Audio Cookie
                                                  xxaimsxx Level 1
                                                  yes the sound is attached the frame itself. however the code above is what i got off of this one site. I want it to function just the way it is only using sound that is attached to the frame. i don't know how to change that part.
                                                  • 22. Re: Audio Cookie
                                                    kglad Adobe Community Professional & MVP
                                                    ok. can you edit the file that contains the sound? ie, you can see the sound file(s) in a swf library?
                                                    • 23. Re: Audio Cookie
                                                      xxaimsxx Level 1
                                                      figured it out:

                                                      _global.gboolSound = true;

                                                      // GLOBAL SOUND OBJECT
                                                      var globalSound:Sound = new Sound();

                                                      // SHARED OBJECT
                                                      var audioSO:SharedObject = SharedObject.getLocal("audioVolume");

                                                      // CHECK TO SEE IF AUDIO SETTING EXISTS, IF IT DOES, RESET VOLUME BACK
                                                      if (audioSO.data.audioSetting != undefined) {
                                                      globalSound.setVolume(audioSO.data.audioSetting);
                                                      }

                                                      // TOGGLE SWITCH
                                                      btn_audio.onRelease = function() {
                                                      if (gboolSound){
                                                      // displays the mute icon
                                                      this.gotoAndStop(2);
                                                      // see if gboolSound true/false
                                                      gboolSound = false;
                                                      // set global volume
                                                      globalSound.setVolume(0);
                                                      // update audioSetting property
                                                      audioSO.data.audioSetting = 0;
                                                      // flush the data to the shared object
                                                      audioSO.flush();
                                                      }

                                                      else {
                                                      // displays the mute icon
                                                      this.gotoAndStop(1);
                                                      // see if gboolSound true/false
                                                      gboolSound = true;
                                                      // set global volume
                                                      globalSound.setVolume(100);
                                                      // update audioSetting property
                                                      audioSO.data.audioSetting = 100;
                                                      // flush the data to the shared object
                                                      audioSO.flush();
                                                      }
                                                      }

                                                      just some minor problems with the on/off toggle that i have to fix
                                                      • 24. Re: Audio Cookie
                                                        kglad Adobe Community Professional & MVP
                                                        good. congrats!