I'm really new to AS3. I could use a little help. I'm creating a flash application that I would love for it to start auto playing my (imported) music file (entitled MySound). I want a button for the option to stop the music, and then toggle for the option to start the music again. When the music is playing, I would love for my mp3 to loop.
I've managed to get the toggle and music playing to work. But the music only starts to play when the button is clicked on. I'm having trouble with the other features. Help?
toggle_btn.stop();
var clickOnce:uint=0;
var aSound:Sound = new MySound();
var aChannel:SoundChannel = new SoundChannel();
toggle_btn.addEventListener(MouseEvent.CLICK, togglePlay);
function togglePlay(event:MouseEvent):void {
clickOnce++;
if (clickOnce==1) {
aChannel=aSound.play();
toggle_btn.gotoAndStop(2);
}
if (clickOnce==2) {
SoundMixer.stopAll();
toggle_btn.gotoAndStop(1);
clickOnce=0;
}
}
aChannel.addEventListener(Event.SOUND_COMPLETE, soundCompleted);
function soundCompleted(event:Event):void{
toggle_btn.gotoAndStop(1);
}
togglePlay(null)at the end of all your code to have it start playing automatically (though be warned, users don't usually like auto playing sounds unless this is a game or something entertainment based) - BadFeelingAboutThis