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

How stop an animation and make it continue on button click.

New Here ,
Aug 02, 2015 Aug 02, 2015

Ok... I've been out of the loop with flash lately and I only know how to use action script 2 (and even that on a basic level). I'm more of an animator than a programmer.

So what I want to do is:

Create a simple animation that will start (i.e go to the second frame) when you push a button symbol that's been placed on the stage.

So I put this in to the first frame:

import flash.events.MouseEvent;

stop();

start_button.addEventListener (MouseEvent.CLICK, onClick);

function onClick(event:MouseEvent):void

{

  gotoAndPlay(2);

}

But the animation doesn't stop. It only stops when if I define the event directly to the stage (stage.addEventListener (MouseEvent.CLICK, on click);). But that allows you to click anywhere on the stage to make the animation play out. What am I doing wrong? Thank you for any answers in advance.

TOPICS
ActionScript
2.8K
Translate
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

Community Expert , Aug 03, 2015 Aug 03, 2015

if you see a compiler error message, no code executes in your project.

you must fix your error message.  change the instance name (in the properties panel) of your start button to start_btn and use that (start_btn) in your code.

Translate
Community Expert ,
Aug 02, 2015 Aug 02, 2015

use:

import flash.events.MouseEvent;

stop();

start_button.addEventListener (MouseEvent.CLICK, onClick);

function onClick(event:MouseEvent):void

{

nextFrame();  // if you want to go to frame 2 and stop

play();  // if you want to go to frame 2 and play

}

Translate
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
New Here ,
Aug 02, 2015 Aug 02, 2015

That didn't solve my problem sadly. The animation still doesn't stop at the first frame but just keeps playing regardless if I press the button or not. It's like it's ignoring the stop(); command.

Translate
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 ,
Aug 03, 2015 Aug 03, 2015

are you publishing an html5 document?

do you see any error messages?

Translate
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
New Here ,
Aug 03, 2015 Aug 03, 2015

No. I am exporting it to swf.

After checking...

The code I used was:

import flash.events.MouseEvent;

stop();

start_button.addEventListener (MouseEvent.CLICK, onClick);

function onClick(event:MouseEvent):void

{

play();

}

and the error read:

Scene 1, Layer 'Layer 1', Frame 1, Line 51061: Call to a possibly undefined method addEventListener through a reference with static type Class.
Translate
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 ,
Aug 03, 2015 Aug 03, 2015

if you see a compiler error message, no code executes in your project.

you must fix your error message.  change the instance name (in the properties panel) of your start button to start_btn and use that (start_btn) in your code.

Translate
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
New Here ,
Aug 03, 2015 Aug 03, 2015

Thanks That did it. Now it works.

Translate
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 ,
Aug 03, 2015 Aug 03, 2015
LATEST

you're welcome.

Translate
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