Copy link to clipboard
Copied
hi there
i'm a bit of a novice when it comes to flash and as3 but I have manged to put together an animation with a voiceover. The voiceover plays along and parts of the animation correspond to what is being said in the voiceover so it's imperative that they play together.
I've managed to add a play and pause button which are working ok however the animation starts playing automatically when testing but the voiceover doesn't. You have to click the pause button foloowed by the play button to get the voiceover to play. Once that's done the play and pause buttons work perfectly. However, they voiceover and animation need to start at exactly the same time as the voiceover references the animation.
I hope I'm making sense!! I'm so close to getting this working but I just can't seem to figure this out. Any help would be much appreciated as I'm getting quite lost with as3!!
I have 3 layers in the flash file, one with the content (movieclip called dude), one with the play/pause buttons (go and halt) and the actionscript (see below).
import flash.events.MouseEvent;
var mySound:Sound = new voiceover();
var myChannel:SoundChannel = new SoundChannel();
var lastPosition:Number = 0;
var soundIsPlaying:Boolean = true;
go.addEventListener(MouseEvent.CLICK, startplaying);
function startplaying(event:MouseEvent):void{
dude.play();
if(!soundIsPlaying){
myChannel = mySound.play(lastPosition);
}
}
halt.addEventListener(MouseEvent.CLICK, stopplaying);
function stopplaying(event:MouseEvent):void{
dude.stop();
lastPosition = myChannel.position;
myChannel.stop();
soundIsPlaying = false;
}
I'd really appreciate any help as my deadline is looming and I'm so stuck on this last hurdle!
Thanks in advance
Try setting the soundIsPlaying value to false instead of true in the beginning of your code. In the start playing function the sound only starts if it is not playing, but by having that value set to be true at the start, it thinks the sound is playing...
if(!soundIsPlaying){ // is testing if the sound is NOT ( ! ) playing
Copy link to clipboard
Copied
Try setting the soundIsPlaying value to false instead of true in the beginning of your code. In the start playing function the sound only starts if it is not playing, but by having that value set to be true at the start, it thinks the sound is playing...
if(!soundIsPlaying){ // is testing if the sound is NOT ( ! ) playing
Copy link to clipboard
Copied
Thank you so much that works perfectly now
Copy link to clipboard
Copied
You're welcome