First time here? First time here? Newsletter Signup Newsletter
Search tutorials
Author: Bryan Gaffin | Website: http://www.bryangaffin.com


by Bryan Gaffin

How do you make menu clips close when you open new ones? Or ever go to a site and press every button at once to see what would happen? Most times, every clip or menu will pop open and stay there. Yuk.

The answer: don't use buttons to activate clips. Use them to change variables. Then make each and every clip do what it is supposed to, but only when the variable is the one the clip is looking for.

Very easy:

STEP 1: button commands:

On the stage make as many buttons as you want and put as the action in the first button:

on (release) {
    if (Number(test) == 1) {

        test = 0;

    } else {
        test = 1;



in every subsequent button, change the numbers, so in button 2 it should be:
on (release) {
    if (Number(test) == 2) {

        test = 0;

    } else {
        test = 2;



note: the "if" portion is to check to see if the clip is already playing/open. If so, you'd want it to close if someone clicked the button again, right? So setting the variable to 0 will close all clips. If you don't want this, just eliminate the if statement and type:

on (release) {

    test = 1;

STEP 2: clip actionscript 1- activating the clip

In the clips, the clip's job is to always be on the lookout for the variable that it is programmed to accept. So in the first 2 frames of clip 1 (which is waiting for button 1 to be pressed), create a loop. In the first frame type:

if (Number(_root.test) == 1) {

    gotoAndPlay ("goclip1");


where "goclip1" is the name of the 3rd frame. In the second frame type:

gotoAndPlay (1);

This sets up the loop. As long as "test" equals anything but 1, the clip will not activate. But when the variable "test" becomes 1,the clip goes to frame 3 ("goclip1") and plays the animation.

STEP 3: clip actionscript 2- closing the clip

When the variable changes, there has to be a way to close the clips that don't correspond to the variable's new number. So instead of a stop action on the frame after the clip opens, create another 2 frame loop. And in the first frame, called "loopframe1" type nothing. In the next frame, type:

if (Number(_root.test) == 1) {
gotoAndPlay ("loopframe1");

As long as "test" remains 1, the clip will stay open and not appear to change, but if the value is no longer 1, then clip continues to play past this frame, and closes the animation.

All you have to do now is change the numbers in all the clips and buttons to make them do what you want, and you are done. This can be a very powerful and very easy thing to use.

Any questions, or helpful advice, contact me at bsg@bryangaffin.com

» Level Intermediate

Added: 2002-04-18
Rating: 8.02 Votes: 108
(10 being the highest)
» Author
Bryan Gaffin is a Senior Art Director with experience in traditional design and advertising, who made the switch to new media 2.5 years ago.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!


  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops
Image for equalize

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.