I am having a problem with timeline sounds in external swf files playing during loading in a main swf. Can anyone help me?
Here is some of the code from the main swf. I hope I have included enough.
Thanks.
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.display.Loader;
import flash.events.ProgressEvent;
import flash.events.Event;
import flash.net.URLRequest;
import fl.events.SliderEvent;
import flash.media.SoundTransform;
preloader_mc.fill_mc.scaleX = 0;
var swfA:Array = ["part1.swf","part2.swf"];
var frameA:Array = [];
var currentLoader:Loader;
var swfTotalFrames:int;
var tl:MovieClip = this;
var st:SoundTransform = new SoundTransform()
var index:int = 0;
loadNextF();
play_slider.enabled = false;
function loadNextF():void{
tl["loader_"+index] = new Loader();
tl["loader_"+index].name = index.toString();
tl["loader_"+index].contentLoaderInfo.addEventListener(ProgressEvent. PROGRESS,progressF);
tl["loader_"+index].contentLoaderInfo.addEventListener(Event.COMPLETE ,completeF);
tl["loader_"+index].load(new URLRequest(swfA[index]));
}
function progressF(e:ProgressEvent):void{
var fractionLoaded:Number = index/swfA.length+e.bytesLoaded/(e.bytesTotal*swfA.length);
preloader_mc.fill_mc.scaleX = fractionLoaded;
preloader_mc.tf.text = (100*fractionLoaded)+"% Loaded";
}
function completeF(e:Event):void{
tl["loader_"+index].contentLoaderInfo.removeEventListener(ProgressEve nt.PROGRESS,progressF);
tl["loader_"+index].contentLoaderInfo.removeEventListener(Event.COMPL ETE,completeF);
SoundMixer.stopAll();
var mc:MovieClip = MovieClip(tl["loader_"+index].content);
mc.gotoAndStop(1);
frameA.push(mc.totalFrames);
index++;
if(index<swfA.length){
loadNextF();
} else {
// all loads complete. start play.
restart_mc.buttonMode = true;
restart_mc.alpha = 1;
tl.addEventListener(Event.ENTER_FRAME,playUpdateF);
tl.removeChild(preloader_mc);
preloader_mc = null;
play_slider.enabled = true;
playpause_mc.alpha = 1;
currentLoader = tl["loader_0"];
tl.addChild(currentLoader);
MovieClip(currentLoader.content).play();
sliderParamsF();
}
}
I am in the work, i haven´t speakers
try this
Add in the first frame of part1.fla and part2.fla this code:
function mute():void {
SoundMixer.stopAll();
}
and in the file remind_main_mod.fla
SoundMixer.stopAll();
MovieClip(currentLoader.content).mute();
each time thatlook
SoundMixer.stopAll();
I have about 70 sounds in my two external swfs. Do I have to stop each one?
//---
more than likely, yes. i guess it would depend on how you have the 70 sounds set up in your external swf... i mean:
do you have 70 named movieclips on the external swf stage with a separate sound in each one? and do they each have a stop() action in the first frame?
or
do you tell your external swf to go to a certain frame label which plays a sound on the timeline at that label?
or
are your 70 sounds created dynamically with code and told to .start()?
//---
also keep in mind, a loading swf will start to play even before it is completely loaded. so instead of when it's completely loaded, try stopping the loaded swf with a listener for "init", which is when the loaded swf enters its first frame:
function loadNextF():void{
tl["loader_"+index] = new Loader();
tl["loader_"+index].name = index.toString();
tl["loader_"+index].contentLoaderInfo.addEventListener(ProgressEvent. PROGRESS,progressF);
tl["loader_"+index].contentLoaderInfo.addEventListener(Event.COMPLETE ,completeF);
tl["loader_"+index].contentLoaderInfo.addEventListener(Event.INIT, initF);
tl["loader_"+index].load(new URLRequest(swfA[index]));
}
function initF(e:Event):void{
SoundMixer.stopAll();
var mc:MovieClip = MovieClip(tl["loader_"+index].content);
mc.gotoAndStop(1);
}
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.display.Loader;
import flash.events.ProgressEvent;
import flash.events.Event;
import flash.net.URLRequest;
import fl.events.SliderEvent;
import flash.media.SoundTransform;
preloader_mc.fill_mc.scaleX = 0;
var swfA:Array = ["part1.swf","part2.swf"];
var frameA:Array = [];
var currentLoader:Loader;
var swfTotalFrames:int;
var tl:MovieClip = this;
var st:SoundTransform = new SoundTransform()
var index:int = 0;
loadNextF();
play_slider.enabled = false;
function loadNextF():void{
tl["loader_"+index] = new Loader();
tl["loader_"+index].name = index.toString();
tl["loader_"+index].contentLoaderInfo.addEventListener(ProgressEvent. PROGRESS,progressF);
tl["loader_"+index].contentLoaderInfo.addEventListener(Event.COMPLETE ,completeF);
tl["loader_"+index].load(new URLRequest(swfA[index]));
}
function progressF(e:ProgressEvent):void{
var fractionLoaded:Number = index/swfA.length+e.bytesLoaded/(e.bytesTotal*swfA.length);
preloader_mc.fill_mc.scaleX = fractionLoaded;
preloader_mc.tf.text = (100*fractionLoaded)+"% Loaded";
}
function completeF(e:Event):void{
tl["loader_"+index].contentLoaderInfo.removeEventListener(ProgressEve nt.PROGRESS,progressF);
tl["loader_"+index].contentLoaderInfo.removeEventListener(Event.COMPL ETE,completeF);
SoundMixer.stopAll();
var mc:MovieClip = MovieClip(tl["loader_"+index].content);
mc.gotoAndStop(1);
frameA.push(mc.totalFrames);
index++;
if(index<swfA.length){
loadNextF();
} else {
// all loads complete. start play.
restart_mc.buttonMode = true;
restart_mc.alpha = 1;
tl.addEventListener(Event.ENTER_FRAME,playUpdateF);
tl.removeChild(preloader_mc);
preloader_mc = null;
play_slider.enabled = true;
playpause_mc.alpha = 1;
currentLoader = tl["loader_0"];
tl.addChild(currentLoader);
MovieClip(currentLoader.content).play();
sliderParamsF();
}
}
///////////////// start sliders /////////////////////////////////
sound_slider.addEventListener(SliderEvent.CHANGE,soundSliderF);
function soundSliderF(e:SliderEvent):void{
st.volume = e.value/100;
tl.soundTransform = st;
}
play_slider.addEventListener(SliderEvent.CHANGE,playSliderF);
play_slider.addEventListener(MouseEvent.MOUSE_DOWN,playSliderDownF);
//play_slider.addEventListener(MouseEvent.MOUSE_UP,playSliderUpF);
function playSliderDownF(e:MouseEvent):void{
tl.removeEventListener(Event.ENTER_FRAME,playUpdateF);
stage.addEventListener(MouseEvent.MOUSE_UP,playSliderUpF);
}
function playSliderUpF(e:MouseEvent):void{
tl.addEventListener(Event.ENTER_FRAME,playUpdateF);
}
function playSliderF(e:SliderEvent):void{
SoundMixer.stopAll();
var frameNum:int = Math.ceil(swfTotalFrames*e.value/100);
var partialTotalFrames:int = 0;
for(var i:int=0;i<frameA.length;i++){
partialTotalFrames += frameA[i];
if(partialTotalFrames>=frameNum){
break;
}
}
partialTotalFrames -= frameA[i];
//trace(i,frameNum,frameNum-partialTotalFrames);
if(currentLoader!=tl["loader_"+(i)]){
tl.removeChild(currentLoader);
MovieClip(currentLoader.content).stop();
currentLoader = tl["loader_"+(i)];
tl.addChild(currentLoader);
}
if(playpause_mc.currentFrame==1){
MovieClip(currentLoader.content).gotoAndPlay(frameNum-partialTotalFra mes);
} else {
MovieClip(currentLoader.content).gotoAndStop(frameNum-partialTotalFra mes);
}
}
function sliderUpdateF(e:Event):void{
var playedFrames:int = 0;
for(var i:int=0;i<Number(currentLoader.name);i++){
playedFrames += frameA[i];
}
playedFrames += MovieClip(currentLoader.content).currentFrame;
play_slider.value = Math.round(100*playedFrames/swfTotalFrames);
}
function sliderParamsF():void{
swfTotalFrames = 0;
for(var i:int=0;i<swfA.length;i++){
swfTotalFrames += MovieClip(tl["loader_"+i].content).totalFrames;
}
}
///////////////// end sliders //////////////////////////////////
///////////////// start playpause restart ///////////////////////
playpause_mc.addEventListener(MouseEvent.CLICK,playpauseF);
playpause_mc.alpha = .2;
restart_mc.addEventListener(MouseEvent.CLICK,restartF);
restart_mc.buttonMode = false;
restart_mc.alpha = .2;
function playpauseF(e:MouseEvent):void{
if(!e.currentTarget.toggle){
MovieClip(currentLoader.content).stop();
tl.removeEventListener(Event.ENTER_FRAME,playUpdateF);
e.currentTarget.gotoAndStop(2);
} else {
MovieClip(currentLoader.content).play();
tl.addEventListener(Event.ENTER_FRAME,playUpdateF);
e.currentTarget.gotoAndStop(1);
}
e.currentTarget.toggle = !e.currentTarget.toggle;
}
///////////////// end playpause //////////////////////////////
function playUpdateF(e:Event):void{
sliderUpdateF(e);
var playingFrame:int = MovieClip(currentLoader.content).currentFrame;
if(playingFrame==frameA[Number(currentLoader.name)]){
// next loader
MovieClip(currentLoader.content).stop();
SoundMixer.stopAll();
MovieClip(currentLoader.content).mute();
var nextIndex:int = Number(currentLoader.name)+1;
if(nextIndex<swfA.length){
tl.removeChild(currentLoader);
currentLoader = tl["loader_"+nextIndex];
tl.addChild(currentLoader);
MovieClip(currentLoader.content).gotoAndPlay(1);
} else {
tl.removeEventListener(Event.ENTER_FRAME,playUpdateF);
playpause_mc.gotoAndStop(2);
playpause_mc.toggle = !playpause_mc.toggle;
//playpause_mc.alpha = .2;
// all swfs have completed play
}
}
}
function restartF(e:MouseEvent):void{
MovieClip(currentLoader.content).stop();
tl.removeChild(currentLoader);
SoundMixer.stopAll();
MovieClip(currentLoader.content).mute();
currentLoader = tl["loader_"+0];
tl.addChild(currentLoader);
if(playpause_mc.currentFrame==1){
MovieClip(currentLoader.content).gotoAndPlay(1);
} else {
MovieClip(currentLoader.content).gotoAndStop(1);
}
}
explain the setup of the sounds on the timeline of the external swf.
i gave 3 possible scenarios. could it be one of those? or something different?
dont forget, while the swf is loading, it is playing... you dont tell it to gotoAndStop(1) until it completes loading... do you hear the sounds start from the beginning twice?
i imported the sounds to the library and dragged each one to the stage where it is needed it in the timeline...they are all on the same layer...i created a keyframe for each one...i did not name them other than the file name they already had... i don't know if that makes them movie clips or not...please excuse my ignorance...i have not added any code to them.
each sound plays once while loading...part way through loading I start to hear the sounds from the second swf...when the swfs are both loaded i hear the sounds again with the animation.
sounds like your loading swf is not stopped.
please try adding this. basically, it's telling the loading swf to gotAndStop(1) as soon as it enters it's first frame, whether it's finished loading or not:
function loadNextF():void{
tl["loader_"+index] = new Loader();
tl["loader_"+index].name = index.toString();
tl["loader_"+index].contentLoaderInfo.addEventListener(ProgressEvent. PROGRESS,progressF);
tl["loader_"+index].contentLoaderInfo.addEventListener(Event.COMPLETE ,completeF);
tl["loader_"+index].contentLoaderInfo.addEventListener(Event.INIT, initF);
tl["loader_"+index].load(new URLRequest(swfA[index]));
}
function initF(e:Event):void{
SoundMixer.stopAll();
var mc:MovieClip = MovieClip(tl["loader_"+index].content);
mc.gotoAndStop(1);
}
//---
another thing you can do simply is try putting a stop() in the first frame of the loading swf (on a separate layer, of course)
North America
Europe, Middle East and Africa
Asia Pacific