13 Replies Latest reply on Jul 23, 2007 8:15 AM by zibber

    embarssing question

    zibber Level 1
      Hi

      Wondered if soemone could help me with this shockingly simple thing i want to do but cant work out:|. Bascially i have two arrays, one contains names of sounds to play and the other contains the time in which to play them. All i would like to be able to do is create a function that just checks the times against the clock and plays the right sounds back at the corect time. Canyone anyone help with this as i cant get my head round how to keep checking and then move and wait for the the next tiem to be hit.

      thanks in advance
        • 1. Re: embarssing question
          kglad Adobe Community Professional & MVP
          what do the time elements look like?
          • 2. Re: embarssing question
            zibber Level 1
            Hi Kglad

            the time elments r based on gettimer so jsut an array of times based in milliseconds. The system is quite crdue basically:

            user presses to record
            then the buttons that play sounds push the sound to play into an array and the time that it was chosen.

            So ideally i just need a way of creating a function that goes through the time array, plays the sound attached to the corresponiding index in that array and then play the next sound when it gets to the chosen time in the following element within the array.
            • 3. Re: embarssing question
              kglad Adobe Community Professional & MVP
              then that's doable. i assume after the sounds and their relative times are selected some event will trigger the sound sequence start.

              at that point you'll start a loop that will repeatedly checks the relative time (using getTimer() ) against the sound sequence start and if the time is within some tolerance limit (or exceeds the time interval set in the array) trigger the play of the next sound.

              if you want more details you'll need to specify if this is as2 or as3?
              • 4. Re: embarssing question
                zibber Level 1
                Hi Kglad

                Yes basically the app allows a user just to play a sequence or select a rcord option. Basically i am not trying to build a playback system for the recorded sequecnes. I kind of got to your explanation but just not sure how to implement it, without using frames to keeping chekcing if time has been reached(yes im more form desing as opposed code side:))I am working in as2 for this, and flashlite 2.0 to be precise:) any more detials would be most helpful

                thanks in advance
                • 5. Re: embarssing question
                  kglad Adobe Community Professional & MVP
                  if soundA is your array of sound linkage ids and timeA is your array of times and you want startBtn to trigger playback, you can use:

                  • 6. Re: embarssing question
                    Greg Dove Level 4
                    setInterval(testF, 1);

                    typo? the interval is in milliseconds.

                    shouldn't that be:
                    setInterval(testF, 100);



                    • 7. Re: embarssing question
                      kglad Adobe Community Professional & MVP
                      no, not if he wants to maximize playback accuracy. though you could use tolerance/2 instead of 1 and still obtain accuracy within tolerance.
                      • 8. embarssing question
                        Greg Dove Level 4
                        Sorry but I don't think that's correct.

                        To start with setInterval is not that accurate. getTimer() is for checking but you can't expect an interval that precise to fire in my experience.

                        Give this a shot and you'll see:

                        var interval= 1;
                        var mySI_Test = setInterval(checkAccuracy,interval);
                        var calls=0;
                        var startTimer =getTimer();
                        function checkAccuracy(){
                        trace(calls+"="+(getTimer()-startTimer));
                        calls += interval;
                        if (calls>100) clearInterval(mySI_Test);
                        }


                        EDIT - oh I see you mean 50. Yes, that would make more sense.
                        • 9. Re: embarssing question
                          zibber Level 1
                          many thanks Kglad. One last question. The issue i have is that potentially the user will record and then use the playback function in one session. Currently when i use the script above in that manner all the sounds are played at once. I am assuming this is because the current time is greater than the time the sounds were "recorded". What is the best way of counteracting this in yuor opnion? I guess i need ot be removing the ongoing time against the time that the first siund was set, if that makes sense:|
                          • 10. Re: embarssing question
                            kglad Adobe Community Professional & MVP
                            no, the code above is just checking the time intervals relative to the startBtn begin pressed. there should be no sound overlap unless that was the way the sound were "recorded".
                            • 11. Re: embarssing question
                              zibber Level 1
                              hmmmmmm there does seem to be something odd going on. I have recorded and hardcoded the result sinto an array but all the sounds do seem to merge:

                              // set up arrays for time and sound objects
                              timeArray = new Array();
                              seqArray = new Array();


                              soundA = ["two","three","one"]
                              timeA = [1462,3788,8517]
                              //initial variables for recording
                              var recording:Boolean = false;
                              var startTime:Number;

                              //playBack()

                              //p = new Sound();
                              //s = new Sound();

                              tolerance = 100;

                              s = new Sound(this);

                              function playBack() {
                              ind = 0;
                              s.attachSound(soundA[ind]);
                              s.start();
                              ind++;
                              startTime = getTimer();
                              testI = setInterval(testF, 1);
                              };
                              function testF() {
                              currTime = getTimer();
                              interval = timeA[ind]-timeA[ind-1];
                              if (currTime-startTime<tolerance+interval || currTime-startTime>interval) {
                              startTime=currTime;
                              s.attachSound(soundA[ind]);
                              s.start();
                              ind++;
                              if (ind == soundA.length) {
                              clearInterval(testI);
                              }
                              }
                              }
                              • 12. Re: embarssing question
                                kglad Adobe Community Professional & MVP
                                my bad. the following should work and is more efficient:

                                • 13. Re: embarssing question
                                  zibber Level 1
                                  beautiful Kglad that seems to work much better! thank u for all of your help