views:

456

answers:

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.

+1  A: 

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
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
I changed the answer to control the maintimeline (_root).
Richard Inglis
thank you so much...
kwek-kwek