10 Replies Latest reply on Sep 9, 2010 1:47 PM by Steve_Nixon_ADP

    Go to - when a sound is complete

    Steve_Nixon_ADP Level 1

      Sorry I know this is simple but I'm not much of a programmer. I want to call a sound and then have it trace when the sound is complete and go to a specific frame. Anyone got this?

       

      Best, Steve

        • 1. Re: Go to - when a sound is complete
          kglad Adobe Community Professional & MVP

          use:

           

           

          yoursound:Sound=new Sound(this);

          .

          .

          yoursound.onSoundComplete=function(){

          yourmc.gotoAndPlay("yourframelabel");

          }

          • 2. Re: Go to - when a sound is complete
            Steve_Nixon_ADP Level 1

            Thanks KGlad, I'll give it a go.

             

            best, Steve

            • 3. Re: Go to - when a sound is complete
              Steve_Nixon_ADP Level 1

              yoursound:Sound=new Sound(spider_b-xtereo_s-7449_hifi.mp3);
              yoursound.onSoundComplete=function(){
              yourmc.gotoAndPlay("marker2");
              }

               

              I'm getting an error when I tried this, any thoughts? Have I specified the sound obect in the library correctly?

               

              Is that 'yourmc.gotoAndPlay' correct on the last line? I'm specifically curious about the 'mc'

               

              Also, is this getting the sound to play in the first place?

               

              Best, Steve

              • 4. Re: Go to - when a sound is complete
                Steve_Nixon_ADP Level 1

                Found this online, testing it now....

                 

                 

                 

                import flash.events.Event;
                import flash.media.Sound;
                import flash.net.URLRequest;
                var sound:Sound = new Sound();
                var soundReq:URLRequest = new
                URLRequest("sounds/intro2.mp3");
                sound.load(soundReq);
                sound.addEventListener(Event.COMPLETE, soundPlay);
                function soundPlay(event:Event):void
                {  
                    var soundChannel:SoundChannel;
                    soundChannel = sound.play();
                    soundChannel.addEventListener(Event.SOUND_COMPLETE, soundComplete);
                }
                function soundComplete(event:Event):void
                {
                    trace("The sound has finished playing.");
                   
                    gotoAndStop("intro");
                }
                • 5. Re: Go to - when a sound is complete
                  kglad Adobe Community Professional & MVP

                  that's as3 code.

                   

                  use the code i suggested.  if you're loading a sound, add a loadSound() method to your sound instance where i put the ellipsis.  if you're attaching a sound, add an attachSound() method to your sound instance where i put the ellipsis.

                  • 6. Re: Go to - when a sound is complete
                    Steve_Nixon_ADP Level 1

                    So if I have the sound named "spider_b-xtereo_s-7449_hifi.mp3" and I want it to play and then go to "marker2" when it is complete, how would that look?

                     

                    loadSound(spider_b-xtereo_s-7449_hifi.mp3)
                    yoursound:Sound=new Sound(loadSound(spider_b-xtereo_s-7449_hifi.mp3));
                    yoursound.onSoundComplete=function(){
                    yourmc.gotoAndPlay("marker2");
                    }

                     

                    I tried this, but it still throws an error. BTW the sound file is in my library, does it need to be external?

                     

                    Best, Steve

                     

                    • 7. Re: Go to - when a sound is complete
                      kglad Adobe Community Professional & MVP

                       

                       

                      use:

                       

                       

                      yoursound:Sound=new Sound(this);

                      yoursound.loadSound("spider_b-xtereo_s-7449_hifi.mp3",true);

                      yoursound.onSoundComplete=function(){

                      yourmc.gotoAndPlay("yourframelabel");

                      }

                      • 8. Re: Go to - when a sound is complete
                        Rothrock Level 5

                        Generally if you are getting errors it is helpful if you post the error you get. That way people can help you with it. Otherwise we have no idea what you are experiencing.

                         

                        Here is a similar thread:

                         

                        http://forums.adobe.com/message/3111858#3111858

                         

                         

                        If your sound is in your library be sure that you have set it to export. And then you would use the attachSound() method of the Sound class.

                         

                        And in your constructor you would do this:

                         

                        var yourSound:Sound=new Sound(this);

                         

                        The argument in the constructor should be a reference to a MovieClip, either "this" which means the timeline the code is on, or perhaps if you have several sounds that need to be controlled independently you might make a special movieclip for that sound, such as:

                         

                        var sndTrack1:MovieClip=this.createEmtpyMovieClip("sndTrack1",1000);

                        var sndTrack2:MovieClip=this.createEmptyMovieClip("sndTrack2",1001);

                         

                        var mySnd1:Sound=new Sound(sndTrack1);

                        var mySnd2:Sound=new Sound(sndTrack2);

                         

                        mySnd1.attachSound("someLinkageID1");

                        mySnd2.loadSound("someURL",isStreaming);

                         

                        That way you could control the volume and other properties of the sounds independently of each other. And in this case mySnd1 is attaching some sound from the library and mySnd2 is handling an externally loaded sound file.

                        • 9. Re: Go to - when a sound is complete
                          kglad Adobe Community Professional & MVP

                          if the sound file is in your library, use attachSound("yoursoundslinkageid") instead of loadSound() and make sure you assign a linkage id to your sound.  apply the play() method to your sound after the attachSound() line.

                          • 10. Re: Go to - when a sound is complete
                            Steve_Nixon_ADP Level 1

                            Hi all, I have a solution to this that works. I got a script from another fellow over at flashKit. This holds it's position in the frame until the sound is finished playing and then advances to frame 10. In the sound properties box in the library the sound has to be set to "Export for Actionscript" and "Export in Frame 1".

                             

                            stop();
                            function doSoundComplete() {
                            trace("completed");
                            gotoAndStop(10);
                            }

                             

                            var my_sound = new Sound();
                            my_sound.onSoundComplete = doSoundComplete;
                            my_sound.attachSound("audioreferencename.mpg");
                            my_sound.start();

                             

                            Thanks for your time on this, both of you - greatly appreciated.

                             

                            Best, Steve