Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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! :)

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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