Skip to main content
August 2, 2015
Answered

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

  • August 2, 2015
  • 1 reply
  • 2998 views

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.

This topic has been closed for replies.
Correct answer kglad

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.

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.

1 reply

kglad
Community Expert
Community Expert
August 2, 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

}

August 2, 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.

kglad
Community Expert
Community Expert
August 3, 2015

are you publishing an html5 document?

do you see any error messages?