First time here? First time here? Newsletter Signup Newsletter
Login | Register | 651326 Members and growing!
Search tutorials
Author: Muhammad Yahya | Website: http://www.yahya3d.tk

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

» 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!

Comments

  • 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: work2survive
» Title: Girl Walking 1kb
» Description: Walking girl, animation just takes 1kb, using high heels shoes, and fashion model attitude.
Featured Sound Loops
Image for equalize

Audio Player

» Author: BoxCat
» Title: CPU Talk
» Description: From the cyberpunk RPG, "Nameless: the Hackers" Completely Free to use! Keywords: edm hip hop rap electronic mysterious mission hacking chase exciting spy ios ambient chilling love happy sad angry suspense
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: nathan
» Description:

A recorded sound of the Dimensional Fork Gate.