0
votes

I have a flash video that is short, has sound, and I've got Play Pause and Stop buttons.

Without sound, it works perfectly. It autoplays, you can hit pause and it pauses, and play resumes where it leaves off. Hitting stop goes to an empty frame if someone wants to turn it off.

I have audio inside my library, and would like connect the audio with the same elements. I've been researching for awhile now, and I've not come up with a solution yet, and having a hard time.

Here is my ActionScript code for my currently working buttons:

StopBtn.addEventListener(MouseEvent.CLICK, stopplaying);
function stopplaying(Event:MouseEvent):void {
    stop()
}

PlayBtn.addEventListener(MouseEvent.CLICK, startplaying);
function startplaying(Event:MouseEvent):void {
    play()
}

CloseBtn.addEventListener(MouseEvent.CLICK, close);
function close(Event:MouseEvent):void {
    gotoAndStop(240)
}
1

1 Answers

1
votes

You should use Sound and SoundChannel to do this. And for pause you'll have to save the current play position so that you can continue from there:

var audio:Sound = new audioFromLibrary(); //linkage name
var soundChannel:SoundChannel = new SoundChannel();
var audioPosition:Number = 0;

//PLAY:
soundChannel = audio.play(audioPosition);

//PAUSE:
audioPosition = soundChannel.position;
soundChannel.stop();

//STOP:
soundChannel.stop();