Ok...another AS3 question for anybody who wants to take a crack at it.
I have a number of random sounds imported to frames on the movie clip timeline. I have a timer code that will go to and stop on random frames thus playing the sound (the timer is set long enough to let the sounds play in full before going to the next one). I'll show you the code then I'll tell you my problem:
//AS3 timer setup
var soundDelay:Timer = new Timer(3000);
var sound_number : Number = 9;
var randomFrame:Number = Math.floor(Math.random() * sound_number);
It works fine! At first. From the trace I thought the frames seem to be multiplying exponentially, then I realized every time the animation on the main timeline loops the timer starts all over again causing the sound to begin to overlap.
So I guess my question is how do I reset the timer at the end of the animation to prevent it from starting all over again and causing the sounds to overlap?
I know I need to use .stop();
to stop the timer, but I need to make sure it doesn't stop untill it reaches the last frame in the root timeline.
All of the tips I've researched are for using button events to start and stop the animation, but I want it to function based on frame numbers.
I can sense I'm so close to the answer, but it's late, I'm tired.
(I know you've probably got some questions about why I put sound in the timeline instead of using the loadSound
commands. I'm just goofing around. I want to learn to use this method for other things as well.)