1. About.com
  2. Computing & Technology
  3. Animation

Discuss in my forum

Flash Animation 17: Controlling Movie Clips With Buttons and ActionScripting

By , About.com Guide

Adding Button Commands to Control the Movie Clip
Flash Animation 17: Controlling Movie Clips With Buttons and ActionScripting
Since we animated the hat, we need to associate it with the button that says "Hat". Right-click on that button and select Actions. With the Actions window in Expert Mode (click the blue arrow in the upper right-hand corner and select Expert Mode), enter the following code:

on (release) {
ShortHat.gotoAndPlay(2) ;
}

You already know how the on (release) and gotoAndPlay commands work; we've told the button that when the mouse click releases, it needs to go to and play frame 2 (frame 1 has a stop on it, remember, so starting on frame 2 will play the animation). This difference is that in previous instances, we've told it to go to and play frame 2 of the current scene, or another scene; this time, we're directing it to an entirely separate timeline nested inside a movie clip. The part of the code that does that is:

ShortHat.

Adding this parameter before the gotoAndPlay command (the period acts as a separator) tells Flash that it needs to access the timeline inside the instance ShortHat of the movie clip HatShort, and then play from there.

And it's that simple. To see a demonstration of just the animated hat, click here.

©2012 About.com. All rights reserved. 

A part of The New York Times Company.