A Flash Developer Resource Site














Internet Commerce

Partners & Affiliates














Developer Channel

internet.com


Featured Flash FLA
Gallery Downloads 11246 Flash Movies | 9 New Flash Movies Added
What's New | Top 100

Featured FLA

» Author: Andrey LosskutnikOff
» Title: 3D Mazda
» Description: just so 3D car
» More by Andrey LosskutnikOff


Random FLAs | Add Flash Movie
Featured Flash Site
Gallery Downloads 6413 Flash Sites | 0 New Flash Links
What's New | Top 100 Flash Site

Featured Site

» Posted in the Flash Kit Links section
» Title:Pinwheel
» Comments: Pinwheel is a full-service graphic design studio in San Francisco specializing in packaging, print, and interactive website design


Random Links | Add your own Flash Related Links
Flash Tutorials 1192 Tutorials 7 New Tutorials Added!
What's New | Top100

» How to convert FLV video to MP3 audio for Mac OS
» Join flv videos together with just a few clicks
» How to convert flv file to avi for mac os x
» How to Create Christmas Flash Greeting eCard without programming skills
» How to Create Real Estate Flash Photo Gallery Presentation
» How to burn DVD, VCD, SVCD
» How to convert FLV to ASF with FLV to ASF converter for Mac os X
» 5 ways to convert PowerPoint to video
» How to Make Vista Buttons
» Unknown Tag: Title10
Random Tutorial | Add Site

bbm.netBBM.net is designed to save you time and deliver the highest quality royalty-free music for your multimedia projects. Features include: over 450 Music Loop Packages from some of the best composers in the business, our music search engine to speed your selection process, alternate music versions & bonus sounds to use for rollovers or transitions, free technical support and free consulting.

Click here for details »

Graphic Designer
Aquent
US-CA-Sausalito

Justtechjobs.com Post A Job | Post A Resume


Tutorials Home What's New Top Rated Submit myTutes Random!

Search Tutorials


Tutorials Tutorials » Actionscripting

Categories Using variables to control movie clips
Author: Bryan Gaffin | Website: www.bryangaffin.com |

 
Page 1
1

USING VARIABLES TO CONTROL CLIPS

by Bryan Gaffin
bsg@bryangaffin.com

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

Enjoy!

1

» Level Intermediate

Added: : 2002-04-18
Rating: 8.41 Votes: 105
Hits: 3718
» 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.
Download (18 kb)
Get conversion and unzipping tools for PC and Mac here!

» Forums
More help? Search our boards for quick answers!

Please rate this tutorial, 10 is the top rating, you can also click the comments link to read/write a review.
10 9 8 7 6 5 4 3 2 1
Read or Post Comments
 
   
 

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers