Flash Timeline Sound Not Stopping On Navigate Away
I have a Flash piece that has one main timeline that loads different movie clips and different sections of that main timeline.
On those embedded movie clips within the main timeline are sounds attached to the embedded movieclips timelines set to "stream". They have to be on the timeline so they sync up correctly (I can't load the sounds programatically).
I'm having the issue that when I navigate to a new section on the main timeline, the movieclip that was embedded on the timeline I navigated away from goes away, but the sound continues to play. I can't figure out how to get the开发者_开发问答 sound to stop once I've navigated away.
I can't add a stop all sounds because the navigation of the movie is controlled from an external player I don't have control over (basically the external player just calls a gotoAndStop("myFrame") on the movie.).
Any ideas why the timeline sounds isn't working like it's suppose to?
Thanks.
Two possible solutions:
1. This should stop all sounds currently playing. May not work for you if you need stuff like background music to continue playing after you transition out. It's a workaround.
import flash.media.SoundMixer;
SoundMixer.stopAll()
2. Do this on the MovieClip that has sounds you want to get rid of:
var myMovieClip:MovieClip;
var muteTransform:SoundTransform = new SoundTransform();
muteTransform.volume = 0;
myMovieClip.soundTransform = muteTransform;
Timeline sounds in Flash are a pain! It's buggy and Adobe should fix it, but they probably won't.
Buggy indeed in AS3 compiled SWF to avoid lots of them timeline sounds should not seat in frame 1 (frame 2 will do) of any embeded timelines...
One thing you can do is to have an object that manages all sounds(ex: a SoundManager class). It knows all the sounds that are playing. When you go to a new section of your movie, the first thing you may want to do is to ask the SoundManager to stop all sounds.
Break your timeline animation up into separate MovieClips.
I've found useful this workaround:
public function stopAllMovies(mov:MovieClip, mute:Boolean=false):void{
//trace("STOPING MOVIE "+mov);
mov.stop();
if(mute) {
var muteTransform:SoundTransform = new SoundTransform(0.0);
mov.soundTransform = muteTransform;
}
for (var i:uint=0;i<mov.numChildren;i++){
var m = mov.getChildAt(i);
if(m is MovieClip){
if(mute) m.soundTransform = muteTransform;
m.stop();
stopAllMovies(m);
}
}
}
make a global variable file myglobal.as, in that file define
package {
public class MyGlobal {
public static var cycle:int;
}
}
and use import myglobal on frame 1 of the main timeline.
myglobal.count +=1; // fist thing you do on frame 1.
if(myglobal.count==1){
sound.play();
};
END that should work to only play it once.
Another simple thing you can do is to add a keyframe to the layer where the audio streams ( within the movieclip, where the audio ends ). When you want to navigate on the main time to a different movieclip, make the previous audio movieclip to jump to that keyframe where the audio ends and then play the next movieclip...
Eg: If the current movieclip that plays the audio has instance name : mc_1
( on main timeline ) and if mc_2
is the consecutive movieclip that would be played.
In such a case you can stop the sound in mc_1 by using
mc_1.gotoAndStop("frameWhereAudioEnds");
start next audio movieclip.
mc_2.play();
I would try listening for the removedFromStage event on the movieclip that's going away (I assume there is no instance of that movie clip in the timeline at the point you're navigating to), and then use MovieClip.SoundTransform as above.
SoundMixer.soundTransform = new SoundTransform(1, 0); //volume, pan
精彩评论