I made this object to take care of this autofade. You init it with the sound mc and update interval i ms. You can then call it with (target volume, length of fade time and delay) Hope you find it usefull: class SoundAuto extends Sound{
private var intervalId:Number private var targetFadeVal:Number private var startFadeVal:Number private var fadeStep:Number private var updateFreq:Number public var onFadeChange:Function function SoundAuto(pMc:MovieClip, pUpdateFreq:Number){ super(pMc) updateFreq = pUpdateFreq trace("Soundauto constructor") } public function fadeTo(pTargetVol:Number, pTime:Number, pDelay:Number):Void{ //clear interval if (intervalId) { clearInterval(intervalId) } //if delay comeback later if(pDelay){ intervalId = setInterval(this, "fadeTo", pDelay, pTargetVol, pTime) return } var curVol = this.getVolume() startFadeVal = curVol targetFadeVal = pTargetVol //vol step per ms fadeStep = (targetFadeVal - curVol)/pTime intervalId = setInterval(this, "autoFade", updateFreq) var newVol = Math.round(curVol + (fadeStep * (pTime/updateFreq))) this.setVolume(newVol) } private function autoFade(Void):Void{ var curVol = this.getVolume() var newVol = Math.round(curVol + (fadeStep * updateFreq)) this.setVolume(newVol) if (startFadeVal < targetFadeVal){ if (newVol >= targetFadeVal){ fadeComplete() return } } else { if (newVol <= targetFadeVal){ fadeComplete() return } } //call onFade function onFade() } private function fadeComplete(Void):Void{ this.setVolume(targetFadeVal) onFadeChange(this.getVolume()); // execute callback for each change in fade value, pass newVal to assigned function clearInterval(intervalId) intervalId = null } private function onFade(Void):Void{ onFadeChange(this.getVolume()); // execute callback for each change in fade value, pass newVal to assigned function } } Brian On 11/7/05, eric dolecki <[EMAIL PROTECTED]> wrote: > > Basically yes :) > > Flash has no notion of decibels - there are probably formulas out there to > try and approximate that logarithmic curve and apply it to your audio to > get > a more natural response. Its a interesting topic at least ;) > > e.dolecki > > On 11/7/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > > ok. are you talking about decibels being logarithmic and not linear? ie. > > decibel * 2 doesn't mean "heard volume" * 2. > > > > anyway this is getting off topic but i'm sure you're right about this > > whole thing anyway :).. > > > > > > eric dolecki wrote: > > > I guess I'm saying that any audio fading up or down should probably > not > > be > > > done linearly ever - while mathematically accurate, to the human ear > it > > > doesn't sound right. You'll notice no change and then zoooom... a > really > > > quick fade down... when what you wanted was something "even" if you > know > > > what I mean. > > > > > > e.dolecki > > > > > > On 11/7/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > >> so then the code here would work since it's not "linear". > > >> > > >> but i'm not sure what you mean by "linear adjustments prove to sound > > >> highly inaccurate"? in this case i don't think it matters anyway > since > > >> it's just a small change of volume and he's probably not coding some > > >> online dj mixing software. or maybe he is.. :) > > >> > > >> andreas > > >> > > >> > > >> Eric E. Dolecki wrote: > > >>> I've found that linear adjustments prove to sound highly inaccurate > - > > or > > >>> strange. You'll notice no difference, and then the change will be > > quite > > >>> abrupt. So be careful with these kinds of things - linear is > probably > > >>> not the best way to go. > > >>> > > >>> e.dolecki > > >>> > > >>> > > >>> On Nov 7, 2005, at 5:21 AM, [EMAIL PROTECTED] wrote: > > >>> > > >>>> If you want to keep things simple, and the volume fade doesn't need > > to > > >>>> be linear, couldn't you just run a soundUpdate function and keep > > track > > >>>> of the volume in a variable. something like this: > > >>>> > > >>>> > > >>>> var volume = 0; > > >>>> var destVolume = 100; > > >>>> > > >>>> setInterval(soundUpdate, 100); > > >>>> > > >>>> function soundUpdate() { > > >>>> volume += (destVolume - volume) / 20; > > >>>> track.setVolume(volume); > > >>>> } > > >>>> > > >>>> then when you need the volume to change you could just do: > > >>>> > > >>>> on (rollOver) { > > >>>> destVolume = 0; > > >>>> } > > >>>> > > >>>> then maybe add another interval that sets destVolume back to 100. > you > > >>>> could probably replace the "volume += (destVolume .." with > something > > >>>> better but at least it should work. :) > > >>>> > > >>>> Andreas > > >>>> > > >>>> MetaArt wrote: > > >>>>> In my movie, I have a jingle, that is loaded by this code: > > >>>>> > > >> > > > code:----------------------------------------------------------------------- > > >>>>> -------track = new Sound(); > > >>>>> track.loadSound("everybody.mp3", true); > > >>>>> track.setVolume(0); > > >>>>> vol = 0; > > >>>>> fade = setInterval(fadeIn, 100); > > >>>>> function fadeIn() { > > >>>>> vol += 1; > > >>>>> track.setVolume(vol); > > >>>>> if (vol>=90) { > > >>>>> clearInterval(fade); > > >>>>> } > > >>>>> > > >> > > > };-------------------------------------------------------------------------- > > >>>>> ---- > > >>>>> during playback of this jingle, is possible that happens an event > (a > > >>>>> rollOver action) by the user that start the playback of an other > > >>>>> audio file, > > >>>>> this time a talkin' human voice. > > >>>>> The problem is that the jingle cover the voice, or whatever the > two > > >>>>> audios > > >>>>> overlaps. > > >>>>> Therefore, I want do something that, on rollOver, do the jingle > has > > a > > >>>>> fast > > >>>>> fadeOut, starting by the volume level where it is. > > >>>>> How can I obtain this? > > >>>>> Enrico Tomaselli > > >>>>> +> web designer <+ > > >>>>> [EMAIL PROTECTED] > > >>>>> http://www.metatad.it > > >>>>> _______________________________________________ > > >>>>> Flashcoders mailing list > > >>>>> Flashcoders@chattyfig.figleaf.com > > >>>>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > >>>> _______________________________________________ > > >>>> Flashcoders mailing list > > >>>> Flashcoders@chattyfig.figleaf.com > > >>>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > >>> _______________________________________________ > > >>> Flashcoders mailing list > > >>> Flashcoders@chattyfig.figleaf.com > > >>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > >>> > > >>> > > >> _______________________________________________ > > >> Flashcoders mailing list > > >> Flashcoders@chattyfig.figleaf.com > > >> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > >> > > > _______________________________________________ > > > Flashcoders mailing list > > > Flashcoders@chattyfig.figleaf.com > > > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > > > > > > > _______________________________________________ > > Flashcoders mailing list > > Flashcoders@chattyfig.figleaf.com > > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > > _______________________________________________ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders