0
votes

I have a 240 frame animation with sound. The sound file is inside my library.

I have 2 buttons. Play/pause, and Stop.

The video autoplays, and you can pause and resume no issue. You can even hit Stop (which clears the video, but you can hit play again and it starts from the beginning).

My issue is that if you let the animation play all the way to the end, the play button does not start back at the beginning. I had a line of code or 2 changed recently, and before it WOULD go back, but there would be 2 instances of audio. I feel like I am so close, and someone else might be able to point out the issue, I'm sure it may be very small. Here is my code.

Frame 1 Actions:

import flash.events.MouseEvent;

var audioPosition:Number = 0; /* Pause Point */

var isJamming:Boolean; //true or false checking whether sound is playing

var snd0:Sound = new snd();
var soundChannel:SoundChannel = new SoundChannel();
PlayBtn.addEventListener(MouseEvent.CLICK, clickPlayPause);

soundChannel = snd0.play();
isJamming = true;



function clickPlayPause(evt:MouseEvent) {   


if(currentFrame == 1){
    audioPosition = 0.00;
gotoAndStop(1);
flash.media.SoundMixer.stopAll();
    play();
        soundChannel = snd0.play(audioPosition);
        isJamming = true;
} else if (isJamming) {
        stop();
        audioPosition = soundChannel.position;
        soundChannel.stop();
        isJamming = false;
    }   else {
        play();
        soundChannel = snd0.play(audioPosition);
        isJamming = true;
    }       
}



CloseBtn.addEventListener(MouseEvent.CLICK, close);
    function close(Event:MouseEvent):void {
    audioPosition = 0.00;
    gotoAndStop(1);
    flash.media.SoundMixer.stopAll();
}

Frame 240 Actions:

audioPosition = 0.00;
gotoAndStop(1);
flash.media.SoundMixer.stopAll();
2

2 Answers

1
votes

you have 2 snd0.play() s in the code. remove the first one. (after PlayBtn.addEventListener(MouseEvent.CLICK, clickPlayPause); line)

0
votes

I fixed my issue. Csomakk helped with one part, and then I figured out I needed to change my if current frame to the LAST frame, as opposed to frame 1. I also changed my closeBtn and Last frame scripts to gotoAndStop(241); as opposed to stopping on 1.

Everything works now!