3 Replies Latest reply on Jan 13, 2013 10:16 AM by kglad

    how do i stop loading a swf file which is still in progress.

    Kusha.W Level 1

      //I have three buttons on the stage (btn1, btn2, btn3)

      when i click the first button swf starts loading

      while the swf is loading if i press the 2nd button

      the first swf wont stop loading and both the swfs start playing

      but if the first swf is fully loaded then every thing workes fine.

       

      so please let me know how do i stop loading a file which is still in progress.

       

      var _contentSWF:ContentSWF

      var _content

       

      btn1.addEventListener(MouseEvent.CLICK, handleClick)

      btn2.addEventListener(MouseEvent.CLICK, handleClick)

      btn3.addEventListener(MouseEvent.CLICK, handleClick)

       

      function handleClick(){

          if(_content!=undefined){

              _contentSWF.removeContent()

              removeChild(_contentSWF);

              _contentSWF =null;

          }

       

          _contentSWF = new ContentSWF()

          _content = addChild(contentSWF);

          _contentSWF.init(some path.swf)

         

      }

       

      //ContentSWF.as

      private var _path:String

      private var swfLoader:Loader

      private var _content

       

      public class ContentSWF extends Sprite{

         

          public function init(path){

             

              if(_content!=null){

                  _content.content.removeEventListener(Event.COMPLETE, completeHandler)

                  _content.removeChild(mymc)

                  _content=null

              }

             

             

              swfLoader=new Loader();

              _path = path

              swfLoader.load(new URLRequest(path));

              swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoaded);

          }

         

          public function removeContent(){

              swfLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, swfLoaded);

              swfLoader.unloadAndStop()

          }

         

          private function swfLoaded(e:Event){

              _content = addChild(mymc)

          }

         

      }

        • 1. Re: how do i stop loading a swf file which is still in progress.
          kglad Adobe Community Professional & MVP

          use the close() method of your loader.  but do not try and apply that if nothing is currently loading or, i believe, you will trigger an error.

          • 2. Re: how do i stop loading a swf file which is still in progress.
            Kusha.W Level 1

            Thanks Kglad, it all worked fine but can you help me in this.

             

            I have 4 movieclips (_a,_b,_c,_d) when i click each of the movieclip they load a SWF(my_mc)

            now when the swf file loades it starts loading a Sound(mp3)

            Now when i press another button  (_b) while this mp3 is loading

            all the methords like  Loader.close and loader.unloadAndStop() workes fine  but i dont know how dose the MP3 loades and start playing

            I also used the below script in  my_mc.swf , but it wont work

             

            this.addEventListener(Event.unload, myfun)

             

            function myfun(e:Event){

            \     if(_sound.bytesLoaded<_sound.bytesTotal){

                      _sound.close()

                 }

                    

                 if (_chanel){

                      _chanel.stop()

                 }

            }

            • 3. Re: how do i stop loading a swf file which is still in progress.
              kglad Adobe Community Professional & MVP

              i don't know what "this" is referencing but i doubt it has an Event.unload event.  use the trace function to confirm that is the problem.

               

              or just replace with this to solve the problem:

               

              this.addEventListener(Event.REMOVED_FROM_STAGE,myfun);

              1 person found this helpful