So, I have been given a flash movie and asked to add sound.
The movie is a long tweened animation, the premise being that the navigation allows teh user to move in either direction along the timeline by dragging a pointer.
I have been asked to get the sound to fade in as the user gets closer to a specific frame. Eg, there is bird imagery in frame 120, and as the user approached frame 120 I need the sound to get louder.
All sounds are in the library.
The problem is that all the sounds are fading in at exactly the same rate- even the "Track.wav" which should not be affected by the onEnterFrame.
In fact, the trace action in the onEnterFrame is apparently showing accurate results for what the volume of each sound object should be; but the reality is that the sounds fade in and out all at the same rate, all apparently following the volume of the last sound in the loop (Projector.wav)
// the most complicated sound object ever! var sdBirds = new Sound(); var sdHeartbeat = new Sound(); var sdMiniBusses = new Sound(); var sdProjector = new Sound(); var sdTrack = new Sound(); // -------------------------------------- var aSounds=[] aSounds[0]={sound:"Birds.wav", frame:120, sdObj:sdBirds, maxVol:40} aSounds[1]={sound:"HeartBeat.wav", frame:45, sdObj:sdHeartbeat, maxVol:40} aSounds[2]={sound:"MiniBusses.wav", frame:55, sdObj:sdMiniBusses, maxVol:40} aSounds[3]={sound:"Projector.wav", frame:155, sdObj:sdProjector, maxVol:40} aSounds[4]={sound:"Track.wav", frame:1, sdObj:sdTrack, maxVol:40} //-------------------------- sdBirds.attachSound(aSounds[0].sound) sdHeartbeat.attachSound(aSounds[1].sound) sdMiniBusses.attachSound(aSounds[2].sound) sdProjector.attachSound(aSounds[3].sound) sdTrack.attachSound(aSounds[4].sound) // ---------------------------------------- for(var i=0; i<aSounds.length-1; i++) { //aSounds[i].setVolume(0) aSounds[i].sdObj.start(0,10000000) } aSounds[4].sdObj.start(0,10000000) // ----------------------------------------
onEnterFrame=function(){ for (var i=0; i<aSounds.length-1; i++) { var d=aSounds[i].maxVol- (Math.sin(Math.abs(((movie_mc._currentframe - aSounds[i].frame) /movie_mc._totalframes)))*100) aSounds[i].sdObj.setVolume((d<0) ? 0 : d)
trace(aSounds[i].sound + " --> " + aSounds[i].sdObj.getVolume())
}
trace("-------------------------------------------")
}
its probably that you need to specify targets for your sound objects. if they don't have target objects then they all refer to the same one and a change in one is a change in all. so your
var snd = new Sound()
should be
var snd1 = new Sound(target1); var snd2 = new Sound(target2); and so on
Haven't tested this just now, but have experienced something like this before
Indeed, each sound must have its very own movieclip - problem solved by creating 5 empty movieclips as a targets.
Thanks!