Flash Actionscript Tutorial 2 - If Statements
Hey guys, this is Maaz1. Today I'm going to be doing a flash action script tutorial number two. It's a follow-up of tutorial number one.
So I'm going to be teaching you how to make a button to toggle playing and pausing for an animation. This is going to be one button, unlike the first tutorial, which had two buttons.
First of all, you're going to want to make a button. Make a new layer. On the new layer, draw a button, select it, and convert it to a symbol. The type should be button, registration should be center.
What you want to do is go into properties. Right? I'm going to name my button "toggle button." Then you're going to want to open up the actions of the layer. Do this by right-clicking on the frame.
You're going to want to set up a variable: var u Boolean = true
. The Boolean type of variable means true or false. So then, you're going to put the if statement inside of an on release.
You're going to do toggle button on release = function() {
. Open the curly brace. Then you're going to do if Fu
, which implies if Fu
equals true. But you don't have to; you can omit that.
Then root.stop()
, and then root.Fu = false
. So, what "root" means is that it goes—the root is the main timeline, which is what you're looking at right here. If it's inside of a button or a movie clip, you want to specify root so that it does it from the main timeline and not from the movie clip or button.
So then you want to do else {
. Open the curly brace. root.play()
, and root.Fu = true
.
So now, if we test this, we press the button, and it pauses. Then we can press the button again, and it plays.
So, thanks for watching! M cu one, subscribe and goodbye!