Bouncing Ball!

else if

Now that we have our ball moving up, we need it to move back down again once it hits the top. We could run another if statement, this time checking if ball.y<boundaryTop That would work, but it's a bit unnecessary since we just checked if ball.y>boundaryBottom It can't be both at the same time!

The answer is to use an else if statement. Flash will only run this statement if the original if statement is false:

If the Y position is less than the top boundary, we want Flash to reset the value of speed to be a positive number. Since that's the only thing we want it to do, we close the else if statement with a right brace:

Check it out; a real bounce at last:

Content on this page requires a newer version of Adobe Flash Player.

Get Adobe Flash player