Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Weird sound problem...

Status
Not open for further replies.

michanagel

Technical User
Jun 23, 2007
34
US
Hi everybody,

I have weird sound issues over here that I can't seem to figure out...

I use an Interval to fade in a specific sound with this code:

Code:

_root.sound_theatre = new Sound(sound_theatre_mc);

_root.sound_theatre.attachSound("sound_theatre");

_root.sound_theatre.start(0, 1000000);

level = 0;
_root.sound_theatre.setVolume(level);

var level_in_interval:Number = setInterval(fadeInSound, 10, _root.sound_theatre);


// this is the sound fade in function
function fadeInSound():Void {
level += 1;
_root.sound_theatre.setVolume(level);
if (level == 100) {
clearInterval(level_in_interval);
}
}

Now when the user presses a specific button, the sound is supposed to fade out with this code (that is assigned to a keyframe on timeline where the movie jumps to when the user presses that specific button):

Code:

var level_out_interval:Number = setInterval(fadeOutSound, 10, _root.sound_theatre);

function fadeOutSound():Void {
level -= 1;
_root.sound_theatre.setVolume(level);
if (level == 100) {
clearInterval(level_out_interval);
}
}

Problem is: when the user presses that button very quickly - before the first interval is finished - the second interval runs through and fades out the music, but then still the first interval fades in the music again...

How can I kill that first Interval / function while it's still in process ?

Are there any other options to fade in a soundfile via actionscript besides the interval option ?

Thanx for your help in advance !!

Mike
 
Kenneth,

thanx for replying.

That button doesn't directly affect the sound function. It makes the timeline jumps to a specific keyframe and then (a few frames later) I placed an action script keyframe to control the fading out...

That '0' is a typo in my post... It's zero in my code in the file...

anyways, the problem lays somewhere else...

This sound code is only makes problems in my 'sections' which are loaded into an empty container (movieclip holder).

So the code works fine the first time, but when u go to a different section and then return to a section that has run the code already, THEN the code makes problems turning the volume way over 100 without stopping, not fading out, etc. ...
 
As I said, clear the Intervals before you set one. Also set a flag when you create an Interval, and then de-flag when the volume reaches 100/0 . When the flag is up do not create a same Interval.

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top