actionscript-3flashactionscriptflash-cs6flash-cc

Looping sound in AS3


Trying to loop a background soundtrack while my flash program is in use.

So far my code is this:

//turn off sound
btnOff.addEventListener(MouseEvent.CLICK, fl_stopsound);

function fl_stopsound(event:MouseEvent):void
{
    SoundMixer.stopAll();
}

//turns sound on
btnOn.addEventListener(MouseEvent.CLICK, fl_ClickToPlayStopSound_1);

var fl_SC_1:SoundChannel;

//keeps track of whether the sound should be played or stopped
var fl_ToPlay_1:Boolean = true;

function fl_ClickToPlayStopSound_1(evt:MouseEvent):void
{
        var mySound:Sound = new background(); 
        mySound.play();
    }

where btnOff turns off the sound and btnOn turns on the sound. My soundtrack is 1:50min long. Is it possible to loop the track within the program with these buttons?

Cheers


Solution

  • Use mySound.play(0, int.MAX_VALUE);