Creating A PLAY Button with ActionScript 3.0

Add an Event Listener

Now that we created the playTimeline function, we have to specify when we want to run it. We're going to reference a button with an instance name bPlay, then get ActionScript to "listen" for a user to click that button. The script starts like this:

bPlay.addEventListener(

There are many different kinds of "events" in the ActionScript world, so we need to declare the specific event we want to listen for:

bPlay.addEventListener(MouseEvent.CLICK,

Finally, we tell ActionScript we want it to run our playTimeline function:

bPlay.addEventListener(MouseEvent.CLICK, playTimeline);

Confused? Don't worry if you are. After a few times this will all be second nature to you. Check out the coding as it happens, and pay close attention to the elements that turn blue:

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

Get Adobe Flash player

You'll also notice I added this line between the two existing blocks of ActionScript. This is not necessary for the project to run properly, but it's a way to keep our script organized. As we continue with ActionScript, you'll grow to appreciate a consistent programming pattern.