Copy link to clipboard
Copied
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.
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.
Copy link to clipboard
Copied
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
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
are you publishing an html5 document?
do you see any error messages?
Copy link to clipboard
Copied
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 5 | 1061: Call to a possibly undefined method addEventListener through a reference with static type Class. |
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Thanks That did it. Now it works.
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now