• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to run two functions on timeline - Animate CC AS3

Participant ,
Jan 15, 2018 Jan 15, 2018

Copy link to clipboard

Copied

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

}

TOPICS
ActionScript

Views

2.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jan 19, 2018 Jan 19, 2018

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.

Votes

Translate

Translate
Community Expert ,
Jan 18, 2018 Jan 18, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 18, 2018 Jan 18, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 18, 2018 Jan 18, 2018

Copy link to clipboard

Copied

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

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 18, 2018 Jan 18, 2018

Copy link to clipboard

Copied

if you're seeing any problems with Row, make sure it exists on frame 1 or 2 or your main timeline and is never removed.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 18, 2018 Jan 18, 2018

Copy link to clipboard

Copied

The movieclip is on the 1st frame. I tried both having it ONLY on the first frame and just a static image on remaining frames and then the image below is the movieclip on all 35 frames. I'm sure this is something simple but when the Yes button is clicked the movieclip sound file plays, it does not play the animation it just plays the sound. If you have any idea how I can upload the file or swf I'd be happy to do it.

FYI - AS posted above is on frame 1 only, the AS on frame 15 & 35 is just "stop();"

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 19, 2018 Jan 19, 2018

Copy link to clipboard

Copied

Row is the object in your Movie Clip layer?

there's actionscript on 3 different frames.

is all the code you're showing on frame 1?

is there any code (other than play(), stop() or goto's) on the other 2 frames?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 19, 2018 Jan 19, 2018

Copy link to clipboard

Copied

I'm not sure what you mean by object in Movie Clip layer, see original post, I had the instance name of the Movie Clip "MovieClip" you indicated it shouldn't be called that so the Movie Clip instance name is now "Row". I'm guessing that's what you mean by object?

Yes, there's AS on 3 different frames.

As indicated previously, yes all the AS listed above is in Frame 1 except I have added "stop();" on Frame 15 & 35

No other code on Frame 15 & 35 except "stop();" all the code above (for play, stop, goto) is only on Frame 1

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 19, 2018 Jan 19, 2018

Copy link to clipboard

Copied

I tried your code (changing "MovieClip" to a valid instance name on stage) in a FLA structured almost like yours and I got a basic navigation with the sounds playing.

I'm not sure of what you are not being able to do.

Would you mind sharing your FLA through Google Drive, Dropbox, WeTransfer, or something like this?

Regards,

JC

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 19, 2018 Jan 19, 2018

Copy link to clipboard

Copied

Thank you, happy to share my sample. Here are the files for .fla and .swf. In this example the movie clip works no problem. The sound and animation works as I want it to (when the play button is clicked bar turns pink and sound plays).

The Yes/No buttons work sort of, when the Yes button is clicked it plays the "try again" sound correctly however, it also plays the audio from the play button movie clip (Row).

I've done these two different things on their own but never tried to combine them on the same page so I may have messy AS that is not correct. I'm not sure how to make them both work independently of each other any suggestions are appreciated!

https://drive.google.com/file/d/1YVMRk9w95KFrvio-xx38BNi-2FQdNgoO/view?usp=sharing

https://drive.google.com/file/d/1VEGnhXmJEuWsTAHrzx5gwAmgZMh23EJ6/view?usp=sharing

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 19, 2018 Jan 19, 2018

Copy link to clipboard

Copied

recheck the fla you uploaded.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 19, 2018 Jan 19, 2018

Copy link to clipboard

Copied

recheck what on the .fla? here is the link:

https://drive.google.com/open?id=1YVMRk9w95KFrvio-xx38BNi-2FQdNgoO

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 19, 2018 Jan 19, 2018

Copy link to clipboard

Copied

download your fla and see if that's what you intended to upload.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 19, 2018 Jan 19, 2018

Copy link to clipboard

Copied

Here is the correct file, my apologies.

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 19, 2018 Jan 19, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 19, 2018 Jan 19, 2018

Copy link to clipboard

Copied

LATEST

https://forums.adobe.com/people/Colin+Holgate  wrote

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.

Ahhh... Thank you sir! That works. Much appreciated.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines