1

Im new to this flash and I am using as2 for the action script I wanted to know if there are any good tutorials on how to create a toggle button so far this is all I have.

on (release) {
play ();
}

on (release) {
stop ();
}

I wanted so that when you hit playit would start the animation but showing the pause button and vice versa.

kwek-kwek
  • 1,343
  • 3
  • 19
  • 34

1 Answers1

1

You need to keep track of the state of your toggle: ie whether the animation is playing or not when the button is pressed.

So the code on your button might be:

on (release){
_root.toggleMe();//assuming you want to start/stop the main timeline
}

And then in the main timeline, you could define the toggleMe() function like this:

var isPlaying:Boolean = false; // track state of animation - paused to start

function toggleMe():Void {
    if (isPlaying) {
        stop();
        isPlaying = false;
    } else {
        play();
        isPlaying = true;
    }
}

stop();

[EDIT: changed the code to control the main timeline]

Richard Inglis
  • 5,888
  • 2
  • 33
  • 37
  • The movie I wanted to control is not inside of a movie clip it is on the _root and the button will be inside of a movieclip? I all new to this so probably an idiot proof instruction would make sense for me.. Thank you and Im sorry – kwek-kwek Jan 27 '10 at 18:24
  • I changed the answer to control the maintimeline (_root). – Richard Inglis Jan 27 '10 at 21:40