0
\$\begingroup\$

I'm working on a Flash game and am trying to figure out how to repeat a sound periodically every 17 seconds. Instead, of having the sound repeat once the .mp3, .wav, finishes.

The problem I'm running into is the sound is repeating itself after the song finishes, and the timer isn't doing anything. I put the timer in the initTitle area because I'm working on my main menu, and then I initialize the sound, and read if the sound finishes. How can I get it so that sound repeats every 17 seconds?

    public function initTitle():void
    {
        initSoundThemeSong();
        initTitleWhooshSound();

        drawTitleBG(); 
        drawTitleLogo();
        drawTitleBGStars();
        drawTitleStart();

        titleWhooshTimer = new Timer ( 17000 );
        titleWhooshTimer.addEventListener( TimerEvent.TIMER, onTitleWhooshFinished );
        titleTimer.start();     
    }

    public function initTitleWhooshSound():void
    {
        titleWhoosh = new TitleSoundWhoosh();
        titleWhooshSoundChannel = titleWhoosh.play();
        titleWhooshSoundChannel.addEventListener( Event.SOUND_COMPLETE,
                                                  onTitleWhooshFinished );
    }

    public function onTitleWhooshFinished( event:Event ):void
    {
        titleWhooshSoundChannel = titleWhoosh.play();
        titleWhooshSoundChannel.addEventListener( Event.SOUND_COMPLETE, 
                                                  onTitleWhooshFinished );
    }

Thanks! :)

\$\endgroup\$
1
\$\begingroup\$

Computers are incredibly smart, and incredibly dumb; because they do exactly what you tell them to. For instance, you're telling it to play the sound when it finishes. =p

titleWhooshSoundChannel.addEventListener( Event.SOUND_COMPLETE,
                                                  onTitleWhooshFinished );

You have that line in several places in your code, but you should only need it on the timer. Since that method has a 'play()' command in it, it will do just that. I'm wondering if this will work correctly without an event listener to note when the sound is fully downloaded, too.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.