How to run two functions on timeline - Animate CC AS3
Hello,
I have two things going on in my animation.
#1 MovieClip on the main timeline, frame 1. Starts when clicking on "sound icon" button. Inside the MovieClip an audio sound file plays and other simple items play on the timeline.
#2 Yes/No answer buttons on the main timeline. Each button when selected plays a short audio file (correct/incorrect sounds),
Both functions need to work independently of each other. I've had no problems having them work properly in different files. However, combining two on the same timeline I have two problems:
1. When I click on Yes/No button they won't reset to their beginning position, they stop where I've added AS on that frame to "stop();"
2. Clicking on Yes button, then No button the audio file from the MovieClip plays, the actual animation doesn't play just the sound file. And it's only after Yes, then No is clicked in that order, which is the order they appear on the main timeline.
I'm pretty sure I'm missing something pretty easy here, if you have an idea for me to try could you indicate where it should be placed in the code please, I'm definitely not an expert, still learning. Much appreciated! Here's the code I'm using:
* sound icon play/stop/restart button */
var playing:Boolean = false;
MovieClip.stop();
function startMovieClip(event:MouseEvent):void
{
if(MovieClip.currentFrame == MovieClip.totalFrames) {
playing = false;
}
if(playing){
MovieClip.gotoAndStop(1);
} else {
MovieClip.gotoAndPlay(1);
}
playing = !playing;
}
startButton1.addEventListener(MouseEvent.CLICK, startMovieClip);
/* Correct answer sound button
Click to Go to Frame and Play
Clicking on the specified symbol instance moves the playhead to the specified frame in the timeline and continues playback from that frame.
Can be used on the main timeline or on movie clip timelines.
*/
stop();
No_Btn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame);
function fl_ClickToGoToAndPlayFromFrame(event:MouseEvent):void
{
gotoAndPlay(16);
}
/* Incorrect answer sound button */
Yes_Btn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame_4);
function fl_ClickToGoToAndPlayFromFrame_4(event:MouseEvent):void
{
gotoAndPlay(2);
}