2 Replies Latest reply: Jul 27, 2011 4:01 AM by kennethkawamoto2 RSS

    Problem on display loader

    xxxheeroxxx Community Member

      I got this code in Scene 1, 2 & 3 only differ on its suffixes like swfLoader1, swfLoader2 and so on.

       

      It seems that when I click on next button the previous swf still playing because of the sound embeded on the timeline of the swf.

       

      I know there is something missing in this code.

      I already got the current mc = null before the nextScene().

      I guess its in the swfLoader1 variable but I'm totally no idea on it.

       

      import flash.display.Loader;

      import flash.net.URLRequest;

      import flash.events.ProgressEvent;

      import flash.events.Event;

      import flash.display.MovieClip;

      import flash.events.MouseEvent;

       

      var mc1: MovieClip;

       

      var swfLoader1: Loader = new Loader();

      var swfUrl1: URLRequest = new URLRequest("scene1.swf");

       

      swfLoader1.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, swfProgressHandler1);

      swfLoader1.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoadedHandler1);

      swfLoader1.load(swfUrl1);

      movieMC.addChild(swfLoader1);

       

      function swfProgressHandler1(e: ProgressEvent):void{

           var loadPercent: Number = e.bytesLoaded / e.bytesTotal;

           sceneLoaderMC.sceneLoaderBarMC.scaleX = loadPercent;

           sceneLoaderMC.sceneLoaderPercent.text = (Math.ceil(loadPercent * 100)).toString() + "%";

      }

       

      function swfLoadedHandler1(e: Event):void{

           swfLoader1.contentLoaderInfo.removeEventListener(Event.COMPLETE, swfLoadedHandler1);

           swfLoader1.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRES S, swfLoadedHandler1);

           sceneLoaderMC.visible = false;

           mc1 = MovieClip(swfLoader1.content);

           mc1.gotoAndPlay(1);

      }

       

      function onEnterFrame1(e: Event):void{

       

           if(mc1.currentFrame == mc1.totalFrames){

       

                mc1.removeEventListener(Event.ENTER_FRAME, onEnterFrame1);

                mc1 = null;

                nextScene();

           }

      }

        • 1. Re: Problem on display loader
          kennethkawamoto2 CommunityMVP

          Try Loader.unloadAndStop()

          ...
          swfLoader1.unloadAndStop();
          nextScene();
          ...
          
          • 2. Re: Problem on display loader
            relaxatraja Community Member

             

            var loader:Loader = new Loader();

            loader.load ( new URLRequest ( "content.swf" ) );

            addChild ( loader );

            stage.addEventListener ( MouseEvent.CLICK, unloadSWF );

            function unloadSWF ( e:MouseEvent ):void

            {

            // Unload the SWF file with automatic object deactivation

            // All deactivation is handled automatically

            loader.unloadAndStop();

            }

             

             

             

            According to the AS3 current documentation, after calling Loader.unloadAndStop, the following happens:

             

             

             

                * Sounds are stopped.

             

                * Stage event listeners are removed.

             

                * Event listeners for enterFrame, frameConstructed, exitFrame, activate and deactivate are removed.

             

                * Timers are stopped.

             

                * Camera and Microphone instances are detached

                * Movie clips are stopped.