Skip to main content
Participant
July 7, 2011
Answered

Noobish question...beyond belief ^_^

  • July 7, 2011
  • 2 replies
  • 807 views

Basically, I am really new to ActionScript

I have tried to Google this but all results are for resetting variables, fields and other code-related things. I am trying to find an answer via the animation part of Flash for this question:

How can I restart my animation? (well, the file anyway.)

I mean, pretty much like closing+opening the file again, you know.

Secondly, um, (since I am new to ActionScript this is gonna be really bad code ^_^) why isn't this code working?

var has_pressed:Boolean;

has_pressed = false;

Button1.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);

function fl_MouseClickHandler(event:MouseEvent):void

{

has_pressed = true;

}

if(has_pressed == false)

{

stop();

}

The stop(); part of it works fine!

But even when I click on Button1, it still stops the animation , or at least it isn't working.

That code is supposed to basically stop the animation until the button is pressed.

Um, I guess there might be another way to do it, but it practically is a 'play' button.

Either my code is wrong, or the entire idea is wrong.

Thanks to answerers of both my messages! (PS: I do know C# and JavaScript so I am not a complete noob at coding - just Flash is a new experience)

Many thanks indeed!

This topic has been closed for replies.
Correct answer

I'm not sure what you are asking about restarting your animation. It sounds like you are using the timeline, so basically a gotoAndStop(1); or a gotoAndPlay(1); will replay the timeline.

var has_pressed:Boolean;

has_pressed = false;

Button1.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);

function fl_MouseClickHandler(event:MouseEvent):void

{

has_pressed = true;

}

if(has_pressed == false)

{

stop();

}

If you are controlling a movie clip, it's probably better to place a stop() on frame 1 inside the clip itself. If you're controlling the main/current timeline then first remove the if test and just stop() the timeline. There's no need for the boolean at all actually... when you click then just issue a play()

Button1.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);

function fl_MouseClickHandler(event:MouseEvent):void

{

     gotoAndPlay(1);

}

stop();

2 replies

Ned Murphy
Legend
July 7, 2011

The button is not a play button by any reasoning... you would need to add a play() command to its event handler to make it so.  The conditional at the end of your code will only execute once immediately upon entering the frame, it is not sitting waiting for a change to the has_pressed variable to happen.  It executes long before you can click that button to change the value.  Since you set the value to false in that frame, and the conditional sees it as such, it will always stop in that frame.

Participant
July 7, 2011

I see, thanks both of you!

Correct answer
July 7, 2011

I'm not sure what you are asking about restarting your animation. It sounds like you are using the timeline, so basically a gotoAndStop(1); or a gotoAndPlay(1); will replay the timeline.

var has_pressed:Boolean;

has_pressed = false;

Button1.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);

function fl_MouseClickHandler(event:MouseEvent):void

{

has_pressed = true;

}

if(has_pressed == false)

{

stop();

}

If you are controlling a movie clip, it's probably better to place a stop() on frame 1 inside the clip itself. If you're controlling the main/current timeline then first remove the if test and just stop() the timeline. There's no need for the boolean at all actually... when you click then just issue a play()

Button1.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);

function fl_MouseClickHandler(event:MouseEvent):void

{

     gotoAndPlay(1);

}

stop();