29 Replies Latest reply on Aug 3, 2008 8:33 PM by Newsgroup_User

    how to calculate second and minisecond for audio cue point

    wuzhishan
      I'm trying to do a sound sync for the audio and movie clip in Flash. I found a tutorial on the web and it seems to work. However, I don't know how to calculate the second and mini second from the mp3 file. The first frame has the following lines to define the time for each animation:
      // Import class
      import net.quip.sound.SoundSync;

      // Stop main timeline
      stop();

      // Create an instance of SoundSync
      var ss:SoundSync = new SoundSync();

      ss.addCuePoint("IT", 20100);
      ss.addCuePoint("admin", 20000);
      ss.addCuePoint("maitenance", 19800);
      ss.addCuePoint("treatment", 16479);
      ss.addCuePoint("engineering", 14598);
      as.addCuePoint("logo_epa_npdes", 12356);
      ss.addCuePoint("construction", 8967);
      ss.addCuePoint("370mgd", 7896);
      ss.addCuePoint("mc_650,000",5439 );
      ss.addCuePoint("130mgd", 3254);
      ss.addCuePoint("1938", 2439);
      ss.addCuePoint("vintage_mc", 0);

      // Use instance to load external MP3
      ss.loadSound("Scn04-05.mp3", true);

      // Create a listener object for the
      // cuePoint and onSoundComplete events
      var listener:Object = new Object();
      listener.cuePoint = function():Void {
      play();
      }
      listener.onSoundComplete = function():Void {
      play();
      }
      ss.addEventListener("cuePoint", listener);
      ss.addEventListener("onSoundComplete", listener);

      and the soundsync.as file as follows:
      import mx.events.EventDispatcher;
      import mx.utils.Delegate;
      class net.quip.sound.SoundSync extends Sound {
      // PROPERTIES
      private var _cuePoints:Array;
      private var _currentCuePoint:Number;
      private var _interval:Number;
      private var _intervalDuration:Number;
      private var _secondOffset:Number;
      // Event dispatcher
      public var dispatchEvent:Function;
      public var addEventListener:Function;
      private var removeEventListener:Function;
      // CONSTRUCTOR
      public function SoundSync(target:MovieClip) {
      super(target);
      init();
      }
      // METHODS
      private function init():Void {
      // Initialize properties
      _cuePoints = new Array();
      _currentCuePoint = 0;
      _intervalDuration = 200;
      _secondOffset = 0;
      // Initialize class instance as valid event broadcaster
      EventDispatcher.initialize(this);
      }
      // Add Cue Point
      public function addCuePoint(cuePointName:String, cuePointTime:Number):Void {
      _cuePoints.push(
      {
      type: "cuePoint",
      name: cuePointName,
      time: cuePointTime,
      target: this
      }
      );
      _cuePoints.sortOn("time", Array.NUMERIC);
      }
      // Get Cue Point
      public function getCuePoint(nameOrTime:Object):Object {
      var counter:Number = 0;
      while (counter < _cuePoints.length) {
      if (typeof(nameOrTime) == "string") {
      if (_cuePoints[counter].name == nameOrTime) {
      return _cuePoints[counter];
      }
      } else if (typeof(nameOrTime) == "number") {
      if (_cuePoints[counter].time == nameOrTime) {
      return _cuePoints[counter];
      }
      }
      counter++;
      }
      return null;
      }
      // Get Current Cue Point Index
      private function getCurrentCuePointIndex(cuePoint:Object):Number {
      var counter:Number = 0;
      while (counter < _cuePoints.length) {
      if (_cuePoints[counter].name == cuePoint.name) {
      return counter;
      }
      counter++;
      }
      return null;
      }
      // Get Next Cue Point Index
      private function getNextCuePointIndex(seconds:Number):Number {
      seconds = (seconds) ? seconds : 0;
      var counter:Number = 0;
      while (counter < _cuePoints.length) {
      if (_cuePoints[counter].time >= seconds * 1000) {
      return counter;
      }
      counter++;
      }
      return null;
      }
      // Remove Cue Point
      public function removeCuePoint(cuePoint:Object):Void {
      _cuePoints.splice(getCurrentCuePointIndex(cuePoint), 1);
      }
      // Remove All Cue Points
      public function removeAll_cuePoints():Void {
      _cuePoints = new Array();
      }
      // Start
      public function start(secondOffset:Number, loops:Number):Void {
      super.start(secondOffset, loops);
      dispatchEvent({type:"onStart", target:this});
      // Reset current cue point
      _secondOffset = secondOffset;
      _currentCuePoint = getNextCuePointIndex(secondOffset);
      // Poll for cue points
      clearInterval(_interval);
      _interval = setInterval(Delegate.create(this, pollCuePoints), _intervalDuration);
      }
      // Load Sound
      public function loadSound(url:String, isStreaming:Boolean):Void {
      super.loadSound(url, isStreaming);
      clearInterval(_interval);
      _interval = setInterval(Delegate.create(this, pollCuePoints), _intervalDuration);
      }
      // Stop
      public function stop(linkageID:String):Void {
      if (linkageID) {
      super.stop(linkageID);
      } else {
      super.stop();
      }
      dispatchEvent({type:"onStop", target:this});
      // Kill polling
      clearInterval(_interval);
      }
      // Poll Cue Points
      private function pollCuePoints():Void {
      // If current position is near the current cue point's time ...
      var time:Number = _cuePoints[_currentCuePoint].time;
      var span:Number = (_cuePoints[_currentCuePoint + 1].time) ? _cuePoints[_currentCuePoint + 1].time : time + _intervalDuration * 2;
      if (position >= time && position <= span) {
      // Dispatch event
      dispatchEvent(_cuePoints[_currentCuePoint]);
      // Advance to next cue point ...
      if (_currentCuePoint < _cuePoints.length) {
      _currentCuePoint++;
      } else {
      _currentCuePoint = getNextCuePointIndex(_secondOffset);
      }
      }
      }
      // EVENT HANDLERS
      // onSoundComplete
      public function onSoundComplete():Void {
      // Kill polling
      clearInterval(_interval);
      // Reset current cue point
      _currentCuePoint = 0;
      // Dispatch event
      dispatchEvent({type:"onSoundComplete", target:this});
      }
      }

      any help will be greatly appreciated.
        • 1. Re: how to calculate second and minisecond for audio cue point
          Rothrock Level 5
          Why do you need to compute the milli/second (I assume that is what you mean)? The cuepoints know what the time is and when they need to be called. What are you actually trying to accomplish?

          In that part in your file you could change this:

          listener.cuePoint = function():Void {
          play();
          }

          to something more useful, perhaps that would help:

          listener.cuePoint=function(event:Object):Void{
          trace("Cuepoint "+event.name+" at: "+event.time);
          play();
          }
          • 2. Re: how to calculate second and minisecond for audio cue point
            Level 7
            wuzhishan,

            > I'm trying to do a sound sync for the audio and movie clip in Flash.
            > I found a tutorial on the web and it seems to work. However, I
            > don't know how to calculate the second and mini second from
            > the mp3 file.

            I wrote that article and the code, so I'll help if I can. :) But I'm
            not sure I understand your question yet.

            Are you asking, "How do I convert minutes and seconds into
            milliseconds?" If so, here's an example. Let's say you want to add a cue
            point at 4 minutes and 41 seconds. Converting the 41 seconds part is easy:
            just mutiply that number by 1,000. So far, you've got 41,000 milliseconds.
            Now set that number aside for just a moment and turn your attention to the
            minutes.

            You've got 4 minutes. There are 60 seconds in a minute, so convert to
            seconds first. 4 * 60 is 240. At this point, you're back to where you were
            before (a seconds value). Multiply that 240 by a thousand -- 240,000 -- and
            add it to the other milliseconds value: 240,000 plus 41,000 equals 281,000
            milliseconds.

            So 4min 41sec is 281,000 milliseconds.

            Does that help?


            David Stiller
            Adobe Community Expert
            Dev blog, http://www.quip.net/blog/
            "Luck is the residue of good design."


            • 3. Re: how to calculate second and minisecond for audio cue point
              wuzhishan Level 1
              Hi Dave, your tutorial is a cute one and it is very useful.
              I'm sorry I didn't make my question clear. I mean I don't know how to get the time for the cue point. For instance, I listen to the mp3 in Windows Media Player and try to get the time for the cue, I found it on the bottom of the player the time shows 00:26. How do I writer this number in the code? Is it 0026 or 26?

              Thank you so much for your help.
              • 4. Re: how to calculate second and minisecond for audio cue point
                Level 7
                wuzhishan,

                > Hi Dave, your tutorial is a cute one and it is very useful.

                Thanks! My daughter is the cute one. She inherited all of that from
                me, so I don't have any left. ;)

                > I'm sorry I didn't make my question clear.

                No worries. :)

                > I listen to the mp3 in Windows Media Player and try to
                > get the time for the cue, I found it on the bottom of the
                > player the time shows 00:26.

                I'm with ya.

                > How do I writer this number in the code? Is it 0026 or 26?

                The code is expecting milliseconds, so 26 seconds would be written like
                this:

                26000

                If it said 1:22 (a minute and 22 seconds), you would write it like this:

                82000

                ... which is 60 seconds for the single minute, plus 22 from the seconds
                side, then multiplied by 1,000 to get milliseconds.


                David Stiller
                Adobe Community Expert
                Dev blog, http://www.quip.net/blog/
                "Luck is the residue of good design."


                • 5. Re: how to calculate second and minisecond for audio cue point
                  wuzhishan Level 1
                  Thanks Dave, you really make my day!!! I can image how cute your daught is from her voice:)
                  • 6. Re: how to calculate second and minisecond for audio cue point
                    wuzhishan Level 1
                    Hi Dave, the movie runs fine in my local drive, but when uploaded to the server, it doesn't work. I uploaded the net/quip/sound/SoundSync.as.

                    Thank very much for your help.
                    • 7. Re: how to calculate second and minisecond for audio cue point
                      Level 7
                      wuzhishan,

                      > Hi Dave, the movie runs fine in my local drive, but when
                      > uploaded to the server, it doesn't work. I uploaded the
                      > net/quip/sound/SoundSync.as.

                      There are two ways to play audio in Flash: a) include audio files in
                      the Library or b) load external files, such as MP3s, at runtime. The
                      SoundSync class supports both of those ways, but if you're loading external
                      MP3s, you'll have to make sure those files are also available on the server.

                      So: upload the SWF, HTML file, and MP3(s). You can leave the FLA and
                      all of your AS files on your local machine.

                      Does that fix it?


                      David Stiller
                      Contributor, How to Cheat in Flash CS3
                      http://tinyurl.com/2cp6na
                      "Luck is the residue of good design."


                      • 8. Re: how to calculate second and minisecond for audio cue point
                        wuzhishan Level 1
                        Hi Dave,

                        Yes, I didn't upload the sound file to the server. That problem is fixed. Thank you.
                        I have another problem and this one is really driving me crazy: I can't make the correct timing for the cue point I listen to the audio play in QuickTime player and Windows Media Player (they give the same timing) and mark down the time and write them in the code but they don't sync right. Here is the cue point with time:
                        // Create an instance of SoundSync
                        var ss:SoundSync = new SoundSync();

                        ss.addCuePoint("IT", 61000);
                        ss.addCuePoint("admin", 59000);
                        ss.addCuePoint("maitenance", 56000);
                        ss.addCuePoint("treatment", 53000);
                        ss.addCuePoint("engineering", 50000);
                        ss.addCuePoint("370mgd", 27000);
                        ss.addCuePoint("logo_epa_npdes", 22000);
                        ss.addCuePoint("construction", 20000);
                        ss.addCuePoint("mc_650000", 15000);
                        ss.addCuePoint("130mgd", 10000);
                        ss.addCuePoint("mc_1938", 8000);
                        ss.addCuePoint("vintage_mc", 4000);
                        ss.addCuePoint("mc_community", 0);

                        I don't understamd why they don't sync right. Could you please help me out?
                        Thank you very much.
                        • 9. Re: how to calculate second and minisecond for audio cue point
                          Level 7
                          wuzhishan,

                          > I can't make the correct timing for the cue point I listen to the
                          > audio play in QuickTime player and Windows Media Player
                          > (they give the same timing) and mark down the time and write
                          > them in the code but they don't sync right.

                          Can you provide more detail in your description? What do you mean by
                          "they don't sync right"? For example, are they consistently early,
                          consistently late, or just inconsistent?


                          David Stiller
                          Adobe Community Expert
                          Dev blog, http://www.quip.net/blog/
                          "Luck is the residue of good design."


                          • 10. Re: how to calculate second and minisecond for audio cue point
                            wuzhishan Level 1
                            Dave, thank you for your instant reply.
                            I think they are consistantly early so I delay each movie by 4 seconds but that only work for the first 4 movie clips and all others still out of sync. e.g. this cue point: ss.addCuePoint("engineering", 50000); no matter what time I set it for it, it still appear early
                            • 11. Re: how to calculate second and minisecond for audio cue point
                              wuzhishan Level 1
                              amazingly, I had a typo here: as.addCuePoint("logo_epa_npdes", 22000); but it makes the cue point in sync!!!!!!
                              but this is not the anwser to the problem.
                              var ss:SoundSync = new SoundSync();

                              ss.addCuePoint("IT", 61000);
                              ss.addCuePoint("admin", 59000);
                              ss.addCuePoint("maitenance", 56000);
                              ss.addCuePoint("treatment", 53000);
                              ss.addCuePoint("engineering", 50000);
                              ss.addCuePoint("370mgd", 27000);
                              as.addCuePoint("logo_epa_npdes", 22000);
                              ss.addCuePoint("construction", 20000);
                              ss.addCuePoint("mc_650000", 15000);
                              ss.addCuePoint("130mgd", 10000);
                              ss.addCuePoint("mc_1938", 8000);
                              ss.addCuePoint("vintage_mc", 4000);
                              ss.addCuePoint("mc_community", 0);
                              • 12. Re: how to calculate second and minisecond for audio cue point
                                Level 7
                                wuzhishan,

                                > amazingly, I had a typo here: as.addCuePoint("logo_epa_npdes",
                                > 22000);
                                > but it makes the cue point in sync!!!!!!

                                w00t! :)

                                > but this is not the anwser to the problem.

                                Aw, shucks. :(

                                >> I think they are consistantly early so I delay each movie by 4
                                >> seconds but that only work for the first 4 movie clips and all
                                >> others still out of sync.

                                Wow! Well, honestly ... four seconds is a huge discrepancy. I was
                                thinking you might be seeing issues within a couple hundred milliseconds.
                                Four seconds is surprising to me. I guess my first question, then, is:
                                What is your event handler? In other words, what are you asking these cue
                                points to trigger? You mention movie clips, so I wonder if you're using
                                your event handler to reference movie clip instance names, asking each movie
                                clip to play (e.g. myMovieClip.play(), or the like). If that's so, you
                                could very well see a delay if your movie clips have varying amounts of
                                unused frames at the beginnings of their timelines.

                                But you're saying these cue points are triggered four seconds *early*.

                                What happens if you temporarily take the movie clips out of the
                                equation, and simply have your event handler trace() out a test message?
                                Are they early then?


                                David Stiller
                                Adobe Community Expert
                                Dev blog, http://www.quip.net/blog/
                                "Luck is the residue of good design."


                                • 13. Re: how to calculate second and minisecond for audio cue point
                                  wuzhishan Level 1
                                  Dave,

                                  I reduced the number of frames for all my movie clip into 1(they had maximum 30 frames before) and I run the movie it still has the same problem: 4 seconds early.
                                  • 14. Re: how to calculate second and minisecond for audio cue point
                                    Level 7
                                    wuzhishan,

                                    > I reduced the number of frames for all my movie clip into
                                    >1(they had maximum 30 frames before) and I run the movie
                                    > it still has the same problem: 4 seconds early.

                                    Can you show the code you're using for your event handler?


                                    David Stiller
                                    Adobe Community Expert
                                    Dev blog, http://www.quip.net/blog/
                                    "Luck is the residue of good design."


                                    • 15. Re: how to calculate second and minisecond for audio cue point
                                      wuzhishan Level 1
                                      Dave,

                                      I'm not a programer. I have very basic understanding of Actionscript.
                                      I did not change anything in your SoundSync.as file. I just replace the name of instances with mine.
                                      The script on the first frame as follows:
                                      // Import class
                                      import net.quip.sound.SoundSync;

                                      // Stop main timeline
                                      stop();

                                      // Create an instance of SoundSync
                                      var ss:SoundSync = new SoundSync();

                                      ss.addCuePoint("IT", 59000);
                                      ss.addCuePoint("admin", 57000);
                                      ss.addCuePoint("maitenance", 54000);
                                      ss.addCuePoint("treatment", 52000);
                                      ss.addCuePoint("engineering", 50000);
                                      ss.addCuePoint("370mgd", 26000);
                                      ss.addCuePoint("logo_epa_npdes", 19000);
                                      ss.addCuePoint("construction", 15000);
                                      ss.addCuePoint("mc_650000", 13000);
                                      ss.addCuePoint("130mgd", 8000);
                                      ss.addCuePoint("mc_1938", 4000);
                                      ss.addCuePoint("vintage_mc", 2000);
                                      ss.addCuePoint("mc_community", 0);

                                      // Use instance to load external MP3
                                      ss.loadSound("FLV/welcome/Scn04-05.mp3", true);

                                      // Create a listener object for the
                                      // cuePoint and onSoundComplete events
                                      var listener:Object = new Object();
                                      listener.cuePoint = function():Void {
                                      play();
                                      }
                                      listener.onSoundComplete = function():Void {
                                      play();
                                      }
                                      ss.addEventListener("cuePoint", listener);
                                      ss.addEventListener("onSoundComplete", listener);


                                      • 16. Re: how to calculate second and minisecond for audio cue point
                                        Level 7
                                        wuzhishan,

                                        > I'm not a programer.

                                        That's okay. :)

                                        > I have very basic understanding of Actionscript. I did not
                                        > change anything in your SoundSync.as file. I just replace
                                        > the name of instances with mine.

                                        In that case, I'm curious what you meant earlier when you mentioned
                                        movie clips -- I guessing frame labels? -- but we'll find out. :) To
                                        perform a bit of troubleshooting, let's replace a bit of code inside your
                                        event handler function. Specifically, this means the portion of
                                        ActionScript that "hears" the cue point event and does something about it
                                        (handles it).

                                        Change this part here:

                                        // Create a listener object for the
                                        // cuePoint and onSoundComplete events
                                        var listener:Object = new Object();
                                        listener.cuePoint = function():Void {
                                        play();
                                        }

                                        To this:

                                        // Create a listener object for the
                                        // cuePoint and onSoundComplete events
                                        var listener:Object = new Object();
                                        listener.cuePoint = function(evt:Object):Void {
                                        trace("cue point " + evt.time);
                                        }

                                        Instead of displaying frame labels on your timeline, this will send text
                                        content to the Output panel when you test your SWF. You should see the
                                        words "cue point" followed by a time value in milliseconds.

                                        My goal at this point is to see if the timing of these Output panel
                                        messages corresponds appropriately to the timing of your cue points.


                                        David Stiller
                                        Adobe Community Expert
                                        Dev blog, http://www.quip.net/blog/
                                        "Luck is the residue of good design."


                                        • 17. Re: how to calculate second and minisecond for audio cue point
                                          wuzhishan Level 1
                                          Dave,

                                          I try your code and get the following cue point:
                                          cue point 0
                                          cue point 2000
                                          cue point 4000
                                          cue point 8000
                                          cue point 13000
                                          cue point 15000
                                          cue point 19000
                                          cue point 29000
                                          cue point 55000
                                          cue point 57000
                                          cue point 59000
                                          cue point 62000
                                          They do correspond to my cue point set for the movie clips(cue point 64000 is missing)
                                          ss.addCuePoint("IT", 64000);
                                          ss.addCuePoint("admin", 62000);
                                          ss.addCuePoint("maitenance", 59000);
                                          ss.addCuePoint("treatment", 57000);
                                          ss.addCuePoint("engineering", 55000);
                                          ss.addCuePoint("370mgd", 29000);
                                          ss.addCuePoint("logo_epa_npdes", 19000);
                                          ss.addCuePoint("construction", 15000);
                                          ss.addCuePoint("mc_650000", 13000);
                                          ss.addCuePoint("130mgd", 8000);
                                          ss.addCuePoint("mc_1938", 4000);
                                          ss.addCuePoint("vintage_mc", 2000);
                                          ss.addCuePoint("mc_community", 0);
                                          I don't have frame label in the movie. The cue point name"mc_community", "vintage_mc", etc. are the names of my movie clips. Just like the name "Benjamin Franklin" in your sample movie in the tutorial. The differences between yours and mine is that yours are graphics with simple fade in and fade out movement but mine are movie clips containing many frames of movement.

                                          Thank you very much for help.
                                          • 18. Re: how to calculate second and minisecond for audio cue point
                                            Level 7
                                            wuzhishan,

                                            > I try your code and get the following cue point:
                                            > cue point 0
                                            > cue point 2000
                                            > cue point 4000
                                            // etc.

                                            Okay, good so far.

                                            > They do correspond to my cue point set for the movie clips(cue point
                                            > 64000 is missing)

                                            Good. :) Tthat's good news. I'm not so concerned about that last
                                            cuepoint -- the missing one -- at the moment, as it might possibly be too
                                            close to the end of the audio file, and might have been picked up by the
                                            "complete" event handler earleir.

                                            > I don't have frame label in the movie. The cue point name
                                            > "mc_community", "vintage_mc", etc. are the names of my
                                            > movie clips. Just like the name "Benjamin Franklin" in your
                                            > sample movie in the tutorial.

                                            Okay.

                                            > The differences between yours and mine is that yours are
                                            > graphics with simple fade in and fade out movement but mine
                                            > are movie clips containing many frames of movement.

                                            My hunch, wuzhishan, is that your timing issue stems from the way your
                                            movie clips are set up. I say this because you said your trace() statements
                                            correspond to the cue points as they should. In fact, all the event handler
                                            does is issue a play() function, which sets the timeline in motion again.
                                            The timing involved -- between the timeline and the nested timelines of your
                                            movie clips -- depends on the overall framerate of your movie, in addition
                                            to the duration of your various timelines.

                                            You don't have to use the event handler to trigger a play(). Instead,
                                            you could use it to attach movie clips from your library, or turn on (or
                                            off) the visibility of movie clips already on the Stage. That might improve
                                            things for you.

                                            Does that make sense?


                                            David Stiller
                                            Adobe Community Expert
                                            Dev blog, http://www.quip.net/blog/
                                            "Luck is the residue of good design."


                                            • 19. Re: how to calculate second and minisecond for audio cue point
                                              wuzhishan Level 1
                                              Hi Dave,

                                              Yes, what you said make a lot of sense, of cause:) I wish I knew how to write the code. Could you please provide the code for this issue, as you described: attach movie clips from library, or turn on (or off) the visibility of movie clips already on the Stage?

                                              I have two more questions:
                                              1. how to tell the movie gotoAndPlay next scene after the audio finish?
                                              2. how to program a preloader for this audio cue point movie?


                                              I really appreciate your help.
                                              • 20. Re: how to calculate second and minisecond for audio cue point
                                                Level 7
                                                wuzhishan,

                                                > Could you please provide the code for this issue, as you
                                                > described: attach movie clips from library, or turn on (or
                                                > off) the visibility of movie clips already on the Stage?

                                                That would depend on the information you provide with your cue points.
                                                If the cue points include the name of a particular movie clip with them --
                                                as yours seem to (IT, admin, maintenance, treatment, etc.) -- then you can
                                                use that information for attaching rather than as the name of a frame label.
                                                If you want to attach a movie clip at runtime, and if you're using AS2
                                                (which you are), then you'll use the MovieClip.attachMovie() method, which
                                                works like this:

                                                someMovieClipReference.attachMovie("linkageID", "instanceName", depth);

                                                ... where linkageID refers to the linkage identifier you give the symbol in
                                                your Library. Right-click a given movie clip and you'll see what I mean.
                                                Select Linkage, and you'll have a place to put your linkage identifier,
                                                which is simply an arbitrary name ... just like any of the strings you're
                                                using (IT, admin, maintenance, treatment, etc.). The instance name can be
                                                the same string, or make up something else -- as long as it's unique to the
                                                scope you're in. The depth can be handled automtatically by way of the
                                                MovieClip.getNextHightestDepth() method. Here's one way you could do it:

                                                var timeline:MovieClip = this;
                                                var listener:Object = new Object();
                                                listener.cuePoint = function(evt:Object):Void {
                                                timeline.attachMovie(evt.name, evt.name, timeline.getNextHighestDepth());
                                                }

                                                This is the same code block I suggested earlier (the event handler --
                                                the handler listening for the cuePoint event). In this case, you're once
                                                again using the evt parameter. This time, instead of referencing evt.time,
                                                as I suggested in my previous reply, you're using evt.name, which would be
                                                the IT, admin, maintenance, treatment, etc., I keep mentioning. In this
                                                event handler, you're invoking the MovieClip.attachMovie() on a reference
                                                called timeline, which is simply a MovieClip reference to the main timeline.
                                                The main timeline *is* a movie clip, and a movie clip reference is all you
                                                need to invoke any method in the MovieClip class.

                                                Incidentally, methods are simply things an object can do. If you look
                                                up "MovieClip class" in the ActionScript 2.0 Language Refernece, you'll see
                                                the class -- the blueprint -- that defines all movie clips. Methods are the
                                                things a movie clip, such as the timeline, can do. The things it can react
                                                to are called events. The characteristics it has are called properties.
                                                This approach toward discovering an object's functionality ... it works for
                                                all object classes. You might get something out of this article, which goes
                                                into greater detail on how to use the AS2 language reference in Flash:

                                                http://www.communitymx.com/abstract.cfm?cid=01B54 (free content)

                                                So ... the timeline variable gives you a handy reference to the main
                                                timeline, which is where this code appears (which is why the keyword "this"
                                                refers the main timeline when written there). The timeline variable gives
                                                you a reference used twice in my suggested code. First, to invoke the
                                                attachMovie() method, which requires at least three parameters: a linkage
                                                ID (taken from the cue point's name property; an instance name, also taken
                                                from the cue point's name property; and finally a depth value, taken from
                                                the second timeline refernce, along with a reference to the
                                                MovieClip.getNextHighestDepth() method. In other words, this will set your
                                                movie clip to the next available depth in the main timeline.

                                                To use a different approach -- such as turning on the visibility of a
                                                movie clip already on the Stage -- you'll need to make sure your clips
                                                already have unique instance names, which you can provide using the Property
                                                inspector. Give each movie clip an instance name, then invoke the
                                                MovieClip.stop() method on each in if the first frame of your movie --
                                                assuming that each movie clip appears in the first frame. In fact, you
                                                should also use the same opportunity to set the MovieClip._visible property
                                                of each to false. Again, using the same instance names:

                                                IT.stop();
                                                IT._visible = false;
                                                admin.stop();
                                                admin._visible = false;
                                                maintenance.stop();
                                                maintenance._visible = false;
                                                treatment.stop();
                                                treatment._visible = false;
                                                // etc.

                                                Then, in your event handler, you might use something like this:

                                                var timeline:MovieClip = this;
                                                var listener:Object = new Object();
                                                listener.cuePoint = function(evt:Object):Void {
                                                timeline[evt.name]._visible = true;
                                                timeline[evt.name].play();
                                                }

                                                In this case, you're using something called the array access operator,
                                                [], to convert a string -- the cue point's name value -- into an object
                                                reference. This article explains the technique:

                                                http://www.quip.net/blog/2006/flash/actionscript-20/reference-objects-dynamically

                                                I can understand if any of these new suggestions are bewildering.
                                                Programming isn't especially easy ... otherwise anyone could do it, and we
                                                wouldn't need forums like this one. :) I hope these suggestions at least
                                                give you a bit more to experiment with.

                                                > I have two more questions:
                                                > 1. how to tell the movie gotoAndPlay next scene after the audio
                                                > finish?

                                                For that, you'll use the SoundSync.onSoundComplete event, as shown in
                                                the samle file with the original article. Instead of invoking the play()
                                                method, you would have to use the gotoAndPlay() funtion -- not a method!
                                                The method version of this functionality doesn't accept scenes as a
                                                parameter. See this for more info:

                                                http://www.quip.net/blog/2006/flash/actionscript-20/gotoandplay-with-scenes

                                                > 2. how to program a preloader for this audio cue point movie?

                                                A preloader for the MP3? Preloading, in general, means comparing the
                                                amount of a file that has already loaded with the total amount of bytes it
                                                contains. Because the SoundSync class extends the native Sound class,
                                                you'll see that your SoundSync instance has access to two useful methods:
                                                getBytesLoaded() and getBytesTotal(). You can see an article that
                                                illustrates these methods (for a different object class) here:

                                                http://www.quip.net/blog/2006/flash/how-to-tell-when-external-swf-loaded


                                                David Stiller
                                                Co-author, Foundation Flash CS3 for Designers
                                                http://tinyurl.com/2k29mj
                                                "Luck is the residue of good design."


                                                • 21. Re: how to calculate second and minisecond for audio cue point
                                                  wuzhishan Level 1
                                                  Dave,

                                                  Thank you so much for such a detailed, step by step explaination on how to make my audio cue point work. I really appreciate your help.
                                                  I found a more simpler way of doing audio cue point. Just convert the mp3 to flv and add ac cue point to the audio flv. and then apply these code on the first frame:
                                                  stop();
                                                  var nextAniIndex:Number = 0;
                                                  var Ani:Array = [ occupations, activites, globe, squarepics, liquid, solid, gas];

                                                  //
                                                  // Listen for cuePoint events on the FLVPlayback component
                                                  //
                                                  flv_audio.addEventListener( "cuePoint", this );

                                                  //
                                                  // Event handler: cuePoint
                                                  //
                                                  function cuePoint ( eventObj:Object )
                                                  {


                                                  var nextAni:MovieClip = Ani [ nextAniIndex ];
                                                  nextAni.play();

                                                  nextAniIndex++;
                                                  }
                                                  //when video finish, go to next scene
                                                  var vidList : Object = new Object();
                                                  vidList.complete = function() {
                                                  gotoAndPlay("howworks2");
                                                  }
                                                  flv_audio.addEventListener ("complete",vidList);


                                                  • 22. Re: how to calculate second and minisecond for audio cue point
                                                    Level 7
                                                    wuzhishan,

                                                    > Thank you so much for such a detailed, step by step explaination
                                                    > on how to make my audio cue point work. I really appreciate your
                                                    > help.

                                                    Sure thing. :)

                                                    > I found a more simpler way of doing audio cue point. Just convert
                                                    > the mp3 to flv and add ac cue point to the audio flv.

                                                    Yup, that'll do it too, so now you have a number of flexible options at
                                                    your fingertips!


                                                    David Stiller
                                                    Adobe Community Expert
                                                    Dev blog, http://www.quip.net/blog/
                                                    "Luck is the residue of good design."


                                                    • 23. Re: how to calculate second and minisecond for audio cue point
                                                      wuzhishan Level 1
                                                      Dave,

                                                      I will practise your code for future project. I'm just running out of time on this one.
                                                      I have another question here:
                                                      My movie has several scenes. The first scene has a flv without cue point but it has following code attached to it:

                                                      var vidList : Object = new Object();
                                                      vidList.complete = function() {
                                                      gotoAndPlay("community"); //go to next scene
                                                      }
                                                      flv_welcome.addEventListener ("complete",vidList);
                                                      stop();

                                                      It plays in IE and Safari, but Firefox doesn't play it.

                                                      Thank you very much for help.
                                                      • 24. Re: how to calculate second and minisecond for audio cue point
                                                        Level 7
                                                        wuzhishan,

                                                        > My movie has several scenes. The first scene has a flv without cue
                                                        > point but it has following code attached to it:
                                                        >
                                                        > var vidList : Object = new Object();
                                                        > vidList.complete = function() {
                                                        > gotoAndPlay("community"); //go to next scene

                                                        As shown, that will go to a frame label named "community", not
                                                        necessarily to a new scene by that name.

                                                        > It plays in IE and Safari, but Firefox doesn't play it.

                                                        Do you have the same version of Flash Player installed in all browsers?

                                                        More importantly, I would test to make sure your gotoAndPlay() statement
                                                        works the way you think it does. It's better to use frame labels than
                                                        scenes anyway, honestly. This isn't something you'll find in the
                                                        documentation ... it's just a known issue that has been discussed for years
                                                        in these forums. Forego scene names. Give each of your timeline
                                                        destinations a unique frame label, and use that instead.


                                                        David Stiller
                                                        Contributor, How to Cheat in Flash CS3
                                                        http://tinyurl.com/2cp6na
                                                        "Luck is the residue of good design."


                                                        • 25. Re: how to calculate second and minisecond for audio cue point
                                                          wuzhishan Level 1
                                                          Dave,

                                                          Thank you for the quick reply.
                                                          You can test the movie to see the "gotoAndPlay" will go to next scene. The virtual tour is ready for test. Here is the url:
                                                          http://www.dcwasa.com/vtour_test/tour1/VirtualTour.html

                                                          Please click on the "Introduction" button to test the movie.
                                                          • 26. Re: how to calculate second and minisecond for audio cue point
                                                            wuzhishan Level 1
                                                            Dave,

                                                            I have to split the movie into small swfs. It's hard to load such a long movie, so I change the code from gotoAndPlay("community") to: _root.loader_mc.loadMovie("intro_community.swf");

                                                            How do I know what version of Flash Player my Foxfire installed? I thought it was installed in my computer.
                                                            • 27. Re: how to calculate second and minisecond for audio cue point
                                                              wuzhishan Level 1
                                                              I chang the code for the event handler now like this:
                                                              function playerCompleteHandler(evnt:Object) {
                                                              //load next swf
                                                              _root.loader_mc.loadMovie("intro_community.swf");
                                                              }
                                                              flv_welcome.addEventListener("complete", playerCompleteHandler);

                                                              It works well in IE and Safari but still doesn't work with Firefox.
                                                              • 28. Re: how to calculate second and minisecond for audio cue point
                                                                wuzhishan Level 1
                                                                The problem is resolved. Nothing to do with the code. I delete the old file and create a new one and now it works.
                                                                • 29. Re: how to calculate second and minisecond for audio cue point
                                                                  Level 7
                                                                  wuzhishan,

                                                                  > The problem is resolved. Nothing to do with the code.
                                                                  > I delete the old file and create a new one and now it works.

                                                                  Ah, good to hear that! I was checking up on threads tonight and checked
                                                                  out yours. Glad you solved it! :)


                                                                  David Stiller
                                                                  Adobe Community Expert
                                                                  Dev blog, http://www.quip.net/blog/
                                                                  "Luck is the residue of good design."