Skip navigation
Currently Being Moderated

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

May 29, 2012 2:13 PM

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

                }

}

 
Replies
  • Currently Being Moderated
    May 29, 2012 2:25 PM   in reply to mlouisem

    maybe

     

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

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

    }

     
    |
    Mark as:
  • Currently Being Moderated
    May 30, 2012 7:43 AM   in reply to mlouisem
    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

     

     
    |
    Mark as:
  • Currently Being Moderated
    May 30, 2012 8:25 AM   in reply to mlouisem

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

     
    |
    Mark as:
  • Currently Being Moderated
    May 30, 2012 2:44 PM   in reply to esdebon

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

     
    |
    Mark as:
  • Currently Being Moderated
    May 30, 2012 4:32 PM   in reply to mlouisem

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

    }

     
    |
    Mark as:
  • Currently Being Moderated
    May 31, 2012 10:15 AM   in reply to mlouisem

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

        }

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 1, 2012 4:33 PM   in reply to mlouisem

    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?

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 4, 2012 10:17 AM   in reply to mlouisem

    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)

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 4, 2012 11:08 AM   in reply to mlouisem

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

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 15, 2012 4:15 PM   in reply to mlouisem

    you're welcome

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points