Hi all… this is the one code that I could make work, but I need it so the music plays at start and then the button will pause/stop it, and then turn into a play graphic which, when pressed, will play it again. I tried editing the code, but I am horrible at programming and of course nothing I tried worked. Please let me know what I have to change to start with music playing, and then have it stop/pause on first press, and alternate “play” and “stop” on subsequent presses. Thanks!
[My fla has 2 layers, one for this AS, and one for the buttons... within the symbol section, I have two layers, one for the button common BG, and two frames in the button layer, one for play (triangle) and one for stop (square). They are saved as a movie clip.]
If need be the tutorial for this button is at (remove all the “$” signs and spaces… I do not have enough posts yet to post urls)
flashperfection. c $o$m/$tutorials/$Toggle-sound-button-in-Actionscript-3-18231. h $t$m $l
THANKS!
//This stops the toggle buttons from playing the second frame.
toggle_btn.stop();
//Variable to detect whether the number of times the toggle button has been clicked.
var clickOnce:uint=0;
//Creates a new instance of the imported sound.
var aSound:Sound = new MySound();
//Create a new instance of the SoundChannel
var aChannel:SoundChannel = new SoundChannel();
//This adds the mouse click event to the toggle button.
toggle_btn.addEventListener(MouseEvent.CLICK, togglePlay);
//If the toggle button has been clicked once then the sound plays
//with an image of a stop symbol. If the toggle button is clicked
//again then sound stops and the play symbol is displayed.
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;
}
}