A Flash Developer Resource Site














Internet Commerce

Partners & Affiliates














Developer Channel

internet.com


Featured Flash FLA
Gallery Downloads 11337 Flash Movies | 1 New Flash Movies Added
What's New | Top 100

Featured FLA

» Author: Bugra Ozden
» Title: Skatalog v9 - product catalog
» Description: Create your product catalog easly and publish on your website or Create your image gallery, documents list, portfolio. Fully XML Driven
» More by Bugra Ozden


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

Featured Site

» Posted in the Flash Kit Links section
» Title: Creative DW Image Show PRO
» Description: Creative DW Image Show PRO is a Dreamweaver extension which enables the user to create multimedia presentations. It combines the features of the popular Creative DW Image Show with the ability to add professional text effects to slides (similar to After Effects). The product is very customizable: the user can choose the duration of the transition effects, the slide motion start and end position, zoom and panning type for both images and texts.


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

» Make a Flash Slide Show Screen Saver
» Simple flash making tutorial for thanksgiving
» Create flash banner for website
» Create xml slideshow with free template
» How to Insert a Multilingual Subtitle Into Your Flash Video Studio
» How to Create Cool Halloween Slideshow
» Debugging flash using the Firebug console
» Create Flash Slideshow on Blogger
» FLASH TRICKS IN WEB ADVERTISING: FLASH BANNERS
» Unknown Tag: Title10
Random Tutorial | Add Site

Sr Instructional Designer D2L-Moodle,Clearance
WSI Nationwide, Inc.
US-NJ-Fort Monmouth

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.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

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