Skip to main content
SheaB
Inspiring
January 15, 2018
Answered

How to run two functions on timeline - Animate CC AS3

  • January 15, 2018
  • 1 reply
  • 2631 views

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);

}

This topic has been closed for replies.
Correct answer Colin Holgate

Here is the correct file, my apologies.

Sample_Play-Pause-Play_YesNo 01-18-2018.fla - Google Drive


It seems like there is a bug in connection with having sound in the first frame of a MovieClip that is in the first frame of the main timeline. Either way, if you move the Row music to start on frame 2, things work ok.

1 reply

kglad
Community Expert
Community Expert
January 18, 2018

don't use MovieClip for an instance name.  that's a reserved word (like the word function).

SheaB
SheaBAuthor
Inspiring
January 18, 2018

Are you just giving me general advice on my AS? It's updated but that didn't resolve the issue.

SheaB
SheaBAuthor
Inspiring
January 18, 2018

* sound icon play/stop/restart button */

var playing:Boolean = false;

Row.stop();

function startRow(event:MouseEvent):void

{

    if(Row.currentFrame == Row.totalFrames) {

         playing = false;

   }

    if(playing){

           Row.gotoAndStop(1);

    } else {

           Row.gotoAndPlay(1);

    }

    playing = !playing;

}

startButton1.addEventListener(MouseEvent.CLICK, startRow);

/* 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);

}