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: Gurgen Tagvorian
» Title: Perpetuum Mobile
» Description: It's just a Perpetuum Mobile for you
» More by Gurgen Tagvorian


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

Featured Site

» Posted in the Flash Kit Links section
» Title: Atlantis Media Ltd
» Comments: Greg Rudman new media creative & website design - Atlantis Media Ltd


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 »

Senior Web Analytics Engineer
Professional Technical Resources
US-OR-Beaverton

Justtechjobs.com Post A Job | Post A Resume


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

Search Tutorials


Categories How to make a toggle button
Author: Muhammad Yahya | Website: www.yahya3d.tk |

 
Page 3
«prev 1 2 3

7.
You, most probably, already have the sound AS on this frame if you have done the first tutorial. So your complete script on this frame will look something like this:

// declare a global variable
var s = 1;
// initiate sound
music = new Sound();
music.attachSound("backsound");
music.start(0, 999999);
// set the volume of the sound to zero
music.setVolume(0);
// set a variable named 'vol'
vol = 0;
// set another variable named 'fade', putting a setInterval function in it
fade = setInterval(fadeIn, 100);
// set the initial fade in function
function fadeIn() {
// fade the sound in with an increment of 3 in the variable 'vol'
vol += 3;
music.setVolume(vol);
// put an if condition to restrict the increment in volume after it reaches to 100
if (vol>=100) {
clearInterval(fade);
// create the 'step' variable
step = 1;
// create the 'fade' variable
Fade = 0;
}
}
// create the fade in and out function
// function executed on onEnterFrame
_root.onEnterFrame = function() {
// set fade out
if (Fade == 1) {
vol = vol-step;
if (vol<0) {
vol = 0;
}
music.setVolume(vol);
// set fade in
} else {
vol = vol+step;
if (vol>100) {
vol = 100;
}
music.setVolume(vol);
}
};

The global variable will help the play head move appropriately.

8.
Keeping in mind that the value of the global variable 's' is 1, select the movieclip on the stage and double click it... you will be in what is called an "edit in place space". Select the invisible button and open the AS panel. Like I said before that I assume that you have already done the previous tutorial so these actions should be there already:

on (release) {
// set the function for variable value toggle
(_root.fade=!_root.fade) ? 0 : 1;
}

Now you need to put an if condition in there. The if condition will determine the playhead movement. The complete AS on this button will look something like this:

on (release) {
// set the function for variable value toggle
(_root.fade=!_root.fade) ? 0 : 1;
// put an if condition to tell the playhead to goto
// the frame from where the play button starts fading in
// as we have pressed the button to stop the sound
// we have already set the value of the variable s to 1
// thus the playhead moves to frame 2 where it starts fading
// the play button in and the stop button out
if (_root.s == 1) {
tellTarget (this) {
gotoAndPlay(2);
// now you aobviously have to set the variable's value
// to 0, so that the next time you click the button
// the playhead moves to the 46th frame where the stop
// button starts fading in
_root.s = 0;
}
} else {
// else block executes when the varianle s is equal to 0
// when you click the button for the first time it sets the
// value of this variable to 0
// so the next time you click this button
// this else block executes
tellTarget (this) {
gotoAndPlay(46);
// now set the value of the var s to 1 again so that
// the next time this button is clicked the block with
// if condition can execute
_root.s = 1;
}
}
}

The global variable 's' plays vital part in all this. By this method you can create a toggle button for anything.

This business is really hard to explain I must confess!! I have explained the action script line by line, putting comments in it and with the help of the source file you should be able to grasp it all. Still if you thing you are confused a bit or want to discuss something.... mail me. I'll be more than happy to help you out!

©2003 yahya3d.tk

«prev 1 2 3

» Level Intermediate

Added: : 2003-10-29
Rating: 5.57 Votes: 7
Hits: 2109
» Author
Muhammad Yahya Cheema. 3d/2d artist.
» Download
Download the files used in this tutorial.
Download (124 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