3 Replies Latest reply on Sep 5, 2010 8:45 PM by Rothrock

    How to give a timeline command after an mp3

    NikonsandVstroms Level 1

      I have a few long pieces of music (10 minutes plus) and was wondering if there is any actionscript 2.0 command I can give to basically say either after X.mp3 ends do Y timeline control or even if there is a way to enter in a time so after X minutes do Y timeline control.  Any ideas on how to do either?

        • 1. Re: How to give a timeline command after an mp3
          Rothrock Level 5

          If the sound is playing using the Sound class there is an onSoundComplete event that can be used to do anything you want when the sound reaches the end.


          If you are publishing to Flash 8 or higher you could also use setTimeout() to do something after a specific number of milliseconds. So


          function doY(){

               // whatever





          However setTimeout() is not precise it won't be exactly 10 minutes and in fact could vary by quite a bit. So in that case you might need something like:



          var myInterval:Number;

          var startTime:Number=getTimer();

          var delay:Number=10*60*1000;


          function checkIfLongEnough(){



                    function doY();





          myInterval = setInterval(checkIfLongEnough,500);


          That will start checking every 1/2 second if it has been 10 minutes since we started. So in that case it should only have at most a 1/2 second variance which doesn't seem too bad over 10 minutes. But of course it all depends upon your exact purpose.

          • 2. Re: How to give a timeline command after an mp3
            NikonsandVstroms Level 1

            Excuse my brain fart here I just can't get it to work.


            dd = new Sound();

            dd.loadSound("testshort.mp3", true);



            Then I keep trying to set up stuff after that and it wont work, so I'll just throw it up here.


            A simple gotoAndPlay would work but Ideally what want it to do on completion is something like:



            • 3. Re: How to give a timeline command after an mp3
              Rothrock Level 5

              You might want to check the help files for the Sound class. But basically you need to give an event handler function.


              var dd:Sound=new Sound(this);




              function handleComplete(){

              //do what you want



              And generally you shouldn't use loadMovie. It doesn't have built in way to handle errors or to tell you when it has completed. Instead look to the MovieClipLoader class. Also depending upon what you are loading the load could take some amount of time, which would make an awkward pause (unless that is what you are going for) between when the sound stops and when the swf loads.


              Instead you might want to use the MovieClipLoader class to start loading the content at the sametime the music starts. Then if it is loaded by the time the music stops you can just play....


              Just a thought.