First time here? First time here? Newsletter Signup Newsletter
Search tutorials
Author: Muhammad Yahya | Website: http://www.yahya3d.tk

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.start(0, 999999);
// set the volume of the sound to zero
// 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;
// put an if condition to restrict the increment in volume after it reaches to 100
if (vol>=100) {
// 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;
// set fade in
} else {
vol = vol+step;
if (vol>100) {
vol = 100;

The global variable will help the play head move appropriately.

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) {
// 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) {
// 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

» Level Intermediate

Added: 2003-10-29
Rating: 4.89 Votes: 9
(10 being the highest)
» Author
Muhammad Yahya Cheema. 3d/2d artist.
» 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.