• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How can I stop timeline sounds in external swf files from playing during loading?

New Here ,
May 29, 2012 May 29, 2012

Copy link to clipboard

Copied

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(ProgressEvent.PROGRESS,progressF);

                tl["loader_"+index].contentLoaderInfo.removeEventListener(Event.COMPLETE,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();

                }

}

TOPICS
ActionScript

Views

10.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , May 30, 2012 May 30, 2012

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

...

Votes

Translate

Translate
Enthusiast ,
May 29, 2012 May 29, 2012

Copy link to clipboard

Copied

maybe

for(var i:int=0; i<swfA.lenght; i++){

     tl["loader_"+i].contentLoaderInfo.SoundMixer.stopAll();

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 30, 2012 May 30, 2012

Copy link to clipboard

Copied

Thanks for your reply. It didn't work. Any other suggestions?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 30, 2012 May 30, 2012

Copy link to clipboard

Copied

I do not know what the name of the sound object within the swf, but you have to specifically refer to it and stop it, SoundMixer.stopAll (); stops the sounds of your movie, but the sounds within the swf "are not in the movie ", are in a own

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 30, 2012 May 30, 2012

Copy link to clipboard

Copied

There is no sound in the main swf. I have about 70 sounds in my two external swfs. Do I have to stop each one? Can you tell me how?

Thanks.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 30, 2012 May 30, 2012

Copy link to clipboard

Copied

Would be something like:

tl["loader_"+i].contentLoaderInfo.channelName.stop();

To each sound

Or maybe you'd need a function within the SWF each stop all sounds using SoundMixer.stopAll();

, and call that function from your main movie.

tl["loader_"+i].contentLoaderInfo.myFunctionMute();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 30, 2012 May 30, 2012

Copy link to clipboard

Copied

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();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 31, 2012 May 31, 2012

Copy link to clipboard

Copied

esdebon,

i tried this but now i have no sound at all.

i'm not sure if i put the code for

remind_main_mod.fla

in the right place.

i put it after

play_slider.enabled = false;

is that ok?

thanks so much for your help

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 31, 2012 May 31, 2012

Copy link to clipboard

Copied

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(ProgressEvent.PROGRESS,progressF);

    tl["loader_"+index].contentLoaderInfo.removeEventListener(Event.COMPLETE,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;

        if(partialTotalFrames>=frameNum){

            break;

        }

    }

   

    partialTotalFrames -= frameA;

    //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-partialTotalFrames);

    } else {

        MovieClip(currentLoader.content).gotoAndStop(frameNum-partialTotalFrames);

    }

   

}

function sliderUpdateF(e:Event):void{

    var playedFrames:int = 0;

    for(var i:int=0;i<Number(currentLoader.name);i++){

        playedFrames += frameA;

    }

    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);

    }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 30, 2012 May 30, 2012

Copy link to clipboard

Copied

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);

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 31, 2012 May 31, 2012

Copy link to clipboard

Copied

i think i have all of that code already (see above)

my swfs completely load before playing but the sound starts during loading

i have 70 separate sounds on the timeline

i do not currently have a stop() action in the first frame of them

any help would be greatly appreciated

thanks very much

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 01, 2012 Jun 01, 2012

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 04, 2012 Jun 04, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 04, 2012 Jun 04, 2012

Copy link to clipboard

Copied

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)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 04, 2012 Jun 04, 2012

Copy link to clipboard

Copied

Didn't read the whole thread, but are your sounds set to streaming or are they event?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 04, 2012 Jun 04, 2012

Copy link to clipboard

Copied

Both.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 15, 2012 Jun 15, 2012

Copy link to clipboard

Copied

thank you SO much! the code you provided above worked perfectly!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 15, 2012 Jun 15, 2012

Copy link to clipboard

Copied

LATEST

you're welcome

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines